Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
rachel-bousfield committed Mar 13, 2024
1 parent 698b076 commit cc2728f
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 30 deletions.
4 changes: 2 additions & 2 deletions arbitrator/arbutil/src/evm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 16 additions & 16 deletions arbitrator/arbutil/src/evm/req.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use eyre::{bail, eyre, Result};
use std::collections::hash_map::Entry;

pub trait RequestHandler<D: DataReader>: Send + 'static {
fn handle_request(&mut self, req_type: EvmApiMethod, req_data: &[u8]) -> (Vec<u8>, D, u64);
fn request(&mut self, req_type: EvmApiMethod, req_data: impl AsRef<[u8]>) -> (Vec<u8>, D, u64);
}

pub struct EvmApiRequestor<D: DataReader, H: RequestHandler<D>> {
Expand All @@ -35,8 +35,8 @@ impl<D: DataReader, H: RequestHandler<D>> EvmApiRequestor<D, H> {
}
}

fn handle_request(&mut self, req_type: EvmApiMethod, req_data: &[u8]) -> (Vec<u8>, D, u64) {
self.handler.handle_request(req_type, req_data)
fn request(&mut self, req_type: EvmApiMethod, req_data: impl AsRef<[u8]>) -> (Vec<u8>, D, u64) {
self.handler.request(req_type, req_data)
}

/// Call out to a contract.
Expand All @@ -54,7 +54,7 @@ impl<D: DataReader, H: RequestHandler<D>> EvmApiRequestor<D, H> {
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);
Expand All @@ -81,7 +81,7 @@ impl<D: DataReader, H: RequestHandler<D>> EvmApiRequestor<D, H> {
}
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);
Expand All @@ -103,9 +103,7 @@ impl<D: DataReader, H: RequestHandler<D>> EvmApi<D> for EvmApiRequestor<D, H> {
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())
});
Expand Down Expand Up @@ -134,8 +132,11 @@ impl<D: DataReader, H: RequestHandler<D>> EvmApi<D> for EvmApiRequestor<D, H> {
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));
}
Expand Down Expand Up @@ -211,15 +212,15 @@ impl<D: DataReader, H: RequestHandler<D>> EvmApi<D> for EvmApiRequestor<D, H> {
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()))
}
Ok(())
}

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)
}

Expand All @@ -233,19 +234,18 @@ impl<D: DataReader, H: RequestHandler<D>> EvmApi<D> for EvmApiRequestor<D, H> {
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(
Expand All @@ -265,6 +265,6 @@ impl<D: DataReader, H: RequestHandler<D>> EvmApi<D> for EvmApiRequestor<D, H> {
request.extend(name.as_bytes());
request.extend(args);
request.extend(outs);
self.handle_request(EvmApiMethod::CaptureHostIO, &request);
self.request(EvmApiMethod::CaptureHostIO, request);
}
}
1 change: 1 addition & 0 deletions arbitrator/arbutil/src/evm/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions arbitrator/jit/src/stylus_backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ struct CothreadRequestor {
}

impl RequestHandler<VecReader> for CothreadRequestor {
fn handle_request(
fn request(
&mut self,
req_type: EvmApiMethod,
req_data: &[u8],
req_data: impl AsRef<[u8]>,
) -> (Vec<u8>, 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) {
Expand Down
2 changes: 1 addition & 1 deletion arbitrator/langs/c
Submodule c updated 1 files
+1 −1 include/hostio.h
6 changes: 3 additions & 3 deletions arbitrator/stylus/src/evm_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ macro_rules! ptr {
}

impl RequestHandler<GoSliceData> for NativeRequestHandler {
fn handle_request(
fn request(
&mut self,
req_type: EvmApiMethod,
req_data: &[u8],
req_data: impl AsRef<[u8]>,
) -> (Vec<u8>, GoSliceData, u64) {
let mut result = GoSliceData::null();
let mut raw_data = GoSliceData::null();
Expand All @@ -39,7 +39,7 @@ impl RequestHandler<GoSliceData> 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),
Expand Down
6 changes: 3 additions & 3 deletions arbitrator/wasm-libraries/user-host/src/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,15 +145,15 @@ impl UserHostRequester {
}

impl RequestHandler<VecReader> for UserHostRequester {
fn handle_request(
fn request(
&mut self,
req_type: EvmApiMethod,
req_data: &[u8],
req_data: impl AsRef<[u8]>,
) -> (Vec<u8>, 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(),
)
}
}
Expand Down
1 change: 1 addition & 0 deletions arbos/programs/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion arbos/programs/testconstants.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,5 @@ func testConstants() error {
if err := assertEq(3, WriteProtection, C.EvmApiStatus_WriteProtection); err != nil {
return err
}

return nil
}

0 comments on commit cc2728f

Please sign in to comment.