-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: make runner example runnable (#44)
* feat: make runner example runnable * com * fix * com
- Loading branch information
Showing
5 changed files
with
55 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#[allow(dead_code)] | ||
const FIBONACCI_CODE: &[u8] = | ||
&hex!("5f355f60015b8215601a578181019150909160019003916005565b9150505f5260205ff3"); | ||
#[allow(dead_code)] | ||
const FIBONACCI_HASH: [u8; 32] = | ||
hex!("ab1ad1211002e1ddb8d9a4ef58a902224851f6a0273ee3e87276a8d21e649ce8"); |
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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
use revm::{ | ||
db::{CacheDB, EmptyDB}, | ||
primitives::{address, hex, AccountInfo, Bytecode, TransactTo, U256}, | ||
}; | ||
use revmc_examples_runner::build_evm; | ||
|
||
include!("./common.rs"); | ||
|
||
fn main() { | ||
let num = | ||
std::env::args().nth(1).map(|s| s.parse().unwrap()).unwrap_or_else(|| U256::from(100)); | ||
// The bytecode runs fib(input + 1), so we need to subtract 1. | ||
let actual_num = num.saturating_sub(U256::from(1)); | ||
|
||
let db = CacheDB::new(EmptyDB::new()); | ||
let mut evm = build_evm(db); | ||
let fibonacci_address = address!("0000000000000000000000000000000000001234"); | ||
evm.db_mut().insert_account_info( | ||
fibonacci_address, | ||
AccountInfo { | ||
code_hash: FIBONACCI_HASH.into(), | ||
code: Some(Bytecode::new_raw(FIBONACCI_CODE.into())), | ||
..Default::default() | ||
}, | ||
); | ||
evm.context.evm.env.tx.transact_to = TransactTo::Call(fibonacci_address); | ||
evm.context.evm.env.tx.data = actual_num.to_be_bytes_vec().into(); | ||
let result = evm.transact().unwrap(); | ||
// eprintln!("{:#?}", result.result); | ||
|
||
println!("fib({num}) = {}", U256::from_be_slice(result.result.output().unwrap())); | ||
} |