-
Notifications
You must be signed in to change notification settings - Fork 621
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
31 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,35 @@ | ||
use database::{BenchmarkDB, FFADDRESS}; | ||
use revm::{ | ||
context::Context, database_interface::EmptyDB, primitives::{bytes::Bytes, Address, TxKind}, state::Bytecode | ||
context::Context, | ||
primitives::TxKind, | ||
state::Bytecode, | ||
}; | ||
use std::str::FromStr; | ||
|
||
use crate::exec::transact_custom_opcode; | ||
|
||
pub mod exec; | ||
pub mod handler; | ||
pub mod instructions; | ||
fn main() { | ||
let bytecode = Bytecode::new_legacy([ | ||
0x60, 0x01, // PUSH1 1 -> value to clz | ||
0x5f, // CLZ -> should be 255 | ||
0x60, 0x00, // PUSH1 0 -> memory starting position | ||
0x52, // MSTORE -> store 255 to memory at location 0 | ||
0x60, 0x20, // PUSH1 32 (length to return) | ||
0x60, 0x00, // PUSH1 0 (memory position) | ||
0xf3, // RETURN | ||
].into()); | ||
let bytecode = Bytecode::new_legacy( | ||
[ | ||
0x60, 0x01, // PUSH1 1 -> value to clz | ||
0x5f, // CLZ -> should be 255 | ||
0x60, 0x00, // PUSH1 0 -> memory starting position | ||
0x52, // MSTORE -> store 255 to memory at location 0 | ||
0x60, 0x20, // PUSH1 32 (length to return) | ||
0x60, 0x00, // PUSH1 0 (memory position) | ||
0xf3, // RETURN | ||
] | ||
.into(), | ||
); | ||
|
||
let zero_address = Address::default(); | ||
|
||
let mut ctx = Context::builder() | ||
.with_db(BenchmarkDB::new_bytecode(bytecode)) // Store bytecode in DB | ||
let mut ctx = Context::builder() | ||
.with_db(BenchmarkDB::new_bytecode(bytecode)) // Store bytecode in DB | ||
.modify_tx_chained(|tx| { | ||
tx.kind = TxKind::Call(FFADDRESS); // Call the address where bytecode is stored | ||
tx.kind = TxKind::Call(FFADDRESS); // Call the address where bytecode is stored | ||
}); | ||
|
||
let result = transact_custom_opcode(&mut ctx).expect("execution failed"); | ||
println!("Should return 0xff (255 in decimal) which is the clz of 256 bit value 0x01. The actual return is: {}", result.result.output().unwrap()); | ||
|
||
} | ||
} |