Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[EVM-Equivalent-YUL] Add exp and signextend opcodes #1615

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion contracts
104 changes: 104 additions & 0 deletions core/lib/multivm/src/versions/vm_latest/tests/evm_simulator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,110 @@ fn test_basic_mulmod_vectors() {
);
}

#[test]
fn test_basic_exp_vectors() {
// Here we just try to test some small EVM contracts and ensure that they work.
assert_eq!(
test_evm_vector(
vec![
// push32 9
hex::decode("7F").unwrap(),
u256_to_h256(9.into()).0.to_vec(),
// push32 5
hex::decode("7F").unwrap(),
u256_to_h256(5.into()).0.to_vec(),
// exp
hex::decode("0A").unwrap(),
// push32 0
hex::decode("7F").unwrap(),
H256::zero().0.to_vec(),
// sstore
hex::decode("55").unwrap(),
]
.into_iter()
.concat()
),
1_953_125.into()
);
assert_eq!(
test_evm_vector(
vec![
// push32 0
hex::decode("7F").unwrap(),
H256::zero().0.to_vec(),
// push32 19
hex::decode("7F").unwrap(),
u256_to_h256(19.into()).0.to_vec(),
// exp
hex::decode("0A").unwrap(),
// push32 0
hex::decode("7F").unwrap(),
H256::zero().0.to_vec(),
// sstore
hex::decode("55").unwrap(),
]
.into_iter()
.concat()
),
1.into()
);
}

#[test]
fn test_basic_signextend_vectors() {
// Here we just try to test some small EVM contracts and ensure that they work.
let mut expected_result: [u8; 32] = [0u8; 32];
hex::decode_to_slice(
"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffb4da6c",
&mut expected_result,
)
.unwrap();
assert_eq!(
test_evm_vector(
vec![
// push32 179,624,556
hex::decode("7F").unwrap(),
u256_to_h256(179_624_556.into()).0.to_vec(),
// push32 2
hex::decode("7F").unwrap(),
u256_to_h256(2.into()).0.to_vec(),
// signextend
hex::decode("0B").unwrap(),
// push32 0
hex::decode("7F").unwrap(),
H256::zero().0.to_vec(),
// sstore
hex::decode("55").unwrap(),
]
.into_iter()
.concat()
),
h256_to_u256(H256::from_slice(&expected_result))
);
assert_eq!(
test_evm_vector(
vec![
// push32 179,624,556
hex::decode("7F").unwrap(),
u256_to_h256(179_624_556.into()).0.to_vec(),
// push32 3
hex::decode("7F").unwrap(),
u256_to_h256(3.into()).0.to_vec(),
// signextend
hex::decode("0B").unwrap(),
// push32 0
hex::decode("7F").unwrap(),
H256::zero().0.to_vec(),
// sstore
hex::decode("55").unwrap(),
]
.into_iter()
.concat()
),
179_624_556.into()
);
}

fn assert_deployed_hash<H: HistoryMode>(
tester: &mut VmTester<H>,
address: Address,
Expand Down
Loading