Skip to content
Open
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
2 changes: 1 addition & 1 deletion .github/workflows/seismic.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ jobs:
TEMP_DIR=$(mktemp -d)
# Temporarily checking out the test--new-storage-opcode-semantics branch that fixes storage opcode semantic tests.
# TODO(samlaf): switch back to seismic (default) branch after we merge https://github.com/SeismicSystems/seismic-solidity/pull/130
git clone -b test--new-storage-opcode-semantics https://github.com/SeismicSystems/seismic-solidity.git "$TEMP_DIR/seismic-solidity"
git clone -b update-precompile-semantic-test https://github.com/SeismicSystems/seismic-solidity.git "$TEMP_DIR/seismic-solidity"
echo "SEISMIC_SOLIDITY_PATH=$TEMP_DIR/seismic-solidity" >> $GITHUB_ENV
echo "seismic-solidity cloned to: $TEMP_DIR/seismic-solidity"
- name: Install latest ssolc release
Expand Down
2 changes: 0 additions & 2 deletions Cargo.lock

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

164 changes: 85 additions & 79 deletions bins/revme/src/cmd/semantics/evm_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ use revm::{
primitives::{Address, Bytes, FixedBytes, Log, TxKind, U256},
Context, DatabaseCommit, DatabaseRef, ExecuteEvm, InspectEvm, MainBuilder, MainContext,
};
use seismic_revm::{DefaultSeismicContext, SeismicBuilder};
use seismic_revm::{
precompiles::rng::domain_sep_rng::SchnorrkelKeypair, DefaultSeismicContext, SeismicBuilder,
};
use std::str::FromStr;

use crate::cmd::semantics::{test_cases::TestStep, utils::verify_emitted_events};
Expand Down Expand Up @@ -126,34 +128,36 @@ impl EvmExecutor {
.map_or(0, |account| account.nonce);
let deploy_out = if self.evm_version == EVMVersion::Mercury {
if trace {
let mut evm = Context::seismic()
.with_db(self.db.clone())
.modify_tx_chained(|tx| {
tx.base.caller = self.config.caller;
tx.base.kind = TxKind::Create;
tx.base.data = deploy_data.clone();
tx.base.value = value;
tx.base.nonce = nonce;
})
.modify_cfg_chained(|cfg| cfg.spec = self.evm_version.to_seismic_spec_id())
.build_seismic_evm_with_inspector(
TracerEip3155::new_stdout().without_summary(),
);
let mut evm = Context::seismic_with_rng_key(
SchnorrkelKeypair::from_bytes(&[0; 96]).expect("safe"),
)
.with_db(self.db.clone())
.modify_tx_chained(|tx| {
tx.base.caller = self.config.caller;
tx.base.kind = TxKind::Create;
tx.base.data = deploy_data.clone();
tx.base.value = value;
tx.base.nonce = nonce;
})
.modify_cfg_chained(|cfg| cfg.spec = self.evm_version.to_seismic_spec_id())
.build_seismic_evm_with_inspector(TracerEip3155::new_stdout().without_summary());
evm.inspect_tx(evm.tx.clone()).map_err(|err| {
Errors::EVMError(format!("DEPLOY transaction error: {:?}", err.to_string()))
})?
} else {
let mut evm = Context::seismic()
.with_db(self.db.clone())
.modify_tx_chained(|tx| {
tx.base.caller = self.config.caller;
tx.base.kind = TxKind::Create;
tx.base.data = deploy_data.clone();
tx.base.value = value;
tx.base.nonce = nonce;
})
.modify_cfg_chained(|cfg| cfg.spec = self.evm_version.to_seismic_spec_id())
.build_seismic_evm();
let mut evm = Context::seismic_with_rng_key(
SchnorrkelKeypair::from_bytes(&[0; 96]).expect("safe"),
)
.with_db(self.db.clone())
.modify_tx_chained(|tx| {
tx.base.caller = self.config.caller;
tx.base.kind = TxKind::Create;
tx.base.data = deploy_data.clone();
tx.base.value = value;
tx.base.nonce = nonce;
})
.modify_cfg_chained(|cfg| cfg.spec = self.evm_version.to_seismic_spec_id())
.build_seismic_evm();
evm.replay().map_err(|err| {
Errors::EVMError(format!("DEPLOY transaction error: {:?}", err.to_string()))
})?
Expand Down Expand Up @@ -243,34 +247,34 @@ impl EvmExecutor {
.map_or(0, |account| account.nonce);
let out = if self.evm_version == EVMVersion::Mercury {
if trace {
let mut evm = Context::seismic()
.with_db(self.db.clone())
.modify_tx_chained(|tx| {
tx.base.caller = self.config.caller;
tx.base.kind = TxKind::Call(self.config.env_contract_address);
tx.base.data = input_data.clone();
tx.base.value = value;
if self.evm_version >= EVMVersion::Cancun {
tx.base.blob_hashes = self.config.blob_hashes.clone();
tx.base.max_fee_per_blob_gas = self.config.max_blob_fee;
}
tx.base.gas_limit = self.config.gas_limit;
tx.base.gas_price = self.config.gas_price;
tx.base.gas_priority_fee = self.config.gas_priority_fee;
tx.base.nonce = nonce;
})
.modify_block_chained(|block| {
block.prevrandao = Some(self.config.block_prevrandao);
block.difficulty = self.config.block_difficulty.into();
block.gas_limit = self.config.block_gas_limit;
block.basefee = self.config.block_basefee;
block.number = self.config.block_number;
block.timestamp = self.config.timestamp;
})
.modify_cfg_chained(|cfg| cfg.spec = self.evm_version.to_seismic_spec_id())
.build_seismic_evm_with_inspector(TracerEip3155::new(Box::new(
std::io::stdout(),
)));
let mut evm = Context::seismic_with_rng_key(
SchnorrkelKeypair::from_bytes(&[0; 96]).expect("safe"),
)
.with_db(self.db.clone())
.modify_tx_chained(|tx| {
tx.base.caller = self.config.caller;
tx.base.kind = TxKind::Call(self.config.env_contract_address);
tx.base.data = input_data.clone();
tx.base.value = value;
if self.evm_version >= EVMVersion::Cancun {
tx.base.blob_hashes = self.config.blob_hashes.clone();
tx.base.max_fee_per_blob_gas = self.config.max_blob_fee;
}
tx.base.gas_limit = self.config.gas_limit;
tx.base.gas_price = self.config.gas_price;
tx.base.gas_priority_fee = self.config.gas_priority_fee;
tx.base.nonce = nonce;
})
.modify_block_chained(|block| {
block.prevrandao = Some(self.config.block_prevrandao);
block.difficulty = self.config.block_difficulty.into();
block.gas_limit = self.config.block_gas_limit;
block.basefee = self.config.block_basefee;
block.number = self.config.block_number;
block.timestamp = self.config.timestamp;
})
.modify_cfg_chained(|cfg| cfg.spec = self.evm_version.to_seismic_spec_id())
.build_seismic_evm_with_inspector(TracerEip3155::new(Box::new(std::io::stdout())));
evm.inspect_tx(evm.tx.clone()).map_err(|err| {
Errors::EVMError(format!(
"EVM transaction error: {:?}, for the file: {:?}",
Expand All @@ -279,32 +283,34 @@ impl EvmExecutor {
))
})?
} else {
let mut evm = Context::seismic()
.with_db(self.db.clone())
.modify_tx_chained(|tx| {
tx.base.caller = self.config.caller;
tx.base.kind = TxKind::Call(self.config.env_contract_address);
tx.base.data = input_data.clone();
tx.base.value = value;
if self.evm_version >= EVMVersion::Cancun {
tx.base.blob_hashes = self.config.blob_hashes.clone();
tx.base.max_fee_per_blob_gas = self.config.max_blob_fee;
}
tx.base.gas_limit = self.config.gas_limit;
tx.base.gas_price = self.config.gas_price;
tx.base.nonce = nonce;
tx.base.gas_priority_fee = self.config.gas_priority_fee;
})
.modify_block_chained(|block| {
block.prevrandao = Some(self.config.block_prevrandao);
block.difficulty = self.config.block_difficulty.into();
block.gas_limit = self.config.block_gas_limit;
block.basefee = self.config.block_basefee;
block.number = self.config.block_number;
block.timestamp = self.config.timestamp;
})
.modify_cfg_chained(|cfg| cfg.spec = self.evm_version.to_seismic_spec_id())
.build_seismic_evm();
let mut evm = Context::seismic_with_rng_key(
SchnorrkelKeypair::from_bytes(&[0; 96]).expect("safe"),
)
.with_db(self.db.clone())
.modify_tx_chained(|tx| {
tx.base.caller = self.config.caller;
tx.base.kind = TxKind::Call(self.config.env_contract_address);
tx.base.data = input_data.clone();
tx.base.value = value;
if self.evm_version >= EVMVersion::Cancun {
tx.base.blob_hashes = self.config.blob_hashes.clone();
tx.base.max_fee_per_blob_gas = self.config.max_blob_fee;
}
tx.base.gas_limit = self.config.gas_limit;
tx.base.gas_price = self.config.gas_price;
tx.base.nonce = nonce;
tx.base.gas_priority_fee = self.config.gas_priority_fee;
})
.modify_block_chained(|block| {
block.prevrandao = Some(self.config.block_prevrandao);
block.difficulty = self.config.block_difficulty.into();
block.gas_limit = self.config.block_gas_limit;
block.basefee = self.config.block_basefee;
block.number = self.config.block_number;
block.timestamp = self.config.timestamp;
})
.modify_cfg_chained(|cfg| cfg.spec = self.evm_version.to_seismic_spec_id())
.build_seismic_evm();
evm.replay().map_err(|err| {
Errors::EVMError(format!(
"EVM transaction error: {:?}, for the file: {:?}",
Expand Down
20 changes: 11 additions & 9 deletions bins/revme/src/cmd/statetest/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ use revm::{
Context, ExecuteCommitEvm,
};
use seismic_revm::{
DefaultSeismicContext, SeismicBuilder, SeismicHaltReason, SeismicHaltReason as HaltReason,
SeismicSpecId as SpecId, SeismicTransaction,
precompiles::rng::domain_sep_rng::SchnorrkelKeypair, DefaultSeismicContext, SeismicBuilder,
SeismicHaltReason, SeismicHaltReason as HaltReason, SeismicSpecId as SpecId,
SeismicTransaction,
};
use serde_json::json;
use statetest_types::{SpecName, Test, TestSuite, TestUnit};
Expand Down Expand Up @@ -426,7 +427,7 @@ fn execute_single_test(ctx: TestExecutionContext) -> Result<(), TestErrorKind> {
.with_bundle_update()
.build();

let evm_context = Context::seismic()
let evm_context = Context::seismic_with_random_rng_key()
.with_block(ctx.block)
.with_tx(ctx.tx)
.with_cfg(ctx.cfg)
Expand Down Expand Up @@ -476,12 +477,13 @@ fn debug_failed_test(ctx: DebugContext) {
.with_bundle_update()
.build();

let mut evm = Context::seismic()
.with_db(&mut state)
.with_block(ctx.block)
.with_tx(ctx.tx)
.with_cfg(ctx.cfg)
.build_seismic_evm_with_inspector(TracerEip3155::buffered(stderr()).without_summary());
let mut evm =
Context::seismic_with_rng_key(SchnorrkelKeypair::from_bytes(&[0; 96]).expect("safe"))
.with_db(&mut state)
.with_block(ctx.block)
.with_tx(ctx.tx)
.with_cfg(ctx.cfg)
.build_seismic_evm_with_inspector(TracerEip3155::buffered(stderr()).without_summary());

let exec_result = evm.inspect_tx_commit(ctx.tx);

Expand Down
12 changes: 12 additions & 0 deletions crates/context/interface/src/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,18 @@ impl<T> FrameStack<T> {
*index += 1;
}

/// Returns a slice of all active (initialized) frames on the stack.
///
/// Frames `0..=index` are always initialized, as the stack only grows
/// via `end_init`/`push` which set the index after initialization.
#[inline]
pub fn active_frames(&self) -> &[T] {
match self.index {
Some(idx) => &self.stack[..=idx],
None => &[],
}
}

/// Clears the stack by setting the index to 0.
/// It does not destroy the stack.
#[inline]
Expand Down
2 changes: 0 additions & 2 deletions crates/seismic/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ serde = { workspace = true, features = ["derive", "rc"], optional = true }

# seismic
schnorrkel = { version = "0.11.2", default-features = false }
merlin = { version = "3.0.0", default-features = false }
rand_core = { version = "0.6.4", default-features = false }
hkdf = { version = "0.12", default-features = false }
seismic-enclave = { workspace = true}
sha2 = { workspace = true }
Expand Down
12 changes: 6 additions & 6 deletions crates/seismic/src/api/default_ctx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,25 @@ pub type SeismicContext<DB> = Context<

/// Trait that allows for a default context to be created.
pub trait DefaultSeismicContext {
/// Create a default context.
fn seismic() -> SeismicContext<EmptyDB>;
/// Create a context that uses a random rng key for precompile everytime.
fn seismic_with_random_rng_key() -> SeismicContext<EmptyDB>;
/// Create a context with a specific RNG keypair.
fn seismic_with_rng_key(rng_keypair: schnorrkel::Keypair) -> SeismicContext<EmptyDB>;
}

impl DefaultSeismicContext for SeismicContext<EmptyDB> {
fn seismic() -> Self {
fn seismic_with_random_rng_key() -> Self {
Context::mainnet()
.with_tx(SeismicTransaction::default())
.with_cfg(CfgEnv::new_with_spec(SeismicSpecId::MERCURY))
.with_chain(SeismicChain::default())
.with_chain(SeismicChain::with_random_rng_key())
}

fn seismic_with_rng_key(rng_keypair: schnorrkel::Keypair) -> Self {
Context::mainnet()
.with_tx(SeismicTransaction::default())
.with_cfg(CfgEnv::new_with_spec(SeismicSpecId::MERCURY))
.with_chain(SeismicChain::with_live_rng_key(Some(rng_keypair)))
.with_chain(SeismicChain::with_live_rng_key(rng_keypair))
}
}

Expand All @@ -47,7 +47,7 @@ mod test {

#[test]
fn default_run_seismic() {
let ctx = Context::seismic();
let ctx = Context::seismic_with_random_rng_key();
// convert to seismic context
let mut evm = ctx.build_seismic_evm_with_inspector(NoOpInspector {});
// execute
Expand Down
Loading