-
Notifications
You must be signed in to change notification settings - Fork 455
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into fix/deploy-script-gastoken
- Loading branch information
Showing
27 changed files
with
1,020 additions
and
454 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
use std::fmt::Display; | ||
|
||
pub enum ParamType { | ||
I32, | ||
I64, | ||
} | ||
|
||
impl Display for ParamType { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
use ParamType::*; | ||
match self { | ||
I32 => write!(f, "i32"), | ||
I64 => write!(f, "i64"), | ||
} | ||
} | ||
} | ||
|
||
use ParamType::*; | ||
|
||
/// order matters! | ||
pub const HOSTIOS: [(&str, &[ParamType], &[ParamType]); 42] = [ | ||
("read_args", &[I32], &[]), | ||
("write_result", &[I32, I32], &[]), | ||
("exit_early", &[I32], &[]), | ||
("storage_load_bytes32", &[I32, I32], &[]), | ||
("storage_cache_bytes32", &[I32, I32], &[]), | ||
("storage_flush_cache", &[I32], &[]), | ||
("transient_load_bytes32", &[I32, I32], &[]), | ||
("transient_store_bytes32", &[I32, I32], &[]), | ||
("call_contract", &[I32, I32, I32, I32, I64, I32], &[I32]), | ||
("delegate_call_contract", &[I32, I32, I32, I64, I32], &[I32]), | ||
("static_call_contract", &[I32, I32, I32, I64, I32], &[I32]), | ||
("create1", &[I32, I32, I32, I32, I32], &[]), | ||
("create2", &[I32, I32, I32, I32, I32, I32], &[]), | ||
("read_return_data", &[I32, I32, I32], &[I32]), | ||
("return_data_size", &[], &[I32]), | ||
("emit_log", &[I32, I32, I32], &[]), | ||
("account_balance", &[I32, I32], &[]), | ||
("account_code", &[I32, I32, I32, I32], &[I32]), | ||
("account_code_size", &[I32], &[I32]), | ||
("account_codehash", &[I32, I32], &[]), | ||
("evm_gas_left", &[], &[I64]), | ||
("evm_ink_left", &[], &[I64]), | ||
("block_basefee", &[I32], &[]), | ||
("chainid", &[], &[I64]), | ||
("block_coinbase", &[I32], &[]), | ||
("block_gas_limit", &[], &[I64]), | ||
("block_number", &[], &[I64]), | ||
("block_timestamp", &[], &[I64]), | ||
("contract_address", &[I32], &[]), | ||
("math_div", &[I32, I32], &[]), | ||
("math_mod", &[I32, I32], &[]), | ||
("math_pow", &[I32, I32], &[]), | ||
("math_add_mod", &[I32, I32, I32], &[]), | ||
("math_mul_mod", &[I32, I32, I32], &[]), | ||
("msg_reentrant", &[], &[I32]), | ||
("msg_sender", &[I32], &[]), | ||
("msg_value", &[I32], &[]), | ||
("native_keccak256", &[I32, I32, I32], &[]), | ||
("tx_gas_price", &[I32], &[]), | ||
("tx_ink_price", &[], &[I32]), | ||
("tx_origin", &[I32], &[]), | ||
("pay_for_memory_grow", &[I32], &[]), | ||
]; |
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,89 @@ | ||
use arbutil::hostios::HOSTIOS; | ||
use std::{env, fmt::Write, fs, path::Path}; | ||
|
||
pub fn gen_forwarder(out_path: &Path) { | ||
let mut wat = String::new(); | ||
macro_rules! wln { | ||
($($text:tt)*) => { | ||
writeln!(wat, $($text)*).unwrap(); | ||
}; | ||
} | ||
let s = " "; | ||
|
||
wln!("(module"); | ||
|
||
macro_rules! group { | ||
($list:expr, $kind:expr) => { | ||
(!$list.is_empty()) | ||
.then(|| { | ||
format!( | ||
" ({} {})", | ||
$kind, | ||
$list | ||
.iter() | ||
.map(|x| x.to_string()) | ||
.collect::<Vec<_>>() | ||
.join(" ") | ||
) | ||
}) | ||
.unwrap_or_default() | ||
}; | ||
} | ||
|
||
wln!("{s};; symbols to re-export"); | ||
for (name, ins, outs) in HOSTIOS { | ||
let params = group!(ins, "param"); | ||
let result = group!(outs, "result"); | ||
wln!(r#"{s}(import "user_host" "{name}" (func $_{name}{params}{result}))"#); | ||
} | ||
wln!(); | ||
|
||
wln!("{s};; reserved offsets for future user_host imports"); | ||
for i in HOSTIOS.len()..512 { | ||
wln!("{s}(func $reserved_{i} unreachable)"); | ||
} | ||
wln!(); | ||
|
||
wln!( | ||
"{s};; allows user_host to request a trap\n\ | ||
{s}(global $trap (mut i32) (i32.const 0))\n\ | ||
{s}(func $check\n\ | ||
{s}{s}global.get $trap ;; see if set\n\ | ||
{s}{s}(global.set $trap (i32.const 0)) ;; reset the flag\n\ | ||
{s}{s}(if (then (unreachable)))\n\ | ||
{s})\n\ | ||
{s}(func (export \"forward__set_trap\")\n\ | ||
{s}{s}(global.set $trap (i32.const 1))\n\ | ||
{s})\n" | ||
); | ||
|
||
wln!("{s};; user linkage"); | ||
for (name, ins, outs) in HOSTIOS { | ||
let params = group!(ins, "param"); | ||
let result = group!(outs, "result"); | ||
wln!("{s}(func (export \"vm_hooks__{name}\"){params}{result}"); | ||
|
||
for i in 0..ins.len() { | ||
wln!("{s}{s}local.get {i}"); | ||
} | ||
|
||
wln!( | ||
"{s}{s}call $_{name}\n\ | ||
{s}{s}call $check\n\ | ||
{s})" | ||
); | ||
} | ||
|
||
wln!(")"); | ||
eprintln!("{}", &wat); | ||
|
||
let wasm = wasmer::wat2wasm(wat.as_bytes()).unwrap(); | ||
|
||
fs::write(out_path, wasm.as_ref()).unwrap(); | ||
} | ||
|
||
fn main() { | ||
let out_dir = env::var("OUT_DIR").unwrap(); | ||
let forwarder_path = Path::new(&out_dir).join("forwarder.wasm"); | ||
gen_forwarder(&forwarder_path); | ||
} |
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
Oops, something went wrong.