diff --git a/crates/evm/src/instructions/memory_operations.cairo b/crates/evm/src/instructions/memory_operations.cairo index cf625ece7..47401703a 100644 --- a/crates/evm/src/instructions/memory_operations.cairo +++ b/crates/evm/src/instructions/memory_operations.cairo @@ -14,7 +14,7 @@ impl MemoryOperation of MemoryOperationTrait { /// MLOAD operation. /// Load word from memory and push to stack. fn exec_mload(ref self: ExecutionContext) -> Result<(), EVMError> { - Result::Ok(()) + panic_with_felt252('MLOAD not implement yet') } /// 0x52 - MSTORE operation. diff --git a/crates/evm/src/tests/test_instructions/test_memory_operations.cairo b/crates/evm/src/tests/test_instructions/test_memory_operations.cairo index 0890335d5..801bf6156 100644 --- a/crates/evm/src/tests/test_instructions/test_memory_operations.cairo +++ b/crates/evm/src/tests/test_instructions/test_memory_operations.cairo @@ -44,6 +44,44 @@ fn test_pc_gets_updated_properly_1() { assert(ctx.stack.pop().unwrap() == 9000, 'updating PC failed'); } +// 0x51 - MLOAD + +#[test] +#[available_gas(20000000000)] +#[should_panic(expected: ('MLOAD not implement yet',))] +fn test_exec_mload_should_load_a_value_from_memory() { + assert_mload(0x1, 0, 0x1, 32); +} + +#[test] +#[available_gas(20000000000)] +#[should_panic(expected: ('MLOAD not implement yet',))] +fn test_exec_mload_should_load_a_value_from_memory_with_memory_expansion() { + assert_mload(0x1, 16, 0x100000000000000000000000000000000, 64); +} + +#[test] +#[available_gas(20000000000)] +#[should_panic(expected: ('MLOAD not implement yet',))] +fn test_exec_mload_should_load_a_value_from_memory_with_offset_larger_than_msize() { + assert_mload(0x1, 684, 0x0, 736); +} + +fn assert_mload(value: u256, offset: u256, expected_value: u256, expected_memory_size: u32) { + // Given + let mut ctx = setup_execution_context(); + ctx.memory.store(value, 0); + + ctx.stack.push(offset); + + // When + ctx.exec_mload(); + + // Then + assert(ctx.stack.len() == 1, 'stack should have one element'); + assert(ctx.stack.pop().unwrap() == expected_value, 'mload failed'); + assert(ctx.memory.bytes_len == expected_memory_size, 'memory size error'); +} #[test] #[available_gas(20000000)]