Skip to content

refactor: bootloader zk tx flow#673

Open
AntonD3 wants to merge 6 commits into
draft-0.4.0from
ad-bootloader-refactoring
Open

refactor: bootloader zk tx flow#673
AntonD3 wants to merge 6 commits into
draft-0.4.0from
ad-bootloader-refactoring

Conversation

@AntonD3
Copy link
Copy Markdown
Contributor

@AntonD3 AntonD3 commented May 20, 2026

What ❔

Refactor of the bootloader's resource / gas accounting in the ZK transaction flow.

  • Drop ResourcesCreationErrorPolicy trait + L1ResourcesPolicy / L2ResourcesPolicy. create_resources_for_tx is a single function that does u64-arithmetic for all three intrinsic charges (pubdata,
    computational native, gas) and returns (ResourcesForTx, Option). Charges are saturating and non-short-circuiting: every subtraction is applied even when an earlier one underflowed,
    so the resource state is well-formed for the L1 saturate-and-continue path, and the first observed validation error is recorded for the L2 fail-fast path.
  • Remove unlimited_native and resources_for_tester compile-time features. The post-unlimited_native way to ask for an unbounded native budget is native_price == 0 in block metadata (handled by
    validation as native_per_gas == 0 ⇒ free_native). The MAX_NATIVE_COMPUTATIONAL per-tx cap and block-level limits now apply uniformly, with no test-only exemption code paths. EVM tester, eth_runner,
    divergence validator, and the rig test profiles are migrated to set native_price = 0 in their block contexts. The TESTER_NATIVE_PER_GAS constant is removed (test rigs encode the equivalent ratio
    directly).
  • Remove dead per-tx BlockGasLimitTooHigh check. Moved from a tx-level recoverable check to a once-per-block MetadataOp::metadata_op invariant — the per-tx version was unreachable in practice. The
    corresponding InvalidTransaction::BlockGasLimitTooHigh variant is dropped along with its forward_system conversion arm.
  • Move intrinsic_computational_native_charged off ResourcesForTx. Lives on TxContextForPreAndPostProcessing (where it's actually consumed by after_execution and verify_intrinsic_native), making
    ResourcesForTx only hold actual resources.

Why ❔

  • The ResourcesCreationErrorPolicy trait existed to host two ~5-line differences between L1 and L2 (fail-vs-saturate, validation-vs-internal-error mapping). The
    dispatch surface (a trait with five methods, two impls, an arithmetic-error enum) outweighed what it actually expressed. With the single function and Option return, both call sites
    become 4 lines and the divergence is "L2 returns the error, L1 logs it."
  • Configuration belongs in metadata, not the type system. unlimited_native and resources_for_tester were compile-time flags that disabled different parts of the resource model for tests/bench.
    Migrating to native_price = 0 means a single runtime metadata field controls the same behavior; production binaries no longer need a parallel "tester" code path that diverges from real semantics.

Is this a breaking change?

  • Yes
  • No

It's breaking in terms of features, but corresponding features usage within the repo was updated; no uses outside the repo were found.

Checklist

  • PR title corresponds to the body of PR (we generate changelog entries from PRs).
  • Tests for the changes have been added / updated.
  • Documentation comments have been added / updated.
  • Code has been formatted.

@github-actions
Copy link
Copy Markdown
Contributor

Block-level effective cycles

Benchmark Symbol Base Eff Head Eff (%) Base Raw Head Raw (%) Base Blake Head Blake (%) Base Bigint Head Bigint (%) Base Keccak Head Keccak (%)
block_19299001 (keccak DA) process_block 208,601,280 208,615,631 (+0.01%) 158,531,432 158,545,783 (+0.01%) 410,630 410,630 (+0.00%) 7,681,862 7,681,862 (+0.00%) 3,193,080 3,193,080 (+0.00%)
block_19299001 (blobs DA) process_block 257,361,921 257,376,272 (+0.01%) 195,650,505 195,664,856 (+0.01%) 414,340 414,340 (+0.00%) 10,690,989 10,690,989 (+0.00%) 3,079,505 3,079,505 (+0.00%)
block_22244135 (keccak DA) process_block 134,741,585 134,763,256 (+0.02%) 106,268,773 106,290,444 (+0.02%) 172,040 172,040 (+0.00%) 5,054,163 5,054,163 (+0.00%) 1,375,880 1,375,880 (+0.00%)
block_22244135 (blobs DA) process_block 184,137,228 184,158,899 (+0.01%) 143,757,100 143,778,771 (+0.02%) 174,090 174,090 (+0.00%) 8,085,096 8,085,096 (+0.00%) 1,313,576 1,313,576 (+0.00%)
Block-level sub-phases
Benchmark Symbol Base Eff Head Eff (%) Base Raw Head Raw (%) Base Blake Head Blake (%) Base Bigint Head Bigint (%) Base Keccak Head Keccak (%)
block_19299001 (blobs DA) blob_versioned_hash 49,568,581 49,568,581 (+0.00%) 37,472,713 37,472,713 (+0.00%) 3,710 3,710 (+0.00%) 3,009,127 3,009,127 (+0.00%) 0 0 (+0.00%)
block_22244135 (blobs DA) blob_versioned_hash 49,849,981 49,849,981 (+0.00%) 37,693,449 37,693,449 (+0.00%) 2,050 2,050 (+0.00%) 3,030,933 3,030,933 (+0.00%) 0 0 (+0.00%)
block_19299001 (blobs DA) da_commitment 1,871,973 1,871,973 (+0.00%) 1,783,013 1,783,013 (+0.00%) 5,560 5,560 (+0.00%) 0 0 (+0.00%) 0 0 (+0.00%)
block_19299001 (keccak DA) da_commitment 2,675,608 2,675,608 (+0.00%) 2,134,944 2,134,944 (+0.00%) 5,560 5,560 (+0.00%) 0 0 (+0.00%) 112,926 112,926 (+0.00%)
block_22244135 (blobs DA) da_commitment 1,138,910 1,138,910 (+0.00%) 1,087,390 1,087,390 (+0.00%) 3,220 3,220 (+0.00%) 0 0 (+0.00%) 0 0 (+0.00%)
block_22244135 (keccak DA) da_commitment 1,590,322 1,590,322 (+0.00%) 1,292,182 1,292,182 (+0.00%) 3,220 3,220 (+0.00%) 0 0 (+0.00%) 61,655 61,655 (+0.00%)
block_19299001 (keccak DA) run_tx_loop 189,774,775 189,789,126 (+0.01%) 141,688,423 141,702,774 (+0.01%) 316,840 316,840 (+0.00%) 7,681,862 7,681,862 (+0.00%) 3,072,366 3,072,366 (+0.00%)
block_22244135 (keccak DA) run_tx_loop 123,362,164 123,383,835 (+0.02%) 96,074,964 96,096,635 (+0.02%) 115,300 115,300 (+0.00%) 5,054,163 5,054,163 (+0.00%) 1,306,437 1,306,437 (+0.00%)
block_19299001 (blobs DA) state_commitment_update 13,043,057 13,043,057 (+0.00%) 11,918,097 11,918,097 (+0.00%) 70,310 70,310 (+0.00%) 0 0 (+0.00%) 0 0 (+0.00%)
block_19299001 (keccak DA) state_commitment_update 13,043,045 13,043,045 (+0.00%) 11,918,085 11,918,085 (+0.00%) 70,310 70,310 (+0.00%) 0 0 (+0.00%) 0 0 (+0.00%)
block_22244135 (blobs DA) state_commitment_update 7,494,676 7,494,676 (+0.00%) 6,841,556 6,841,556 (+0.00%) 40,820 40,820 (+0.00%) 0 0 (+0.00%) 0 0 (+0.00%)
block_22244135 (keccak DA) state_commitment_update 7,493,320 7,493,320 (+0.00%) 6,840,200 6,840,200 (+0.00%) 40,820 40,820 (+0.00%) 0 0 (+0.00%) 0 0 (+0.00%)
block_19299001 (keccak DA) system_init 36,786 36,786 (+0.00%) 36,786 36,786 (+0.00%) 0 0 (+0.00%) 0 0 (+0.00%) 0 0 (+0.00%)
block_22244135 (keccak DA) system_init 36,786 36,786 (+0.00%) 36,786 36,786 (+0.00%) 0 0 (+0.00%) 0 0 (+0.00%) 0 0 (+0.00%)
Precompiles test-crate bench (synthetic workload, all labels)
Benchmark Symbol Base Eff Head Eff (%) Base Raw Head Raw (%) Base Blake Head Blake (%) Base Bigint Head Bigint (%) Base Keccak Head Keccak (%)
precompiles bn254_ecadd 53,315 53,315 (+0.00%) 47,863 47,863 (+0.00%) 0 0 (+0.00%) 1,363 1,363 (+0.00%) 0 0 (+0.00%)
precompiles bn254_ecmul 731,892 731,892 (+0.00%) 567,704 567,704 (+0.00%) 0 0 (+0.00%) 41,047 41,047 (+0.00%) 0 0 (+0.00%)
precompiles bn254_pairing 71,468,694 71,468,694 (+0.00%) 56,940,550 56,940,550 (+0.00%) 0 0 (+0.00%) 3,632,036 3,632,036 (+0.00%) 0 0 (+0.00%)
precompiles da_commitment 16,431 16,431 (+0.00%) 13,355 13,355 (+0.00%) 30 30 (+0.00%) 0 0 (+0.00%) 649 649 (+0.00%)
precompiles ecrecover 370,099 368,887 (-0.33%) 241,443 240,703 (-0.31%) 0 0 (+0.00%) 31,515 31,397 (-0.37%) 649 649 (+0.00%)
precompiles id 925 925 (+0.00%) 925 925 (+0.00%) 0 0 (+0.00%) 0 0 (+0.00%) 0 0 (+0.00%)
precompiles keccak 31,673 31,688 (+0.05%) 10,901 10,916 (+0.14%) 0 0 (+0.00%) 1 1 (+0.00%) 5,192 5,192 (+0.00%)
precompiles modexp 31,888,536 31,888,536 (+0.00%) 21,230,716 21,230,716 (+0.00%) 0 0 (+0.00%) 2,664,455 2,664,455 (+0.00%) 0 0 (+0.00%)
precompiles p256_verify 747,278 747,278 (+0.00%) 468,586 468,586 (+0.00%) 0 0 (+0.00%) 69,673 69,673 (+0.00%) 0 0 (+0.00%)
precompiles process_block 144,540,204 144,547,203 (+0.00%) 114,942,004 114,934,587 (-0.01%) 5,340 5,340 (+0.00%) 7,326,270 7,329,874 (+0.05%) 51,920 51,920 (+0.00%)
precompiles process_transaction 72,062,286 72,060,784 (-0.00%) 57,317,022 57,309,216 (-0.01%) 160 160 (+0.00%) 3,663,610 3,665,186 (+0.04%) 22,066 22,066 (+0.00%)
precompiles ripemd 8,010 8,010 (+0.00%) 8,010 8,010 (+0.00%) 0 0 (+0.00%) 0 0 (+0.00%) 0 0 (+0.00%)
precompiles run_tx_loop 144,074,439 144,077,040 (+0.00%) 114,592,547 114,580,732 (-0.01%) 180 180 (+0.00%) 7,326,270 7,329,874 (+0.05%) 43,483 43,483 (+0.00%)
precompiles sha256 13,315 13,315 (+0.00%) 13,315 13,315 (+0.00%) 0 0 (+0.00%) 0 0 (+0.00%) 0 0 (+0.00%)
precompiles state_commitment_update 188,672 188,743 (+0.04%) 148,992 149,063 (+0.05%) 2,480 2,480 (+0.00%) 0 0 (+0.00%) 0 0 (+0.00%)
precompiles system_init 41,514 41,514 (+0.00%) 41,514 41,514 (+0.00%) 0 0 (+0.00%) 0 0 (+0.00%) 0 0 (+0.00%)

Per-opcode

Per-opcode cycle diff

Opcode Count Med Cycles eff (%) Total Cycles eff (%) Med Cyc/Gas eff (%) Worst Cyc/Gas eff (%)
SHA3 2497 4,731 (+0.3%) 13,333,738 (+0.3%) 112.6 (+0.3%) 150.6

Per-precompile

Per-precompile per-execution ratios (head)
cycles = effective (raw + Blake×16 + BigInt×4 + Keccak×4)
precompile                count    med c/g    p95 c/g    p99 c/g    max c/g    med n/g    p95 n/g    p99 n/g    max n/g
------------------------------------------------------------------------------------------------------------------------
modexp                      105       70.6      713.4     2846.8     2847.5      300.0     1200.3     4814.0     4814.0
point_eval                    2     1025.1     1025.1     1025.1     1025.1     1262.1     1262.1     1262.1     1262.1
blake2f                       2      803.7      803.7      803.7      803.7        0.0        0.0        0.0        0.0
ecadd                        57      335.9      358.4      360.0      360.0      350.7      350.7      350.7      350.7
bls12_pairing_check           2      217.2      217.2      217.2      217.2        0.0        0.0        0.0        0.0
ecpairing                    31      168.4      185.6      185.6      185.6      398.2      428.6      428.6      428.6
keccak                     2497      112.1      127.0      139.5      150.6      478.8      558.6      626.8      684.2
ecmul                        37      119.0      124.1      126.5      126.5      127.3      127.3      127.3      127.3
ecrecover                    59      119.1      122.3      123.5      123.5      174.0      174.0      174.0      174.0
sha256                        4       68.4      123.3      123.3      123.3       80.6      131.5      131.5      131.5
p256_verify                  16      107.3      108.3      108.3      108.3      113.6      113.6      113.6      113.6
bls12_g1msm                   2      100.3      100.3      100.3      100.3        0.0        0.0        0.0        0.0
bls12_g2msm                   2       88.1       88.1       88.1       88.1        0.0        0.0        0.0        0.0
bls12_g2add                   2       45.0       45.0       45.0       45.0        0.0        0.0        0.0        0.0
identity                      5       22.7       34.3       34.3       34.3       31.4       48.1       48.1       48.1
bls12_g1add                   2       28.1       28.1       28.1       28.1        0.0        0.0        0.0        0.0
ripemd160                     4        4.4        7.4        7.4        7.4        8.1       13.1       13.1       13.1

@AntonD3 AntonD3 marked this pull request as ready for review May 27, 2026 11:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant