@@ -36,6 +36,9 @@ type LedgerType = snarkvm_ledger_store::helpers::memory::ConsensusMemory<Mainnet
3636#[ cfg( feature = "rocks" ) ]
3737type LedgerType = snarkvm_ledger_store:: helpers:: rocksdb:: ConsensusDB < MainnetV0 > ;
3838
39+ /// Fixed RNG seed so benchmark inputs are reproducible across CI runs.
40+ const BENCH_RNG_SEED : u64 = 0xB34D_CAFE_CDEC_0123 ;
41+
3942fn initialize_vm < R : Rng + CryptoRng > (
4043 private_key : & PrivateKey < MainnetV0 > ,
4144 rng : & mut R ,
@@ -60,7 +63,7 @@ fn initialize_vm<R: Rng + CryptoRng>(
6063}
6164
6265fn deploy ( c : & mut Criterion ) {
63- let rng = & mut TestRng :: default ( ) ;
66+ let rng = & mut TestRng :: fixed ( BENCH_RNG_SEED ) ;
6467
6568 // Sample a new private key and address.
6669 let private_key = PrivateKey :: < MainnetV0 > :: new ( rng) . unwrap ( ) ;
@@ -93,7 +96,7 @@ function hello:
9396}
9497
9598fn execute ( c : & mut Criterion ) {
96- let rng = & mut TestRng :: default ( ) ;
99+ let rng = & mut TestRng :: fixed ( BENCH_RNG_SEED ^ 1 ) ;
97100
98101 // Sample a new private key and address.
99102 let private_key = PrivateKey :: < MainnetV0 > :: new ( rng) . unwrap ( ) ;
@@ -135,8 +138,12 @@ fn execute(c: &mut Criterion) {
135138
136139 // Bench the Transaction.write_le method using the LimitedWriter.
137140 c. bench_function ( "LimitedWriter::new - transfer_public" , |b| {
141+ let max = MainnetV0 :: LATEST_MAX_TRANSACTION_SIZE ( ) ;
138142 let mut buffer = Vec :: with_capacity ( 3000 ) ;
139- b. iter ( || transaction. write_le ( LimitedWriter :: new ( & mut buffer, MainnetV0 :: LATEST_MAX_TRANSACTION_SIZE ( ) ) ) )
143+ b. iter ( || {
144+ buffer. clear ( ) ;
145+ transaction. write_le ( LimitedWriter :: new ( & mut buffer, max) )
146+ } )
140147 } ) ;
141148
142149 // Bench the execution of transfer_public.
@@ -181,8 +188,12 @@ fn execute(c: &mut Criterion) {
181188
182189 // Bench the Transaction.write_le method using the LimitedWriter.
183190 c. bench_function ( "LimitedWriter::new - transfer_private" , |b| {
191+ let max = MainnetV0 :: LATEST_MAX_TRANSACTION_SIZE ( ) ;
184192 let mut buffer = Vec :: with_capacity ( 3000 ) ;
185- b. iter ( || transaction. write_le ( LimitedWriter :: new ( & mut buffer, MainnetV0 :: LATEST_MAX_TRANSACTION_SIZE ( ) ) ) )
193+ b. iter ( || {
194+ buffer. clear ( ) ;
195+ transaction. write_le ( LimitedWriter :: new ( & mut buffer, max) )
196+ } )
186197 } ) ;
187198
188199 // Bench the check_transaction method.
@@ -270,21 +281,24 @@ function main:
270281
271282 // Bench the Transaction.write_le method using the LimitedWriter.
272283 c. bench_function ( "LimitedWriter::new - too_big.aleo" , |b| {
273- let mut buffer = Vec :: with_capacity ( MainnetV0 :: LATEST_MAX_TRANSACTION_SIZE ( ) ) ;
274- b. iter ( || transaction. write_le ( LimitedWriter :: new ( & mut buffer, MainnetV0 :: LATEST_MAX_TRANSACTION_SIZE ( ) ) ) )
284+ let max = MainnetV0 :: LATEST_MAX_TRANSACTION_SIZE ( ) ;
285+ let mut buffer = Vec :: with_capacity ( max) ;
286+ b. iter ( || {
287+ buffer. clear ( ) ;
288+ transaction. write_le ( LimitedWriter :: new ( & mut buffer, max) )
289+ } )
275290 } ) ;
276291
277- // Bench the check_transaction method.
278- c. bench_function ( "Transaction::Execute(too_big.aleo) - verify" , |b| {
279- b. iter ( || vm. check_transaction ( & transaction, None , rng) )
292+ // At genesis height the active cap is V1 (128 KiB); this transaction exceeds it and rejects before full verification.
293+ c. bench_function ( "Transaction::Execute(too_big.aleo) - oversize_reject" , |b| {
294+ b. iter ( || {
295+ vm. check_transaction ( & transaction, None , rng)
296+ . expect_err ( "transaction must exceed V1 MAX_TRANSACTION_SIZE at genesis height" ) ;
297+ } )
280298 } ) ;
281299 }
282300}
283301
284- criterion_group ! {
285- name = transaction;
286- config = Criterion :: default ( ) . sample_size( 10 ) ;
287- targets = deploy, execute
288- }
302+ criterion_group ! ( transaction, deploy, execute) ;
289303
290304criterion_main ! ( transaction) ;
0 commit comments