diff --git a/Makefile b/Makefile index 0365e86ea..28756022f 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/arbitrator/stylus/src/evm_api.rs b/arbitrator/stylus/src/evm_api.rs index 70e492d2f..7246ae316 100644 --- a/arbitrator/stylus/src/evm_api.rs +++ b/arbitrator/stylus/src/evm_api.rs @@ -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 @@ -264,10 +265,10 @@ impl EvmApi for GoEvmApi { address: Bytes20, offset: u32, size: u32, - gas: u64, + gas_left: u64, ) -> (Vec, 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, @@ -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)); diff --git a/arbitrator/stylus/src/host.rs b/arbitrator/stylus/src/host.rs index d59bcf6d3..343d96354 100644 --- a/arbitrator/stylus/src/host.rs +++ b/arbitrator/stylus/src/host.rs @@ -229,19 +229,19 @@ pub(crate) fn account_code( hostio!(env, account_code(address, offset, size, code)) } -pub(crate) fn account_codehash( +pub(crate) fn account_code_size( mut env: WasmEnvMut, address: u32, - ptr: u32, -) -> MaybeEscape { - hostio!(env, account_codehash(address, ptr)) +) -> Result { + hostio!(env, account_code_size(address)) } -pub(crate) fn account_code_size( +pub(crate) fn account_codehash( mut env: WasmEnvMut, address: u32, -) -> Result { - hostio!(env, account_code_size(address)) + ptr: u32, +) -> MaybeEscape { + hostio!(env, account_codehash(address, ptr)) } pub(crate) fn block_basefee(mut env: WasmEnvMut, ptr: u32) -> MaybeEscape { diff --git a/arbitrator/stylus/src/test/api.rs b/arbitrator/stylus/src/test/api.rs index 110dab98b..080f517bd 100644 --- a/arbitrator/stylus/src/test/api.rs +++ b/arbitrator/stylus/src/test/api.rs @@ -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!() } diff --git a/arbitrator/wasm-libraries/forward/src/main.rs b/arbitrator/wasm-libraries/forward/src/main.rs index a7dabd740..70268055b 100644 --- a/arbitrator/wasm-libraries/forward/src/main.rs +++ b/arbitrator/wasm-libraries/forward/src/main.rs @@ -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", ""], diff --git a/arbitrator/wasm-libraries/user-host/src/host.rs b/arbitrator/wasm-libraries/user-host/src/host.rs index 0fa5ab5fe..bcf48e4f9 100644 --- a/arbitrator/wasm-libraries/user-host/src/host.rs +++ b/arbitrator/wasm-libraries/user-host/src/host.rs @@ -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] diff --git a/arbos/programs/api.go b/arbos/programs/api.go index 4ca0458c1..0b3051566 100644 --- a/arbos/programs/api.go +++ b/arbos/programs/api.go @@ -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) @@ -60,8 +60,8 @@ type goClosures struct { emitLog emitLogType accountBalance accountBalanceType accountCode accountCodeType - accountCodeHash accountCodehashType accountCodeSize accountCodeSizeType + accountCodeHash accountCodehashType addPages addPagesType captureHostio captureHostioType } @@ -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) @@ -304,8 +304,8 @@ func newApiClosures( emitLog: emitLog, accountBalance: accountBalance, accountCode: accountCode, - accountCodeHash: accountCodehash, accountCodeSize: accountCodeSize, + accountCodeHash: accountCodehash, addPages: addPages, captureHostio: captureHostio, } diff --git a/arbos/programs/native_api.go b/arbos/programs/native_api.go index b7ae8e201..74471ce34 100644 --- a/arbos/programs/native_api.go +++ b/arbos/programs/native_api.go @@ -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); @@ -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);