Repository navigation
feat(avm): AVM gas schedule from ZisK proving cost (proposal) - #25924
Closed
zac-williamson wants to merge 3 commits into
Closed
zac-williamson wants to merge 3 commits into
zac-williamson wants to merge 3 commits into
Conversation
Turbo proves public execution inside its ZisK epoch program, so AVM gas should track ZisK steps. Each opcode's L2 gas is now round(steps x 0.05254), where steps is the ziskemu (ZisK 1.4.0-alpha) step count of one instance of the opcode run by aztec-rs's avm-simulator in a ZisK guest (zisk feature, precompiles on, pq1fr), measured as the slope over loop counts at the opcode's worst measured input, and 0.05254 is the old schedule's median gas per step over the 45 measured opcodes. - Tree opcodes add the checked trees' cost per access (aztec-core trees, pq1-fr nodes; 64 random accesses into 2^16-leaf trees, ~1,300 steps per pq1-fr node hash as shipped). - CALL/STATICCALL are priced at a cold call to a new contract with the largest bytecode: 189 k steps, which gives 9936 again. - SSTORE, EMITNOTEHASH and EMITNULLIFIER keep L2_GAS_DISTRIBUTED_STORAGE_PREMIUM on top, and SENDL2TOL1MSG keeps L2_GAS_PER_L2_TO_L1_MSG. DA gas, addressing gas, RETURN and REVERT are unchanged. - Underpriced before (steps/gas over 2x the median of 19): TORADIXBE's per-limb gas (71 steps/gas; 3 -> 11) and EMITPUBLICLOG's base (39; 15 -> 31). Largest cuts: KECCAKF1600 58176 -> 78, BLAKE3COMPRESSION 14123 -> 66, SHA256COMPRESSION 12288 -> 59, SSTORE 33140 -> 3148, EMITNULLIFIER 30800 -> 3061, EMITNOTEHASH 19275 -> 1405. POSEIDON2 360 -> 593. Epoch-72's public txs (recomputed from per-opcode charges, which reproduce the recorded gas): transfer_in_public 79,279 -> 19,200 public L2 gas, the 12,940-instruction claim 403,730 -> 300,290. The recorded epoch-72 no longer replays under the new schedule (fees and roots in its headers follow the old gas); its README says so. H4 fixture: 25,433 -> 9,710 with the opcode, 422,628 -> 394,001 in pure Noir (Rust test measured; the C++ test's numbers by arithmetic from the per-opcode counts, bb not built).
…orks' byte-wise reduction Fr::from_be_bytes_reduce goes through arkworks' from_be_bytes_mod_order, about 2,000 ZisK steps per SETFF decoded. Straight-line SETFF code cost 2,313 steps per instruction (first decode), 210 steps per gas at the new SET gas of 11, against a median of 19. Fr::from_hash gives the same value (a 32-byte big-endian value reduced mod p, at most five subtractions) and brings it to 666 steps. Decode is cached per batch, so loops are unaffected (measured equal within 23 steps). The decode test now compares both reductions on p - 1, p, p + 1, 5p, 2^256 - 1, 0 and 64 pseudo-random values.
Same method; the build with the SETFF decode change moves a few step counts by up to 150, so the median is 0.05250 gas per step (was 0.05254) and five constants move by 1 or 2 gas: GETENVVAR 12 -> 11, SLOAD 941 -> 940, SSTORE 3148 -> 3147, EMITNULLIFIER 3061 -> 3059, GETCONTRACTINSTANCE 3136 -> 3137. The fixture gas (9,710 / 394,001) is unchanged.
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.
Requested by Zac · project thread
Stacked on #25923 (
zkvm/avm-blake3-h4). This is a draft proposal and is not for auto-merge. It changes the AVM's L2 gas prices protocol-wide.Why
Turbo proves public execution inside its ZisK epoch program, so L2 gas should track ZisK proving steps. If an opcode is underpriced, a tx can use up more of a checkpoint's ~72 s proving budget per unit of gas than intended. That is a denial-of-service risk for the prover.
Method (all counts measured with
ziskemu, ZisK 1.4.0-alpha)Biggest changes
Epoch-72's public txs: a transfer goes from 79,279 to 19,189 L2 gas, and the largest claim from 403,730 to 300,280.
Open questions for review
Checks
avm-simulator: 66/66, with and withoutpq1fr.gen_constants.sh --check, fmt andclippy -D warningsare clean.Not done:
Generated by Claude Code