feat(passes): leverage snarkVM aggregate ternary opcodes#29349
Draft
mohammadfawaz wants to merge 1 commit into
Draft
feat(passes): leverage snarkVM aggregate ternary opcodes#29349mohammadfawaz wants to merge 1 commit into
mohammadfawaz wants to merge 1 commit into
Conversation
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.
d971f26 to
7dcbd63
Compare
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
Switch the
snarkvmdependency to themohammadfawaz/complex_ternarybranch (snarkVM PR #3222), which extends theternaryinstruction to accept literal, array, and plaintext struct operands in addition to registers. The Leo flattening pass is updated to take advantage of this:identifiers, and literals are now preserved in emitted bytecode rather than decomposed field-by-field.ternaryoperands.rand/rand_chachaare bumped to0.10to match snarkVM, with the corresponding CLI call-site adjustments.New compiler and execution tests cover ternaries over structs, nested structs, arrays, arrays of structs, records, primitives, and the
identifiertype, in both transition and finalize contexts.Bytecode impact (compiler test suite)
Measured across the 1,408 expectation files under
tests/expectations/compiler/**/*.outthat are present on bothmasterand this branch:Top savers (bytes saved):
option/unwrap_or_deep.out— 64,668storage/external_storage.out— 15,020storage/aggregates.out— 9,529function/flatten_test.out— 6,161option/in_modules.out— 3,154storage/{primitives,signed,unsigned,external_storage_multi_deps}.out— 2,186–2,492 eachfunction/flatten_arrays.out— 1,254examples/tictactoe.out— 1,076option/implicit_wrapping.out— 1,021Savings concentrate on code that previously forced field-by-field destructuring of ternaries — struct/array conditionals, option-like wrappers, and external storage aggregates.
Bytecode impact (
leo-examples)Measured by running
leo buildon each of the 34 programs underexamples/with themasterCLI and with this branch's CLI, comparingbuild/main.aleobyte sizes:Only
tictactoe/main.aleochanged: 6,525 → 5,401 B (−17.2%), 207 → 183 lines. The per-row/per-cell decomposition of theBoardstruct now folds into three aggregateternaryops overRow/Board.All other 33 example programs produce byte-identical bytecode — they don't conditionally select over composite types, so the new opcodes have nothing to fold.
Bytecode impact (
compliant-stablecoin)Measured by running
leo buildon the 5 programs of ProvableHQ/compliant-stablecoin (ported to Leo 4.x) with the base CLI and with this branch's CLI:merkle_treemultisig_corefreezelist_programstablecoin_programbridge_programAll savings come from
merkle_tree, which is the only module conditionally selecting over composite types ([field; 3]arrays inside the sibling-hash loop). The other four programs compile to byte-identical bytecode — they don't use aggregate ternaries, so the new opcodes have nothing to fold.Test plan
cargo test -p leo-passescargo test -p leo-compiler --lib test_compilercargo test -p leo-compiler --lib test_execute(newternary_*cases)cargo clippy -- -D warningscargo +nightly fmt --check