Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
enitrat committed Sep 6, 2024
1 parent 5b1816d commit aff2ea7
Show file tree
Hide file tree
Showing 8 changed files with 113 additions and 27 deletions.
6 changes: 3 additions & 3 deletions crates/evm/src/create_helpers.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
Expand Down
4 changes: 3 additions & 1 deletion crates/evm/src/gas.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
18 changes: 15 additions & 3 deletions crates/evm/src/instructions/logging_operations.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,11 @@ mod tests {
let mut vm = VMBuilderTrait::new_with_presets().build();

vm.memory.store_with_expansion(Bounded::<u256>::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::<u256>::MAX).expect('push failed');
Expand Down Expand Up @@ -234,7 +238,11 @@ mod tests {
let mut vm = VMBuilderTrait::new_with_presets().build();

vm.memory.store_with_expansion(Bounded::<u256>::MAX, 0);
vm.memory.store_with_expansion(0x0123456789ABCDEF000000000000000000000000000000000000000000000000, 0x20);
vm
.memory
.store_with_expansion(
0x0123456789ABCDEF000000000000000000000000000000000000000000000000, 0x20
);

vm.stack.push(Bounded::<u256>::MAX).expect('push failed');
vm.stack.push(0x00).expect('push failed');
Expand Down Expand Up @@ -364,7 +372,11 @@ mod tests {
let mut vm = VMBuilderTrait::new_with_presets().build();

vm.memory.store_with_expansion(Bounded::<u256>::MAX, 0);
vm.memory.store_with_expansion(0x0123456789ABCDEF000000000000000000000000000000000000000000000000, 0x20);
vm
.memory
.store_with_expansion(
0x0123456789ABCDEF000000000000000000000000000000000000000000000000, 0x20
);

vm.stack.push(Bounded::<u256>::MAX).expect('push failed');
vm.stack.push(0x00).expect('push failed');
Expand Down
94 changes: 78 additions & 16 deletions crates/evm/src/instructions/sha3.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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');
Expand All @@ -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');
Expand All @@ -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');
Expand All @@ -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');
Expand All @@ -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');
Expand All @@ -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');
Expand All @@ -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');
Expand All @@ -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');
Expand All @@ -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');
Expand All @@ -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');
Expand All @@ -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');
Expand All @@ -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;
};

Expand All @@ -459,7 +513,11 @@ mod tests {
let mut vm = VMBuilderTrait::new_with_presets().build();
let mut to_hash: Array<u64> = Default::default();

vm.memory.store_with_expansion(0xFAFFFFFF000000E500000077000000DEAD0000000004200000FADE0000450000, 0);
vm
.memory
.store_with_expansion(
0xFAFFFFFF000000E500000077000000DEAD0000000004200000FADE0000450000, 0
);
let mut size = 32;
let mut offset = 0;

Expand All @@ -483,7 +541,11 @@ mod tests {
let mut vm = VMBuilderTrait::new_with_presets().build();
let mut to_hash: Array<u64> = Default::default();

vm.memory.store_with_expansion(0xFAFFFFFF000000E500000077000000DEAD0000000004200000FADE0000450000, 0);
vm
.memory
.store_with_expansion(
0xFAFFFFFF000000E500000077000000DEAD0000000004200000FADE0000450000, 0
);
let mut size = 33;
let mut offset = 0;

Expand Down
8 changes: 7 additions & 1 deletion crates/evm/src/interpreter.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion crates/evm/src/precompiles/ec_recover.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down
3 changes: 2 additions & 1 deletion crates/evm/src/precompiles/identity.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down
3 changes: 2 additions & 1 deletion crates/evm/src/precompiles/sha256.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit aff2ea7

Please sign in to comment.