From aff2ea798c62344cabba6c07dda4070a1ca05f74 Mon Sep 17 00:00:00 2001 From: enitrat Date: Fri, 6 Sep 2024 16:15:33 +0200 Subject: [PATCH] fmt --- crates/evm/src/create_helpers.cairo | 6 +- crates/evm/src/gas.cairo | 4 +- .../src/instructions/logging_operations.cairo | 18 +++- crates/evm/src/instructions/sha3.cairo | 94 +++++++++++++++---- crates/evm/src/interpreter.cairo | 8 +- crates/evm/src/precompiles/ec_recover.cairo | 4 +- crates/evm/src/precompiles/identity.cairo | 3 +- crates/evm/src/precompiles/sha256.cairo | 3 +- 8 files changed, 113 insertions(+), 27 deletions(-) diff --git a/crates/evm/src/create_helpers.cairo b/crates/evm/src/create_helpers.cairo index 9127f701e..5e7a7d061 100644 --- a/crates/evm/src/create_helpers.cairo +++ b/crates/evm/src/create_helpers.cairo @@ -60,9 +60,9 @@ impl CreateHelpersImpl of CreateHelpers { CreateType::Create2 => { let calldata_words = ceil32(size) / 32; gas::CREATE - + gas::KECCAK256WORD * calldata_words.into() - + memory_expansion.expansion_cost - + init_code_gas + + gas::KECCAK256WORD * calldata_words.into() + + memory_expansion.expansion_cost + + init_code_gas }, }; self.charge_gas(charged_gas)?; diff --git a/crates/evm/src/gas.cairo b/crates/evm/src/gas.cairo index d0b2dd9bf..dd9e90a7b 100644 --- a/crates/evm/src/gas.cairo +++ b/crates/evm/src/gas.cairo @@ -168,7 +168,9 @@ fn calculate_memory_gas_cost(size_in_bytes: usize) -> u128 { fn memory_expansion(current_size: usize, operations: Span<(usize, usize)>) -> MemoryExpansion { let mut max_size = current_size; - for (offset, size) in operations { + for ( + offset, size + ) in operations { if *size != 0 { let end = *offset + *size; if end > max_size { diff --git a/crates/evm/src/instructions/logging_operations.cairo b/crates/evm/src/instructions/logging_operations.cairo index e19360c38..89b8e21d0 100644 --- a/crates/evm/src/instructions/logging_operations.cairo +++ b/crates/evm/src/instructions/logging_operations.cairo @@ -197,7 +197,11 @@ mod tests { let mut vm = VMBuilderTrait::new_with_presets().build(); vm.memory.store_with_expansion(Bounded::::MAX, 0); - vm.memory.store_with_expansion(0x0123456789ABCDEF000000000000000000000000000000000000000000000000, 0x20); + vm + .memory + .store_with_expansion( + 0x0123456789ABCDEF000000000000000000000000000000000000000000000000, 0x20 + ); vm.stack.push(0x00).expect('push failed'); vm.stack.push(Bounded::::MAX).expect('push failed'); @@ -234,7 +238,11 @@ mod tests { let mut vm = VMBuilderTrait::new_with_presets().build(); vm.memory.store_with_expansion(Bounded::::MAX, 0); - vm.memory.store_with_expansion(0x0123456789ABCDEF000000000000000000000000000000000000000000000000, 0x20); + vm + .memory + .store_with_expansion( + 0x0123456789ABCDEF000000000000000000000000000000000000000000000000, 0x20 + ); vm.stack.push(Bounded::::MAX).expect('push failed'); vm.stack.push(0x00).expect('push failed'); @@ -364,7 +372,11 @@ mod tests { let mut vm = VMBuilderTrait::new_with_presets().build(); vm.memory.store_with_expansion(Bounded::::MAX, 0); - vm.memory.store_with_expansion(0x0123456789ABCDEF000000000000000000000000000000000000000000000000, 0x20); + vm + .memory + .store_with_expansion( + 0x0123456789ABCDEF000000000000000000000000000000000000000000000000, 0x20 + ); vm.stack.push(Bounded::::MAX).expect('push failed'); vm.stack.push(0x00).expect('push failed'); diff --git a/crates/evm/src/instructions/sha3.cairo b/crates/evm/src/instructions/sha3.cairo index 73ba94c00..1884b9d4d 100644 --- a/crates/evm/src/instructions/sha3.cairo +++ b/crates/evm/src/instructions/sha3.cairo @@ -169,7 +169,11 @@ mod tests { vm.stack.push(0x00).expect('push failed'); vm.stack.push(0x00).expect('push failed'); - vm.memory.store_with_expansion(0xFFFFFFFF00000000000000000000000000000000000000000000000000000000, 0); + vm + .memory + .store_with_expansion( + 0xFFFFFFFF00000000000000000000000000000000000000000000000000000000, 0 + ); // When vm.exec_sha3().expect('exec_sha3 failed'); @@ -193,7 +197,11 @@ mod tests { vm.stack.push(0x05).expect('push failed'); vm.stack.push(0x04).expect('push failed'); - vm.memory.store_with_expansion(0xFFFFFFFF00000000000000000000000000000000000000000000000000000000, 0); + vm + .memory + .store_with_expansion( + 0xFFFFFFFF00000000000000000000000000000000000000000000000000000000, 0 + ); // When vm.exec_sha3().expect('exec_sha3 failed'); @@ -215,7 +223,11 @@ mod tests { vm.stack.push(24).expect('push failed'); vm.stack.push(10).expect('push failed'); - vm.memory.store_with_expansion(0xFFFFFFFF00000000000000000000000000000000000000000000000000000000, 0); + vm + .memory + .store_with_expansion( + 0xFFFFFFFF00000000000000000000000000000000000000000000000000000000, 0 + ); // When vm.exec_sha3().expect('exec_sha3 failed'); @@ -234,7 +246,11 @@ mod tests { vm.stack.push(0xFFFFF).expect('push failed'); vm.stack.push(1000).expect('push failed'); - vm.memory.store_with_expansion(0xFFFFFFFF00000000000000000000000000000000000000000000000000000000, 0); + vm + .memory + .store_with_expansion( + 0xFFFFFFFF00000000000000000000000000000000000000000000000000000000, 0 + ); // When vm.exec_sha3().expect('exec_sha3 failed'); @@ -256,7 +272,11 @@ mod tests { vm.stack.push(1000000).expect('push failed'); vm.stack.push(2).expect('push failed'); - vm.memory.store_with_expansion(0xFFFFFFFF00000000000000000000000000000000000000000000000000000000, 0); + vm + .memory + .store_with_expansion( + 0xFFFFFFFF00000000000000000000000000000000000000000000000000000000, 0 + ); // When vm.exec_sha3().expect('exec_sha3 failed'); @@ -278,8 +298,16 @@ mod tests { vm.stack.push(1000000).expect('push failed'); vm.stack.push(2).expect('push failed'); - vm.memory.store_with_expansion(0xFFFFFFFF00000000000000000000000000000000000000000000000000000000, 0); - vm.memory.store_with_expansion(0xFFFFFFFF00000000000000000000000000000000000000000000000000000000, 0); + vm + .memory + .store_with_expansion( + 0xFFFFFFFF00000000000000000000000000000000000000000000000000000000, 0 + ); + vm + .memory + .store_with_expansion( + 0xFFFFFFFF00000000000000000000000000000000000000000000000000000000, 0 + ); // When vm.exec_sha3().expect('exec_sha3 failed'); @@ -301,7 +329,11 @@ mod tests { vm.stack.push(1).expect('push failed'); vm.stack.push(2048).expect('push failed'); - vm.memory.store_with_expansion(0xFFFFFFFF00000000000000000000000000000000000000000000000000000000, 0); + vm + .memory + .store_with_expansion( + 0xFFFFFFFF00000000000000000000000000000000000000000000000000000000, 0 + ); // When vm.exec_sha3().expect('exec_sha3 failed'); @@ -323,7 +355,11 @@ mod tests { vm.stack.push(0).expect('push failed'); vm.stack.push(1024).expect('push failed'); - vm.memory.store_with_expansion(0xFFFFFFFF00000000000000000000000000000000000000000000000000000000, 0); + vm + .memory + .store_with_expansion( + 0xFFFFFFFF00000000000000000000000000000000000000000000000000000000, 0 + ); // When vm.exec_sha3().expect('exec_sha3 failed'); @@ -345,7 +381,11 @@ mod tests { vm.stack.push(32).expect('push failed'); vm.stack.push(2016).expect('push failed'); - vm.memory.store_with_expansion(0xFFFFFFFF00000000000000000000000000000000000000000000000000000000, 0); + vm + .memory + .store_with_expansion( + 0xFFFFFFFF00000000000000000000000000000000000000000000000000000000, 0 + ); // When vm.exec_sha3().expect('exec_sha3 failed'); @@ -367,7 +407,11 @@ mod tests { vm.stack.push(32).expect('push failed'); vm.stack.push(0).expect('push failed'); - vm.memory.store_with_expansion(0xFAFFFFFF000000E500000077000000DEAD0000000004200000FADE0000450000, 0); + vm + .memory + .store_with_expansion( + 0xFAFFFFFF000000E500000077000000DEAD0000000004200000FADE0000450000, 0 + ); // When vm.exec_sha3().expect('exec_sha3 failed'); @@ -389,7 +433,11 @@ mod tests { vm.stack.push(31).expect('push failed'); vm.stack.push(0).expect('push failed'); - vm.memory.store_with_expansion(0xFAFFFFFF000000E500000077000000DEAD0000000004200000FADE0000450000, 0); + vm + .memory + .store_with_expansion( + 0xFAFFFFFF000000E500000077000000DEAD0000000004200000FADE0000450000, 0 + ); // When vm.exec_sha3().expect('exec_sha3 failed'); @@ -411,7 +459,11 @@ mod tests { vm.stack.push(33).expect('push failed'); vm.stack.push(0).expect('push failed'); - vm.memory.store_with_expansion(0xFAFFFFFF000000E500000077000000DEAD0000000004200000FADE0000450000, 0); + vm + .memory + .store_with_expansion( + 0xFAFFFFFF000000E500000077000000DEAD0000000004200000FADE0000450000, 0 + ); // When vm.exec_sha3().expect('exec_sha3 failed'); @@ -437,7 +489,9 @@ mod tests { while mem_dst <= 0x0C80 { vm .memory - .store_with_expansion(0xFAFAFAFA00000000000000000000000000000000000000000000000000000000, mem_dst); + .store_with_expansion( + 0xFAFAFAFA00000000000000000000000000000000000000000000000000000000, mem_dst + ); mem_dst += 0x20; }; @@ -459,7 +513,11 @@ mod tests { let mut vm = VMBuilderTrait::new_with_presets().build(); let mut to_hash: Array = Default::default(); - vm.memory.store_with_expansion(0xFAFFFFFF000000E500000077000000DEAD0000000004200000FADE0000450000, 0); + vm + .memory + .store_with_expansion( + 0xFAFFFFFF000000E500000077000000DEAD0000000004200000FADE0000450000, 0 + ); let mut size = 32; let mut offset = 0; @@ -483,7 +541,11 @@ mod tests { let mut vm = VMBuilderTrait::new_with_presets().build(); let mut to_hash: Array = Default::default(); - vm.memory.store_with_expansion(0xFAFFFFFF000000E500000077000000DEAD0000000004200000FADE0000450000, 0); + vm + .memory + .store_with_expansion( + 0xFAFFFFFF000000E500000077000000DEAD0000000004200000FADE0000450000, 0 + ); let mut size = 33; let mut offset = 0; diff --git a/crates/evm/src/interpreter.cairo b/crates/evm/src/interpreter.cairo index fa963caf0..4c420ab5c 100644 --- a/crates/evm/src/interpreter.cairo +++ b/crates/evm/src/interpreter.cairo @@ -244,7 +244,13 @@ impl EVMImpl of EVMTrait { } fn execute_opcode(ref self: VM, opcode: u8) -> Result<(), EVMError> { - println!("Address {:?}, opcode {:?}, pc {:?}, gas left in call {:?}", self.message().code_address.evm, opcode, self.pc(), self.gas_left()); + println!( + "Address {:?}, opcode {:?}, pc {:?}, gas left in call {:?}", + self.message().code_address.evm, + opcode, + self.pc(), + self.gas_left() + ); // Call the appropriate function based on the opcode. if opcode == 0 { // STOP diff --git a/crates/evm/src/precompiles/ec_recover.cairo b/crates/evm/src/precompiles/ec_recover.cairo index 82748a415..1336de202 100644 --- a/crates/evm/src/precompiles/ec_recover.cairo +++ b/crates/evm/src/precompiles/ec_recover.cairo @@ -80,7 +80,9 @@ mod tests { use evm::precompiles::ec_recover::EcRecover; use evm::stack::StackTrait; use evm::test_utils::setup_test_storages; - use evm::test_utils::{VMBuilderTrait, MemoryTestUtilsTrait, native_token, other_starknet_address}; + use evm::test_utils::{ + VMBuilderTrait, MemoryTestUtilsTrait, native_token, other_starknet_address + }; use snforge_std::{start_mock_call, test_address}; use utils::helpers::{U256Trait, ToBytes, FromBytes}; diff --git a/crates/evm/src/precompiles/identity.cairo b/crates/evm/src/precompiles/identity.cairo index c34f753a0..9e478f013 100644 --- a/crates/evm/src/precompiles/identity.cairo +++ b/crates/evm/src/precompiles/identity.cairo @@ -32,7 +32,8 @@ mod tests { use evm::precompiles::identity::Identity; use evm::stack::StackTrait; use evm::test_utils::{ - VMBuilderTrait, MemoryTestUtilsTrait, native_token, other_starknet_address, setup_test_storages + VMBuilderTrait, MemoryTestUtilsTrait, native_token, other_starknet_address, + setup_test_storages }; use snforge_std::{start_mock_call, test_address}; diff --git a/crates/evm/src/precompiles/sha256.cairo b/crates/evm/src/precompiles/sha256.cairo index 3ba9626fd..489fc9a15 100644 --- a/crates/evm/src/precompiles/sha256.cairo +++ b/crates/evm/src/precompiles/sha256.cairo @@ -62,7 +62,8 @@ mod tests { use evm::precompiles::sha256::Sha256; use evm::stack::StackTrait; use evm::test_utils::{ - VMBuilderTrait, MemoryTestUtilsTrait, native_token, other_starknet_address, setup_test_storages + VMBuilderTrait, MemoryTestUtilsTrait, native_token, other_starknet_address, + setup_test_storages }; use snforge_std::{start_mock_call}; use utils::helpers::ToBytes;