diff --git a/arbitrator/arbutil/src/evm/mod.rs b/arbitrator/arbutil/src/evm/mod.rs index 72d0ec6e9..86ce2accc 100644 --- a/arbitrator/arbutil/src/evm/mod.rs +++ b/arbitrator/arbutil/src/evm/mod.rs @@ -14,10 +14,10 @@ pub const SSTORE_SENTRY_GAS: u64 = 2300; // params.ColdAccountAccessCostEIP2929 pub const COLD_ACCOUNT_GAS: u64 = 2600; -// params.WarmStorageReadCostEIP2929 +// params.ColdSloadCostEIP2929; pub const COLD_SLOAD_GAS: u64 = 2100; -// params.WarmSloadCostEIP2929; +// params.WarmStorageReadCostEIP2929 pub const WARM_SLOAD_GAS: u64 = 100; // params.LogGas and params.LogDataGas diff --git a/arbitrator/arbutil/src/evm/req.rs b/arbitrator/arbutil/src/evm/req.rs index d7cab0071..0243c408e 100644 --- a/arbitrator/arbutil/src/evm/req.rs +++ b/arbitrator/arbutil/src/evm/req.rs @@ -15,7 +15,7 @@ use eyre::{bail, eyre, Result}; use std::collections::hash_map::Entry; pub trait RequestHandler: Send + 'static { - fn handle_request(&mut self, req_type: EvmApiMethod, req_data: &[u8]) -> (Vec, D, u64); + fn request(&mut self, req_type: EvmApiMethod, req_data: impl AsRef<[u8]>) -> (Vec, D, u64); } pub struct EvmApiRequestor> { @@ -35,8 +35,8 @@ impl> EvmApiRequestor { } } - fn handle_request(&mut self, req_type: EvmApiMethod, req_data: &[u8]) -> (Vec, D, u64) { - self.handler.handle_request(req_type, req_data) + fn request(&mut self, req_type: EvmApiMethod, req_data: impl AsRef<[u8]>) -> (Vec, D, u64) { + self.handler.request(req_type, req_data) } /// Call out to a contract. @@ -54,7 +54,7 @@ impl> EvmApiRequestor { request.extend(gas.to_be_bytes()); request.extend(input); - let (res, data, cost) = self.handle_request(call_type, &request); + let (res, data, cost) = self.request(call_type, &request); let status: UserOutcomeKind = res[0].try_into().expect("unknown outcome"); let data_len = data.slice().len() as u32; self.last_return_data = Some(data); @@ -81,7 +81,7 @@ impl> EvmApiRequestor { } request.extend(code); - let (mut res, data, cost) = self.handle_request(create_type, &request); + let (mut res, data, cost) = self.request(create_type, request); if res.len() != 21 || res[0] == 0 { if !res.is_empty() { res.remove(0); @@ -103,9 +103,7 @@ impl> EvmApi for EvmApiRequestor { let mut cost = cache.read_gas(); let value = cache.entry(key).or_insert_with(|| { - let (res, _, gas) = self - .handler - .handle_request(EvmApiMethod::GetBytes32, key.as_slice()); + let (res, _, gas) = self.handler.request(EvmApiMethod::GetBytes32, key); cost = cost.saturating_add(gas).saturating_add(EVM_API_INK); StorageWord::known(res.try_into().unwrap()) }); @@ -134,8 +132,11 @@ impl> EvmApi for EvmApiRequestor { if clear { self.storage_cache.clear(); } + if data.len() == 8 { + return Ok(0); // no need to make request + } - let (res, _, cost) = self.handle_request(EvmApiMethod::SetTrieSlots, &data); + let (res, _, cost) = self.request(EvmApiMethod::SetTrieSlots, data); if res[0] != EvmApiStatus::Success.into() { bail!("{}", String::from_utf8_or_hex(res)); } @@ -211,7 +212,7 @@ impl> EvmApi for EvmApiRequestor { request.extend(topics.to_be_bytes()); request.extend(data); - let (res, _, _) = self.handle_request(EvmApiMethod::EmitLog, &request); + let (res, _, _) = self.request(EvmApiMethod::EmitLog, request); if !res.is_empty() { bail!(String::from_utf8(res).unwrap_or("malformed emit-log response".into())) } @@ -219,7 +220,7 @@ impl> EvmApi for EvmApiRequestor { } fn account_balance(&mut self, address: Bytes20) -> (Bytes32, u64) { - let (res, _, cost) = self.handle_request(EvmApiMethod::AccountBalance, address.as_slice()); + let (res, _, cost) = self.request(EvmApiMethod::AccountBalance, address); (res.try_into().unwrap(), cost) } @@ -233,19 +234,18 @@ impl> EvmApi for EvmApiRequestor { req.extend(address); req.extend(gas_left.to_be_bytes()); - let (_, data, cost) = self.handle_request(EvmApiMethod::AccountCode, &req); + let (_, data, cost) = self.request(EvmApiMethod::AccountCode, req); self.last_code = Some((address, data.clone())); (data, cost) } fn account_codehash(&mut self, address: Bytes20) -> (Bytes32, u64) { - let (res, _, cost) = self.handle_request(EvmApiMethod::AccountCodeHash, address.as_slice()); + let (res, _, cost) = self.request(EvmApiMethod::AccountCodeHash, address); (res.try_into().unwrap(), cost) } fn add_pages(&mut self, pages: u16) -> u64 { - self.handle_request(EvmApiMethod::AddPages, &pages.to_be_bytes()) - .2 + self.request(EvmApiMethod::AddPages, pages.to_be_bytes()).2 } fn capture_hostio( @@ -265,6 +265,6 @@ impl> EvmApi for EvmApiRequestor { request.extend(name.as_bytes()); request.extend(args); request.extend(outs); - self.handle_request(EvmApiMethod::CaptureHostIO, &request); + self.request(EvmApiMethod::CaptureHostIO, request); } } diff --git a/arbitrator/arbutil/src/evm/storage.rs b/arbitrator/arbutil/src/evm/storage.rs index 7fc4a6911..10d1ab799 100644 --- a/arbitrator/arbutil/src/evm/storage.rs +++ b/arbitrator/arbutil/src/evm/storage.rs @@ -8,6 +8,7 @@ use std::{ }; /// Represents the EVM word at a given key. +#[derive(Debug)] pub struct StorageWord { /// The current value of the slot. pub value: Bytes32, diff --git a/arbitrator/jit/src/stylus_backend.rs b/arbitrator/jit/src/stylus_backend.rs index 74a8d6ae1..61dbf258d 100644 --- a/arbitrator/jit/src/stylus_backend.rs +++ b/arbitrator/jit/src/stylus_backend.rs @@ -43,14 +43,14 @@ struct CothreadRequestor { } impl RequestHandler for CothreadRequestor { - fn handle_request( + fn request( &mut self, req_type: EvmApiMethod, - req_data: &[u8], + req_data: impl AsRef<[u8]>, ) -> (Vec, VecReader, u64) { let msg = MessageFromCothread { req_type: req_type as u32 + EVM_API_METHOD_REQ_OFFSET, - req_data: req_data.to_vec(), + req_data: req_data.as_ref().to_vec(), }; if let Err(error) = self.tx.send(msg) { diff --git a/arbitrator/langs/c b/arbitrator/langs/c index c7bbff75d..29fe05d68 160000 --- a/arbitrator/langs/c +++ b/arbitrator/langs/c @@ -1 +1 @@ -Subproject commit c7bbff75d5e3d4a49a722c4d029817f21a28dc27 +Subproject commit 29fe05d68672797572080084b0f5f0a282e298ef diff --git a/arbitrator/langs/rust b/arbitrator/langs/rust index c8951eab9..1fcef8387 160000 --- a/arbitrator/langs/rust +++ b/arbitrator/langs/rust @@ -1 +1 @@ -Subproject commit c8951eab9b5bd61b264d192241642bf316aa466e +Subproject commit 1fcef8387e5f337901f18f44250756c5bf08db40 diff --git a/arbitrator/stylus/src/evm_api.rs b/arbitrator/stylus/src/evm_api.rs index fdcc5b16a..d26737282 100644 --- a/arbitrator/stylus/src/evm_api.rs +++ b/arbitrator/stylus/src/evm_api.rs @@ -27,10 +27,10 @@ macro_rules! ptr { } impl RequestHandler for NativeRequestHandler { - fn handle_request( + fn request( &mut self, req_type: EvmApiMethod, - req_data: &[u8], + req_data: impl AsRef<[u8]>, ) -> (Vec, GoSliceData, u64) { let mut result = GoSliceData::null(); let mut raw_data = GoSliceData::null(); @@ -39,7 +39,7 @@ impl RequestHandler for NativeRequestHandler { (self.handle_request_fptr)( self.id, req_type as u32 + EVM_API_METHOD_REQ_OFFSET, - ptr!(RustSlice::new(req_data)), + ptr!(RustSlice::new(req_data.as_ref())), ptr!(cost), ptr!(result), ptr!(raw_data), diff --git a/arbitrator/wasm-libraries/user-host/src/program.rs b/arbitrator/wasm-libraries/user-host/src/program.rs index a6ec966c0..b43e632b9 100644 --- a/arbitrator/wasm-libraries/user-host/src/program.rs +++ b/arbitrator/wasm-libraries/user-host/src/program.rs @@ -145,15 +145,15 @@ impl UserHostRequester { } impl RequestHandler for UserHostRequester { - fn handle_request( + fn request( &mut self, req_type: EvmApiMethod, - req_data: &[u8], + req_data: impl AsRef<[u8]>, ) -> (Vec, VecReader, u64) { unsafe { self.send_request( req_type as u32 + EVM_API_METHOD_REQ_OFFSET, - req_data.to_vec(), + req_data.as_ref().to_vec(), ) } } diff --git a/arbos/programs/api.go b/arbos/programs/api.go index 73c1915da..390a3f43e 100644 --- a/arbos/programs/api.go +++ b/arbos/programs/api.go @@ -312,6 +312,7 @@ func newApiClosures( out, cost := getBytes32(key) return out[:], nil, cost case SetTrieSlots: + println("setting trie slots", len(input)) gasLeft := takeU64() gas := gasLeft status := setTrieSlots(takeRest(), &gas) diff --git a/arbos/programs/testconstants.go b/arbos/programs/testconstants.go index f37ccb4b0..cfaf42d88 100644 --- a/arbos/programs/testconstants.go +++ b/arbos/programs/testconstants.go @@ -84,6 +84,5 @@ func testConstants() error { if err := assertEq(3, WriteProtection, C.EvmApiStatus_WriteProtection); err != nil { return err } - return nil }