Skip to content

Commit

Permalink
reorder hostios
Browse files Browse the repository at this point in the history
  • Loading branch information
rachel-bousfield committed Jan 30, 2024
1 parent b9f43a4 commit c21deff
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 31 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -468,12 +468,12 @@ contracts/test/prover/proofs/%.json: $(arbitrator_cases)/%.wasm $(prover_bin)

.make/lint: $(DEP_PREDICATE) build-node-deps $(ORDER_ONLY_PREDICATE) .make
go run linter/pointercheck/pointer.go ./...
#golangci-lint run --fix
golangci-lint run --fix
yarn --cwd contracts solhint
@touch $@

.make/fmt: $(DEP_PREDICATE) build-node-deps .make/yarndeps $(ORDER_ONLY_PREDICATE) .make
#golangci-lint run --disable-all -E gofmt --fix
golangci-lint run --disable-all -E gofmt --fix
cargo fmt -p arbutil -p prover -p jit -p stylus --manifest-path arbitrator/Cargo.toml -- --check
cargo fmt --all --manifest-path arbitrator/wasm-testsuite/Cargo.toml -- --check
cargo fmt --all --manifest-path arbitrator/langs/rust/Cargo.toml -- --check
Expand Down
13 changes: 7 additions & 6 deletions arbitrator/stylus/src/evm_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ pub struct GoEvmApi {
size: u32,
gas_cost: *mut u64,
),
pub account_code_size: unsafe extern "C" fn(id: usize, address: Bytes20, gas_cost: *mut u64) -> u32, // code size
pub account_code_size:
unsafe extern "C" fn(id: usize, address: Bytes20, gas_cost: *mut u64) -> u32, // code size
pub account_codehash:
unsafe extern "C" fn(id: usize, address: Bytes20, gas_cost: *mut u64) -> Bytes32, // codehash
pub add_pages: unsafe extern "C" fn(id: usize, pages: u16) -> u64, // gas cost
Expand Down Expand Up @@ -264,10 +265,10 @@ impl EvmApi for GoEvmApi {
address: Bytes20,
offset: u32,
size: u32,
gas: u64,
gas_left: u64,
) -> (Vec<u8>, u64) {
let mut data = RustBytes::new(vec![]);
let mut cost = gas; // pass amount left
let mut cost = gas_left; // pass amount left
call!(
self,
account_code,
Expand All @@ -280,12 +281,12 @@ impl EvmApi for GoEvmApi {
(into_vec!(data), cost)
}

fn account_code_size(&mut self, address: Bytes20, gas: u64) -> (u32, u64) {
let mut cost = gas; // pass amount left
fn account_code_size(&mut self, address: Bytes20, gas_left: u64) -> (u32, u64) {
let mut cost = gas_left; // pass amount left
let size = call!(self, account_code_size, address, ptr!(cost));
(size, cost)
}

fn account_codehash(&mut self, address: Bytes20) -> (Bytes32, u64) {
let mut cost = 0;
let value = call!(self, account_codehash, address, ptr!(cost));
Expand Down
14 changes: 7 additions & 7 deletions arbitrator/stylus/src/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,19 +229,19 @@ pub(crate) fn account_code<E: EvmApi>(
hostio!(env, account_code(address, offset, size, code))
}

pub(crate) fn account_codehash<E: EvmApi>(
pub(crate) fn account_code_size<E: EvmApi>(
mut env: WasmEnvMut<E>,
address: u32,
ptr: u32,
) -> MaybeEscape {
hostio!(env, account_codehash(address, ptr))
) -> Result<u32, Escape> {
hostio!(env, account_code_size(address))
}

pub(crate) fn account_code_size<E: EvmApi>(
pub(crate) fn account_codehash<E: EvmApi>(
mut env: WasmEnvMut<E>,
address: u32,
) -> Result<u32, Escape> {
hostio!(env, account_code_size(address))
ptr: u32,
) -> MaybeEscape {
hostio!(env, account_codehash(address, ptr))
}

pub(crate) fn block_basefee<E: EvmApi>(mut env: WasmEnvMut<E>, ptr: u32) -> MaybeEscape {
Expand Down
4 changes: 2 additions & 2 deletions arbitrator/stylus/src/test/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,11 +172,11 @@ impl EvmApi for TestEvmApi {
unimplemented!()
}

fn account_codehash(&mut self, _address: Bytes20) -> (Bytes32, u64) {
fn account_code_size(&mut self, _address: Bytes20, _gas_left: u64) -> (u32, u64) {
unimplemented!()
}

fn account_code_size(&mut self, _address: Bytes20, _gas_left: u64) -> (u32, u64) {
fn account_codehash(&mut self, _address: Bytes20) -> (Bytes32, u64) {
unimplemented!()
}

Expand Down
2 changes: 1 addition & 1 deletion arbitrator/wasm-libraries/forward/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ const HOSTIOS: [[&str; 3]; 33] = [
["emit_log", "i32 i32 i32", ""],
["account_balance", "i32 i32", ""],
["account_code", "i32 i32 i32 i32", "i32"],
["account_codehash", "i32 i32", ""],
["account_code_size", "i32", "i32"],
["account_codehash", "i32 i32", ""],
["evm_gas_left", "", "i64"],
["evm_ink_left", "", "i64"],
["block_basefee", "i32", ""],
Expand Down
8 changes: 4 additions & 4 deletions arbitrator/wasm-libraries/user-host/src/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,13 @@ pub unsafe extern "C" fn user_host__account_code(
}

#[no_mangle]
pub unsafe extern "C" fn user_host__account_codehash(address: u32, ptr: u32) {
hostio!(account_codehash(address, ptr))
pub unsafe extern "C" fn user_host__account_code_size(address: u32) -> u32 {
hostio!(account_code_size(address))
}

#[no_mangle]
pub unsafe extern "C" fn user_host__account_code_size(address: u32) -> u32 {
hostio!(account_code_size(address))
pub unsafe extern "C" fn user_host__account_codehash(address: u32, ptr: u32) {
hostio!(account_codehash(address, ptr))
}

#[no_mangle]
Expand Down
8 changes: 4 additions & 4 deletions arbos/programs/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ type create2Type func(
type getReturnDataType func(offset uint32, size uint32) []byte
type emitLogType func(data []byte, topics uint32) error
type accountBalanceType func(address common.Address) (value common.Hash, cost uint64)
type accountCodehashType func(address common.Address) (value common.Hash, cost uint64)
type accountCodeType func(address common.Address, gas uint64) ([]byte, uint64)
type accountCodeSizeType func(address common.Address, gas uint64) (uint32, uint64)
type accountCodehashType func(address common.Address) (value common.Hash, cost uint64)
type addPagesType func(pages uint16) (cost uint64)
type captureHostioType func(name string, args, outs []byte, startInk, endInk uint64)

Expand All @@ -60,8 +60,8 @@ type goClosures struct {
emitLog emitLogType
accountBalance accountBalanceType
accountCode accountCodeType
accountCodeHash accountCodehashType
accountCodeSize accountCodeSizeType
accountCodeHash accountCodehashType
addPages addPagesType
captureHostio captureHostioType
}
Expand Down Expand Up @@ -264,7 +264,7 @@ func newApiClosures(
// In the future it'll be possible to know the size of a contract before loading it.
// For now, require the worst case before doing the load.

metaCost := vm.WasmAccountTouchCost(evm.StateDB, address)
metaCost := vm.WasmAccountTouchCost(evm.StateDB, address) + params.ExtcodeCopyBaseEIP150
loadCost := 3 * am.WordsForBytes(params.MaxCodeSize)
sentry := am.SaturatingUAdd(metaCost, loadCost)

Expand Down Expand Up @@ -304,8 +304,8 @@ func newApiClosures(
emitLog: emitLog,
accountBalance: accountBalance,
accountCode: accountCode,
accountCodeHash: accountCodehash,
accountCodeSize: accountCodeSize,
accountCodeHash: accountCodehash,
addPages: addPages,
captureHostio: captureHostio,
}
Expand Down
10 changes: 5 additions & 5 deletions arbos/programs/native_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,6 @@ Bytes32 accountBalanceWrap(usize api, Bytes20 address, u64 * cost) {
return accountBalanceImpl(api, address, cost);
}
Bytes32 accountCodeHashImpl(usize api, Bytes20 address, u64 * cost);
Bytes32 accountCodeHashWrap(usize api, Bytes20 address, u64 * cost) {
return accountCodeHashImpl(api, address, cost);
}
void accountCodeImpl(usize api, RustBytes * data, Bytes20 address, u32 offset, u32 size, u64 * cost);
void accountCodeWrap(usize api, RustBytes * data, Bytes20 address, u32 offset, u32 size, u64 * cost) {
return accountCodeImpl(api, data, address, offset, size, cost);
Expand All @@ -81,6 +76,11 @@ void accountCodeSizeWrap(usize api, Bytes20 address, u64 * cost) {
return accountCodeSizeImpl(api, address, cost);
}
Bytes32 accountCodeHashImpl(usize api, Bytes20 address, u64 * cost);
Bytes32 accountCodeHashWrap(usize api, Bytes20 address, u64 * cost) {
return accountCodeHashImpl(api, address, cost);
}
u64 addPagesImpl(usize api, u16 pages);
u64 addPagesWrap(usize api, u16 pages) {
return addPagesImpl(api, pages);
Expand Down

0 comments on commit c21deff

Please sign in to comment.