Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(deps): bump alloy + revm #63

Merged
merged 7 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 57 additions & 14 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ revmc-context = { version = "0.1.0", path = "crates/revmc-context", default-feat
revmc-cranelift = { version = "0.1.0", path = "crates/revmc-cranelift", default-features = false }
revmc-llvm = { version = "0.1.0", path = "crates/revmc-llvm", default-features = false }

alloy-primitives = { version = "0.7.0", default-features = false }
revm = { version = "13.0.0", default-features = false }
revm-primitives = { version = "8.0.0", default-features = false }
revm-interpreter = { version = "9.0.0", default-features = false }
ruint = { version = "1.12.1", default-features = false }
alloy-primitives = { version = "0.8", default-features = false }
revm = { version = "14.0", default-features = false }
revm-primitives = { version = "9.0", default-features = false }
revm-interpreter = { version = "10.0", default-features = false }
ruint = { version = "1.12", default-features = false }

color-eyre = "0.6"
eyre = "0.6"
Expand Down
56 changes: 24 additions & 32 deletions crates/revmc-builtins/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ use alloc::{boxed::Box, vec::Vec};
use revm_interpreter::{
as_u64_saturated, as_usize_saturated, CallInputs, CallScheme, CallValue, CreateInputs,
EOFCreateInputs, FunctionStack, InstructionResult, InterpreterAction, InterpreterResult,
LoadAccountResult, SStoreResult,
};
use revm_primitives::{
eof::EofHeader, Address, Bytes, CreateScheme, Eof, Log, LogData, SpecId, KECCAK_EMPTY,
Expand Down Expand Up @@ -154,10 +153,10 @@ pub unsafe extern "C" fn __revmc_builtin_balance(
address: &mut EvmWord,
spec_id: SpecId,
) -> InstructionResult {
let (balance, is_cold) = try_host!(ecx.host.balance(address.to_address()));
*address = balance.into();
let state = try_host!(ecx.host.balance(address.to_address()));
*address = state.data.into();
let gas = if spec_id.is_enabled_in(SpecId::BERLIN) {
gas::warm_cold_cost(is_cold)
gas::warm_cold_cost(state.is_cold)
} else if spec_id.is_enabled_in(SpecId::ISTANBUL) {
// EIP-1884: Repricing for trie-size-dependent opcodes
700
Expand Down Expand Up @@ -206,14 +205,10 @@ pub unsafe extern "C" fn __revmc_builtin_extcodesize(
address: &mut EvmWord,
spec_id: SpecId,
) -> InstructionResult {
let (code, is_cold) = try_host!(ecx.host.code(address.to_address()));
let (code, state) = try_host!(ecx.host.code(address.to_address())).into_components();
*address = code.len().into();
let gas = if spec_id.is_enabled_in(SpecId::BERLIN) {
if is_cold {
gas::COLD_ACCOUNT_ACCESS_COST
} else {
gas::WARM_STORAGE_READ_COST
}
gas::warm_cold_cost_with_delegation(state)
} else if spec_id.is_enabled_in(SpecId::TANGERINE) {
700
} else {
Expand All @@ -229,9 +224,10 @@ pub unsafe extern "C" fn __revmc_builtin_extcodecopy(
rev![address, memory_offset, code_offset, len]: &mut [EvmWord; 4],
spec_id: SpecId,
) -> InstructionResult {
let (code, is_cold) = try_host!(ecx.host.code(address.to_address()));
let (code, state) = try_host!(ecx.host.code(address.to_address())).into_components();

let len = try_into_usize!(len);
gas_opt!(ecx, gas::extcodecopy_cost(spec_id, len as u64, is_cold));
gas_opt!(ecx, gas::extcodecopy_cost(spec_id, len as u64, state));
if len != 0 {
let memory_offset = try_into_usize!(memory_offset);
let code_offset = code_offset.to_u256();
Expand Down Expand Up @@ -269,14 +265,10 @@ pub unsafe extern "C" fn __revmc_builtin_extcodehash(
address: &mut EvmWord,
spec_id: SpecId,
) -> InstructionResult {
let (hash, is_cold) = try_host!(ecx.host.code_hash(address.to_address()));
let (hash, state) = try_host!(ecx.host.code_hash(address.to_address())).into_components();
*address = EvmWord::from_be_bytes(hash.0);
let gas = if spec_id.is_enabled_in(SpecId::BERLIN) {
if is_cold {
gas::COLD_ACCOUNT_ACCESS_COST
} else {
gas::WARM_STORAGE_READ_COST
}
gas::warm_cold_cost_with_delegation(state)
} else if spec_id.is_enabled_in(SpecId::ISTANBUL) {
700
} else {
Expand Down Expand Up @@ -314,8 +306,8 @@ pub unsafe extern "C" fn __revmc_builtin_self_balance(
ecx: &mut EvmContext<'_>,
slot: &mut EvmWord,
) -> InstructionResult {
let (balance, _) = try_host!(ecx.host.balance(ecx.contract.target_address));
*slot = balance.into();
let state = try_host!(ecx.host.balance(ecx.contract.target_address));
*slot = state.data.into();
InstructionResult::Continue
}

Expand Down Expand Up @@ -352,9 +344,9 @@ pub unsafe extern "C" fn __revmc_builtin_sload(
spec_id: SpecId,
) -> InstructionResult {
let address = ecx.contract.target_address;
let (res, is_cold) = try_opt!(ecx.host.sload(address, index.to_u256()));
gas!(ecx, gas::sload_cost(spec_id, is_cold));
*index = res.into();
let state = try_opt!(ecx.host.sload(address, index.to_u256()));
gas!(ecx, gas::sload_cost(spec_id, state.is_cold));
*index = state.data.into();
InstructionResult::Continue
}

Expand All @@ -366,11 +358,11 @@ pub unsafe extern "C" fn __revmc_builtin_sstore(
) -> InstructionResult {
ensure_non_staticcall!(ecx);

let SStoreResult { original_value: original, present_value: old, new_value: new, is_cold } =
let state =
try_opt!(ecx.host.sstore(ecx.contract.target_address, index.to_u256(), value.to_u256()));

gas_opt!(ecx, gas::sstore_cost(spec_id, original, old, new, ecx.gas.remaining(), is_cold));
ecx.gas.record_refund(gas::sstore_refund(spec_id, original, old, new));
gas_opt!(ecx, gas::sstore_cost(spec_id, &state.data, ecx.gas.remaining(), state.is_cold));
ecx.gas.record_refund(gas::sstore_refund(spec_id, &state.data));
InstructionResult::Continue
}

Expand Down Expand Up @@ -705,12 +697,13 @@ pub unsafe extern "C" fn __revmc_builtin_call(
};

// Load account and calculate gas cost.
let LoadAccountResult { is_cold, mut is_empty } = try_host!(ecx.host.load_account(to));
let mut account_load = try_host!(ecx.host.load_account_delegated(to));

if call_kind != CallKind::Call {
is_empty = false;
account_load.is_empty = false;
}

gas!(ecx, gas::call_cost(spec_id, transfers_value, is_cold, is_empty));
gas!(ecx, gas::call_cost(spec_id, transfers_value, account_load));

// EIP-150: Gas cost changes for IO-heavy operations
let mut gas_limit = if spec_id.is_enabled_in(SpecId::TANGERINE) {
Expand Down Expand Up @@ -794,11 +787,10 @@ pub unsafe extern "C" fn __revmc_builtin_ext_call(
return InstructionResult::CallNotAllowedInsideStatic;
}

let Some(LoadAccountResult { is_cold, is_empty }) = ecx.host.load_account(target_address)
else {
let Some(account_load) = ecx.host.load_account_delegated(target_address) else {
return InstructionResult::FatalExternalError;
};
let call_cost = gas::call_cost(spec_id, transfers_value, is_cold, is_empty);
let call_cost = gas::call_cost(spec_id, transfers_value, account_load);
gas!(ecx, call_cost);

let gas_reduce = core::cmp::max(ecx.gas.remaining() / 64, 5000);
Expand Down
15 changes: 7 additions & 8 deletions crates/revmc-cli/benches/iai.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,15 @@ fn setup_group(group: &mut BinaryBenchmarkGroup, is_ct: bool) {
run
};
let benches = [
// ("fibonacci", true),
// ("counter", true),
// ("hash_10k", true),
// ("bswap64", true),
// ("usdc_proxy", false),
// ("weth", false),
("fibonacci", true),
("counter", true),
("hash_10k", true),
("hash_10k-eof", true),
("snailtracer", true),
("snailtracer-eof", true),
("bswap64", true),
("usdc_proxy", false),
("weth", false),
// ("snailtracer", false),
// ("snailtracer-eof", false),
];
for (bench, small) in benches {
if !is_ct && !small {
Expand Down
28 changes: 20 additions & 8 deletions crates/revmc-context/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -817,33 +817,44 @@ mod tests {
fn env_mut(&mut self) -> &mut Env {
self.0
}
fn load_account(
fn load_account_delegated(
&mut self,
address: Address,
) -> Option<revm_interpreter::LoadAccountResult> {
) -> Option<revm_interpreter::AccountLoad> {
unimplemented!()
}
fn block_hash(&mut self, number: u64) -> Option<revm_primitives::B256> {
unimplemented!()
}
fn balance(&mut self, address: Address) -> Option<(U256, bool)> {
fn balance(&mut self, address: Address) -> Option<revm_interpreter::StateLoad<U256>> {
unimplemented!()
}
fn code(&mut self, address: Address) -> Option<(revm_primitives::Bytes, bool)> {
fn code(
&mut self,
address: Address,
) -> Option<revm_interpreter::Eip7702CodeLoad<Bytes>> {
unimplemented!()
}
fn code_hash(&mut self, address: Address) -> Option<(revm_primitives::B256, bool)> {
fn code_hash(
&mut self,
address: Address,
) -> Option<revm_interpreter::Eip7702CodeLoad<revm_primitives::FixedBytes<32>>>
{
unimplemented!()
}
fn sload(&mut self, address: Address, index: U256) -> Option<(U256, bool)> {
fn sload(
&mut self,
address: Address,
index: U256,
) -> Option<revm_interpreter::StateLoad<U256>> {
unimplemented!()
}
fn sstore(
&mut self,
address: Address,
index: U256,
value: U256,
) -> Option<revm_interpreter::SStoreResult> {
) -> Option<revm_interpreter::StateLoad<revm_interpreter::SStoreResult>> {
unimplemented!()
}
fn tload(&mut self, address: Address, index: U256) -> U256 {
Expand All @@ -859,7 +870,8 @@ mod tests {
&mut self,
address: Address,
target: Address,
) -> Option<revm_interpreter::SelfDestructResult> {
) -> Option<revm_interpreter::StateLoad<revm_interpreter::SelfDestructResult>>
{
unimplemented!()
}
}
Expand Down
Loading