mirror of
https://github.com/pezkuwichain/revive.git
synced 2026-04-24 18:18:02 +00:00
@@ -6,4 +6,11 @@ contract MSize {
|
||||
size := msize()
|
||||
}
|
||||
}
|
||||
|
||||
function mStore100() public pure returns (uint size) {
|
||||
assembly {
|
||||
mstore(100, msize())
|
||||
size := msize()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -163,7 +163,7 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn msize() {
|
||||
fn msize_plain() {
|
||||
sol!(
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
contract MSize {
|
||||
@@ -175,9 +175,9 @@ mod tests {
|
||||
include_str!("../contracts/MSize.sol"),
|
||||
false,
|
||||
);
|
||||
let (instance, export) = mock_runtime::prepare(&code, None);
|
||||
|
||||
let input = MSize::mSizeCall::new(()).abi_encode();
|
||||
let (instance, export) = mock_runtime::prepare(&code, None);
|
||||
let state = crate::mock_runtime::call(State::new(input), &instance, export);
|
||||
|
||||
assert_eq!(state.output.flags, 0);
|
||||
@@ -187,4 +187,32 @@ mod tests {
|
||||
let received = U256::from_be_bytes::<32>(state.output.data.try_into().unwrap());
|
||||
assert_eq!(received, expected);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn msize_non_word_sized_access() {
|
||||
sol!(
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
contract MSize {
|
||||
function mStore100() public pure returns (uint);
|
||||
}
|
||||
);
|
||||
let code = crate::compile_blob_with_options(
|
||||
"MSize",
|
||||
include_str!("../contracts/MSize.sol"),
|
||||
false,
|
||||
);
|
||||
let (instance, export) = mock_runtime::prepare(&code, None);
|
||||
|
||||
let input = MSize::mStore100Call::new(()).abi_encode();
|
||||
let state = crate::mock_runtime::call(State::new(input), &instance, export);
|
||||
|
||||
assert_eq!(state.output.flags, 0);
|
||||
|
||||
// https://docs.zksync.io/build/developer-reference/differences-with-ethereum.html#mstore-mload
|
||||
// "Unlike EVM, where the memory growth is in words, on zkEVM the memory growth is counted in bytes."
|
||||
// "For example, if you write mstore(100, 0) the msize on zkEVM will be 132, but on the EVM it will be 160."
|
||||
let expected = U256::try_from(132).unwrap();
|
||||
let received = U256::from_be_bytes::<32>(state.output.data.try_into().unwrap());
|
||||
assert_eq!(received, expected);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -201,5 +201,8 @@ where
|
||||
.build_ptr_to_int(heap_start, context.xlen_type(), "heap_start")?,
|
||||
"heap_size",
|
||||
)?;
|
||||
Ok(heap_size.as_basic_value_enum())
|
||||
Ok(context
|
||||
.builder()
|
||||
.build_int_z_extend(heap_size, context.field_type(), "heap_size_extended")?
|
||||
.as_basic_value_enum())
|
||||
}
|
||||
|
||||
@@ -89,5 +89,5 @@ where
|
||||
"return_data_copy_memcpy_from_return_data",
|
||||
)?;
|
||||
|
||||
Ok(())
|
||||
todo!("Build heap GEP to allocate if necessary")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user