@@ -65,75 +65,51 @@ contract Simulator {
6565 }
6666
6767 function num_storage_slots_needed (SimulatorConfig calldata config ) public view returns (uint256 ) {
68- return current_storage_slot_index +
69- config.load_storage +
70- config.update_storage;
68+ return current_storage_slot_index + config.load_storage + config.update_storage;
7169 }
7270
7371 function num_accounts_needed (SimulatorConfig calldata config ) public view returns (uint160 ) {
74- return current_address_index +
75- config.load_accounts +
76- config.update_accounts;
72+ return current_address_index + config.load_accounts + config.update_accounts;
7773 }
7874
7975 function run (SimulatorConfig calldata config ) public {
8076 require (
81- current_storage_slot_index +
82- config.load_storage +
83- config.update_storage <=
84- num_storage_initialized,
77+ current_storage_slot_index + config.load_storage + config.update_storage <= num_storage_initialized,
8578 "Not enough storage slots to load/update "
8679 );
8780
8881 require (
89- current_address_index +
90- config.load_accounts +
91- config.update_accounts <=
92- num_address_initialized,
82+ current_address_index + config.load_accounts + config.update_accounts <= num_address_initialized,
9383 "Not enough accounts to load/update "
9484 );
9585
9686 // load storage slots using SLOAD in a loop. Ensure we're loading a unique storage slot each time.
9787 uint256 total = 0 ;
98- for (
99- uint256 i = current_storage_slot_index;
100- i < current_storage_slot_index + config.load_storage;
101- i++
102- ) {
103- total += uint256 (IExtsload (address (0x498581fF718922c3f8e6A244956aF099B2652b2b )).extsload (bytes32 (i)));
88+ for (uint256 i = current_storage_slot_index; i < current_storage_slot_index + config.load_storage; i++ ) {
89+ assembly {
90+ total := add (total, sload (i))
91+ }
10492 }
10593 current_storage_slot_index += config.load_storage;
10694
10795 // starting from current_storage_slot_index, update existing storage slots in a loop (using SSTORE)
108- for (
109- uint256 i = current_storage_slot_index;
110- i < current_storage_slot_index + config.update_storage;
111- i++
112- ) {
96+ for (uint256 i = current_storage_slot_index; i < current_storage_slot_index + config.update_storage; i++ ) {
11397 assembly {
11498 sstore (i, i)
11599 }
116100 }
117101 current_storage_slot_index += config.update_storage;
118102
119103 // starting from num_storage_initialized, create new storage slots in a loop (using SSTORE)
120- for (
121- uint256 i = num_storage_initialized;
122- i < num_storage_initialized + config.create_storage;
123- i++
124- ) {
104+ for (uint256 i = num_storage_initialized; i < num_storage_initialized + config.create_storage; i++ ) {
125105 assembly {
126106 sstore (i, i)
127107 }
128108 }
129109 num_storage_initialized += config.create_storage;
130110
131111 // starting from 0, delete storage slots in a loop (using SSTORE)
132- for (
133- uint256 i = num_storage_deleted;
134- i < num_storage_deleted + config.delete_storage;
135- i++
136- ) {
112+ for (uint256 i = num_storage_deleted; i < num_storage_deleted + config.delete_storage; i++ ) {
137113 assembly {
138114 sstore (i, 0 )
139115 }
@@ -161,17 +137,11 @@ contract Simulator {
161137 current_address_index += config.update_accounts;
162138
163139 for (uint256 i = 0 ; i < config.precompiles.length ; i++ ) {
164- run_precompile (
165- config.precompiles[i].precompile_address,
166- config.precompiles[i].num_calls
167- );
140+ run_precompile (config.precompiles[i].precompile_address, config.precompiles[i].num_calls);
168141 }
169142 }
170143
171- function run_precompile (
172- address precompile_address ,
173- uint256 num_calls
174- ) private {
144+ function run_precompile (address precompile_address , uint256 num_calls ) private {
175145 if (precompile_address == address (1 )) {
176146 run_ecrecover (num_calls);
177147 } else if (precompile_address == address (2 )) {
@@ -211,7 +181,6 @@ contract Simulator {
211181 }
212182 }
213183
214-
215184 function hashLongString () public pure returns (string memory ) {
216185 string memory longInput = string (
217186 abi.encodePacked (
@@ -287,7 +256,7 @@ contract Simulator {
287256 function run_modexp (uint256 num_iterations , bool use_long ) private {
288257 bytes memory base = "8 " ;
289258 bytes memory exponent = "9 " ;
290-
259+
291260 for (uint256 i = 0 ; i < num_iterations; i++ ) {
292261 if (use_long) {
293262 bytes memory modulus = abi.encodePacked (hashLongString (), i);
@@ -367,7 +336,8 @@ contract Simulator {
367336
368337 for (uint256 i = 0 ; i < num_iterations; i++ ) {
369338 uint32 rounds = uint32 (i);
370- (bool ok ,) = address (9 ).staticcall (abi.encodePacked (rounds, h[0 ], h[1 ], m[0 ], m[1 ], m[2 ], m[3 ], t[0 ], t[1 ], f));
339+ (bool ok ,) =
340+ address (9 ).staticcall (abi.encodePacked (rounds, h[0 ], h[1 ], m[0 ], m[1 ], m[2 ], m[3 ], t[0 ], t[1 ], f));
371341 require (ok, "Blake2f failed " );
372342 }
373343 }
@@ -449,7 +419,6 @@ contract Simulator {
449419 }
450420 }
451421
452-
453422 function run_g2msm (uint256 num_iterations ) private {
454423 bytes32 [8 ] memory p1;
455424 p1[0 ] = 0x00000000000000000000000000000000103121a2ceaae586d240843a39896732 ;
@@ -486,7 +455,7 @@ contract Simulator {
486455 p1[1 ] = 0xc3688c4f9774b905a14e3a3f171bac586c55e83ff97a1aeffb3af00adb22c6bb ;
487456 p1[2 ] = 0x0000000000000000000000000000000008b3f481e3aaa0f1a09e30ed741d8ae4 ;
488457 p1[3 ] = 0xfcf5e095d5d00af600db18cb2c04b3edd03cc744a2888ae40caa232946c5e7e1 ;
489-
458+
490459 bytes32 [8 ] memory p2;
491460 p2[0 ] = 0x00000000000000000000000000000000024aa2b2f08f0a91260805272dc51051 ;
492461 p2[1 ] = 0xc6e47ad4fa403b02b4510b647ae3d1770bac0326a805bbefd48056c8c121bdb8 ;
0 commit comments