Skip to content

Commit

Permalink
remove poseidon code hash also code size field
Browse files Browse the repository at this point in the history
  • Loading branch information
lightsing committed Jan 2, 2025
1 parent cea2fde commit 1b7ef49
Show file tree
Hide file tree
Showing 19 changed files with 40 additions and 308 deletions.
6 changes: 2 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ jobs:
"--no-default-features",
"",
"--features=\"scroll\"",
"--features=\"scroll, scroll-poseidon-codehash\"",
"--features=\"all, scroll\"",
"--features=\"all, scroll, scroll-poseidon-codehash\"",
"--features=\"optimism\"",
"--features=\"all, optimism\""
]
Expand All @@ -47,7 +45,7 @@ jobs:
strategy:
fail-fast: false
matrix:
features: ["", "optimism,kzg-rs"]
features: [ "", "optimism,kzg-rs" ]
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
Expand All @@ -62,7 +60,7 @@ jobs:
strategy:
fail-fast: false
matrix:
features: ["", "serde", "std"]
features: [ "", "serde", "std" ]
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
Expand Down
33 changes: 0 additions & 33 deletions Cargo.lock

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

3 changes: 1 addition & 2 deletions bins/revm-test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ edition = "2021"
[dependencies]
bytes = "1.7"
hex = "0.4"
revm = { path = "../../crates/revm", version = "19.0.0", default-features=false }
revm = { path = "../../crates/revm", version = "19.0.0", default-features = false }
microbench = "0.5"
alloy-sol-macro = "0.8.11"
alloy-sol-types = "0.8.11"
Expand All @@ -29,4 +29,3 @@ name = "burntpix"

[features]
scroll = ["revm/scroll"]
scroll-poseidon-codehash = ["scroll", "revm/scroll-poseidon-codehash"]
1 change: 0 additions & 1 deletion bins/revme/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,3 @@ k256 = { version = "0.13.3", features = ["ecdsa"] }

[features]
scroll = ["revm/scroll"]
scroll-poseidon-codehash = ["scroll", "revm/scroll-poseidon-codehash"]
12 changes: 2 additions & 10 deletions bins/revme/src/cmd/statetest/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,19 +257,11 @@ pub fn execute_test_suite(
// Create database and insert cache
let mut cache_state = revm::CacheState::new(false);
for (address, info) in unit.pre {
#[cfg(feature = "scroll")]
let code_size = info.code.len();
let keccak_code_hash = keccak256(&info.code);
#[cfg(feature = "scroll-poseidon-codehash")]
let poseidon_code_hash = revm::primitives::poseidon(&info.code);
let code_hash = keccak256(&info.code);
let bytecode = to_analysed(Bytecode::new_raw(info.code));
let acc_info = revm::primitives::AccountInfo {
balance: info.balance,
#[cfg(feature = "scroll")]
code_size,
code_hash: keccak_code_hash,
#[cfg(feature = "scroll-poseidon-codehash")]
poseidon_code_hash,
code_hash,
code: Some(bytecode),
nonce: info.nonce,
};
Expand Down
4 changes: 0 additions & 4 deletions crates/interpreter/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,6 @@ scroll-default-handler = [
negate-scroll-default-handler = [
"revm-primitives/negate-scroll-default-handler",
]
scroll-poseidon-codehash = [
"scroll",
"revm-primitives/scroll-poseidon-codehash",
]

dev = [
"memory_limit",
Expand Down
4 changes: 0 additions & 4 deletions crates/interpreter/src/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,6 @@ pub trait Host {
/// Get code hash of `address` and if the account is cold.
fn code_hash(&mut self, address: Address) -> Option<StateLoad<B256>>;

#[cfg(feature = "scroll")]
/// Get code size of `address` and if the account is cold.
fn code_size(&mut self, address: Address) -> Option<(usize, bool)>;

/// Get storage value of `address` at `index` and if the account is cold.
fn sload(&mut self, address: Address, index: U256) -> Option<StateLoad<U256>>;

Expand Down
6 changes: 0 additions & 6 deletions crates/interpreter/src/host/dummy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,6 @@ impl Host for DummyHost {
Some(Default::default())
}

#[inline]
#[cfg(feature = "scroll")]
fn code_size(&mut self, _address: Address) -> Option<(usize, bool)> {
Some((0, false))
}

#[inline]
fn code_hash(&mut self, _address: Address) -> Option<StateLoad<B256>> {
Some(StateLoad::new(KECCAK_EMPTY, false))
Expand Down
17 changes: 0 additions & 17 deletions crates/interpreter/src/instructions/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ pub fn selfbalance<H: Host + ?Sized, SPEC: Spec>(interpreter: &mut Interpreter,
push!(interpreter, balance.data);
}

#[cfg(not(feature = "scroll"))]
pub fn extcodesize<H: Host + ?Sized, SPEC: Spec>(interpreter: &mut Interpreter, host: &mut H) {
pop_address!(interpreter, address);
let Some(code) = host.code(address) else {
Expand All @@ -62,22 +61,6 @@ pub fn extcodesize<H: Host + ?Sized, SPEC: Spec>(interpreter: &mut Interpreter,
push!(interpreter, U256::from(code.len()));
}

#[cfg(feature = "scroll")]
pub fn extcodesize<H: Host + ?Sized, SPEC: Spec>(interpreter: &mut Interpreter, host: &mut H) {
pop_address!(interpreter, address);
let Some((code_size, is_cold)) = host.code_size(address) else {
interpreter.instruction_result = InstructionResult::FatalExternalError;
return;
};
#[cfg(feature = "scroll")]
if is_cold && host.is_address_in_access_list(interpreter.contract.target_address) {
panic!("access list account should be either loaded or never accessed");
}
gas!(interpreter, warm_cold_cost(is_cold));

push!(interpreter, U256::from(code_size));
}

/// EIP-1052: EXTCODEHASH opcode
pub fn extcodehash<H: Host + ?Sized, SPEC: Spec>(interpreter: &mut Interpreter, host: &mut H) {
check!(interpreter, CONSTANTINOPLE);
Expand Down
4 changes: 0 additions & 4 deletions crates/primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,6 @@ serde = { version = "1.0", default-features = false, features = [
"rc",
], optional = true }

# scroll
poseidon-bn254 = { git = "https://github.com/scroll-tech/poseidon-bn254", branch = "master", features = ["bn254"], optional = true }

[build-dependencies]
hex = { version = "0.4", default-features = false }

Expand Down Expand Up @@ -103,7 +100,6 @@ scroll = []
# Scroll default handler enabled Scroll handler register by default in EvmBuilder.
scroll-default-handler = ["scroll"]
negate-scroll-default-handler = []
scroll-poseidon-codehash = ["scroll", "poseidon-bn254"]

dev = [
"memory_limit",
Expand Down
12 changes: 0 additions & 12 deletions crates/primitives/src/bytecode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,6 @@ impl Bytecode {
}
}

/// Calculate poseidon hash of the bytecode.
#[cfg(feature = "scroll-poseidon-codehash")]
pub fn poseidon_hash_slow(&self) -> B256 {
use crate::{poseidon, POSEIDON_EMPTY};

if self.is_empty() {
POSEIDON_EMPTY
} else {
poseidon(self.original_byte_slice())
}
}

/// Return reference to the EOF if bytecode is EOF.
#[inline]
pub const fn eof(&self) -> Option<&Arc<Eof>> {
Expand Down
81 changes: 9 additions & 72 deletions crates/primitives/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,14 +228,8 @@ pub struct AccountInfo {
pub balance: U256,
/// Account nonce.
pub nonce: u64,
#[cfg(feature = "scroll")]
/// code size,
pub code_size: usize,
/// code hash,
pub code_hash: B256,
#[cfg(feature = "scroll-poseidon-codehash")]
/// poseidon code hash, won't be calculated if code is not changed.
pub poseidon_code_hash: B256,
/// code: if None, `code_by_hash` will be used to fetch it if code needs to be loaded from
/// inside `revm`.
pub code: Option<Bytecode>,
Expand All @@ -245,11 +239,7 @@ impl Default for AccountInfo {
fn default() -> Self {
Self {
balance: U256::ZERO,
#[cfg(feature = "scroll")]
code_size: 0,
code_hash: KECCAK_EMPTY,
#[cfg(feature = "scroll-poseidon-codehash")]
poseidon_code_hash: crate::POSEIDON_EMPTY,
code: Some(Bytecode::default()),
nonce: 0,
}
Expand All @@ -259,19 +249,9 @@ impl Default for AccountInfo {
impl PartialEq for AccountInfo {
#[allow(clippy::let_and_return)]
fn eq(&self, other: &Self) -> bool {
let eq = self.balance == other.balance
self.balance == other.balance
&& self.nonce == other.nonce
&& self.code_hash == other.code_hash;

#[cfg(all(debug_assertions, feature = "scroll"))]
if eq {
assert_eq!(self.code_size, other.code_size);
#[cfg(feature = "scroll-poseidon-codehash")]
if self.poseidon_code_hash != B256::ZERO && other.poseidon_code_hash != B256::ZERO {
assert_eq!(self.poseidon_code_hash, other.poseidon_code_hash);
}
}
eq
&& self.code_hash == other.code_hash
}
}

Expand All @@ -288,12 +268,8 @@ impl AccountInfo {
Self {
balance,
nonce,
#[cfg(feature = "scroll")]
code_size: code.len(),
code: Some(code),
code_hash,
#[cfg(feature = "scroll-poseidon-codehash")]
poseidon_code_hash: B256::ZERO,
}
}

Expand All @@ -310,12 +286,8 @@ impl AccountInfo {
Self {
balance: self.balance,
nonce: self.nonce,
#[cfg(feature = "scroll")]
code_size: self.code_size,
code_hash: self.code_hash,
code: None,
#[cfg(feature = "scroll-poseidon-codehash")]
poseidon_code_hash: self.poseidon_code_hash,
}
}

Expand All @@ -341,15 +313,6 @@ impl AccountInfo {
/// - nonce is zero
pub fn is_empty(&self) -> bool {
let code_empty = self.is_empty_code_hash() || self.code_hash.is_zero();

#[cfg(all(feature = "scroll", debug_assertions))]
if code_empty {
assert_eq!(
self.code_size, 0,
"code size should be zero if code hash is empty"
);
}

code_empty && self.balance.is_zero() && self.nonce == 0
}

Expand All @@ -372,15 +335,6 @@ impl AccountInfo {
/// Returns true if the code hash is the Keccak256 hash of the empty string `""`.
#[inline]
pub fn is_empty_code_hash(&self) -> bool {
#[cfg(all(debug_assertions, feature = "scroll-poseidon-codehash"))]
if self.code_hash == KECCAK_EMPTY {
assert_eq!(self.code_size, 0);
assert!(
self.poseidon_code_hash == crate::POSEIDON_EMPTY
|| self.poseidon_code_hash == B256::ZERO
);
}

self.code_hash == KECCAK_EMPTY
}

Expand All @@ -397,30 +351,13 @@ impl AccountInfo {
}

pub fn from_bytecode(bytecode: Bytecode) -> Self {
let code_hash = bytecode.hash_slow();
cfg_if::cfg_if! {
if #[cfg(not(feature = "scroll"))] {
AccountInfo {
balance: U256::ZERO,
nonce: 1,
code: Some(bytecode),
code_hash,
}
} else {
let code_size = bytecode.len();
#[cfg(feature = "scroll-poseidon-codehash")]
let poseidon_code_hash = bytecode.poseidon_hash_slow();

AccountInfo {
balance: U256::ZERO,
nonce: 1,
code_size,
code: Some(bytecode),
code_hash,
#[cfg(feature = "scroll-poseidon-codehash")]
poseidon_code_hash,
}
}
let hash = bytecode.hash_slow();

AccountInfo {
balance: U256::ZERO,
nonce: 1,
code: Some(bytecode),
code_hash: hash,
}
}
}
Expand Down
Loading

0 comments on commit 1b7ef49

Please sign in to comment.