Repository navigation
feat(passes): preserve aggregate ternary instructions - #29349
Draft
mohammadfawaz wants to merge 3 commits into
Draft
mohammadfawaz wants to merge 3 commits into
mohammadfawaz wants to merge 3 commits into
Conversation
mohammadfawaz
force-pushed
the
mohammadfawaz/ternary_ops
branch
from
April 18, 2026 20:28
d971f26 to
7dcbd63
Compare
Switch snarkVM to the `mohammadfawaz/complex_ternary` branch (PR #3222), which extends the `ternary` instruction to accept literal, array, and plaintext struct operands in addition to registers. The flattening pass is updated to preserve aggregate ternaries over arrays, plaintext structs, and primitives / identifiers / literals rather than decomposing them field-by-field. Records are still decomposed per-field because their ciphertext components cannot appear directly as `ternary` operands. The pass docstring is updated to reflect the new behaviour in both transition and finalize contexts. Also bumps `rand` and `rand_chacha` to `0.10` to match snarkVM, with the corresponding CLI call-site adjustments. New compiler and execution tests exercise ternaries over structs, nested structs, arrays, arrays of structs, records, primitives, and the `identifier` type, in both transition and finalize contexts.
mohammadfawaz
force-pushed
the
mohammadfawaz/ternary_ops
branch
from
May 29, 2026 22:30
7dcbd63 to
1e04f77
Compare
Merge current master and use the rebased snarkVM ternary branch. Align RocksDB with that dependency. Update the flattening pass for the current type APIs. Update constructor and execution fixtures for the current harness and consensus V23. Regenerate compiler and execution expectations.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Preserve ternaries over arrays and plaintext structs as single Aleo
ternaryinstructions. Keep tuple and record ternaries split into element or field selections. Array, struct, and identifier ternaries requireConsensusVersion::V23.Update the snarkVM dependency to PR #3222, commit
933acedd6. Support V23 in CLI version selection. Align the existing RocksDB dependency with the selected snarkVM revision. Update the fixtures for current constructor, execution-harness, and consensus-version requirements.Measurement method
Compare this PR with
masteratfcbebc7db6. Use identical source inputs and build options for both compilers. Each percentage is the change in total bytes for its stated corpus.Regenerate compiler expectations with
UPDATE_EXPECT=1 cargo test -p leo-compiler --lib test_compiler::test_compiler -- --exact --nocapture. For external programs, runleo build --network testnet --offlinefrom fresh source copies and measure the main program's emitted.aleotext file. Exclude imported bytecode from those program totals.Compiler expectation files
Compare the 1,675 fixture-backed output paths present in both trees. Exclude the 11 new compiler fixtures and nine orphaned expectation files. These totals include diagnostics and output from both import modes; they measure expectation files, not only Aleo bytecode.
The subset with bytecode and no errors contains 1,113 files. Its size changes from 1,570,011 to 1,553,197 bytes, a reduction of 16,814 bytes (1.07%). Its line count changes from 51,393 to 51,073, and 29 files change.
Changes for every compiler path listed in the previous description
tests/expectations/compiler/function/flatten_test.outstorage/external_storage.outoption/unwrap_or_deep.outstorage/aggregates.outoption/in_modules.outfunction/flatten_arrays.outexamples/tictactoe.outoption/implicit_wrapping.outstorage/primitives.outstorage/signed.outstorage/unsigned.outstorage/external_storage_multi_deps.outAggregate selection can retain both branch constructions. Some storage outputs increase in size, including the four listed above.
Bytecode impact: leo-examples
Use all 34 programs from
leo-examplesat03554ec3.tictactoechanges from 6,525 to 5,401 bytes (-17.23%) and from 207 to 183 lines. Its output contains two aggregate ternaries, both overBoardvalues. The other 33 programs are byte-identical, checked by SHA-256.Bytecode impact: amm-v3
Use the
developmentsnapshot at8d161722. It contains seven primary source programs, five test programs, and two libraries. Keep the pinned ARCs dependency atbf0a4e7aa9cb155751aa6b8aebe7c9162e2a7a5ffor both compilers. No source port is required.The primary-program comparison excludes the five test programs and two unchanged precompiled ARC22 inputs. The libraries,
u256andoracle_types, emit no standalone program bytecode.shield_swap.aleoshield_swap_freezelist.aleoshield_swap_lp_router.aleoshield_swap_multisig_core.aleoshield_swap_pricing_terms.aleoshield_swap_rebalance_router.aleoshield_swap_router.aleoOnly
shield_swap.aleochanges. Its line count changes from 36,903 to 35,340 (-1,563). The other six primary programs are byte-identical. Total primary-program lines change from 40,494 to 38,931.Upgrade compatibility: shield_swap
The candidate bytecode is not a valid upgrade from the baseline bytecode built from the same pinned AMM source. The interface, closure, and constructor checks pass. The record-output register check fails. snarkVM requires these registers to stay unchanged for upgrades at V10 and later, including V23.
mintPositionNFTr1242r972mintMintComplianceRecordr1241r971rebalance_positionPositionNFTr840r660rebalance_positionMintComplianceRecordr839r659collectPositionNFTr826r646Do not use this size reduction as evidence of upgrade compatibility. To upgrade from this baseline, the new bytecode must preserve the existing record-output registers. The custom constructor also requires multisig approval for the exact new checksum and next edition.
At the observed mainnet height of 23,392,293, the endpoint reports
shield_swap.aleoat edition 3, deployed at block 22,245,833 in transactionat1ts87l4c708nffeyd8l75cgje69trrmzyr8vnhe5ddeeurccj2grs5076w2. Its record-output registers match the baseline column above. The candidate fails the same record-register check against this deployed edition. A separate constructor mismatch exists in both baseline and candidate builds: the pinned source uses a different initial deployer address from edition 3. The baseline passes the record-register check but fails the constructor check. The candidate fails both. V23 does not remove either upgrade restriction.AMM test-program outputs
test_token_a.aleotest_token_b.aleotest_token_c.aleotest_token_d.aleotest_oracle_consumer.aleoThe oracle consumer increases by 39 bytes, while its line count changes from 3,930 to 3,924. The four token programs are byte-identical. Total test-program lines change from 4,698 to 4,692 (-6).