Skip to content

chore(l2): remove save state module #3119

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

Open
wants to merge 22 commits into
base: l2/remove_execute_cache
Choose a base branch
from
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
4 changes: 4 additions & 0 deletions Cargo.lock

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

21 changes: 2 additions & 19 deletions crates/l2/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.PHONY: help init down clean restart cli init-local-l1 init-l1 down-local-l1 \
restart-local-l1 rm-db-l1 clean-contract-deps restart-contract-deps deploy-l1 init-l2 \
init-l2-no-metrics down-l2 restart-l2 init-prover rm-db-l2 purge_prover_state ci_test test \
init-l2-no-metrics down-l2 restart-l2 init-prover rm-db-l2 ci_test test \
init-testnet deploy-l1-testnet restart-testnet

.DEFAULT_GOAL := help
Expand All @@ -22,7 +22,7 @@ down: down-local-l1 down-l2 down-metrics## 🛑 Shuts down the localnet
clean: clean-contract-deps ## 🧹 Cleans the localnet
rm -rf out/

restart: restart-local-l1 deploy-l1 purge_prover_state restart-l2 ## 🔄 Restarts the localnet
restart: restart-local-l1 deploy-l1 restart-l2 ## 🔄 Restarts the localnet

## Same as restart but for testnet deployment. The local database is cleaned and the contracts are deployed again.
restart-testnet:
Expand Down Expand Up @@ -241,20 +241,3 @@ state-diff-test:
docker compose -f docker-compose-l2.yaml -f docker-compose-l2-store.overrides.yaml up --detach

cargo test state_reconstruct --release

# Purge L2's state
UNAME_S:=$(shell uname -s)
# This directory is set by crates/l2/utils/prover/save_state.rs -> const DEFAULT_DATADIR
PROJECT_NAME:=ethrex_l2_state

ifeq ($(UNAME_S),Linux)
PROJECT_PATH := $(HOME)/.local/share/${PROJECT_NAME}
else ifeq ($(UNAME_S),Darwin)
PROJECT_PATH := $(HOME)/Library/Application\ Support/${PROJECT_NAME}
else
$(error Unsupported platform: $(UNAME_S))
endif

purge_prover_state: ## 🧹 Removes the L2 state, only use to start fresh.
rm -rf $(PROJECT_PATH); \
echo "Directory deleted."
26 changes: 26 additions & 0 deletions crates/l2/common/src/calldata.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
use ethrex_common::{Address, Bytes, U256};
use serde::{Deserialize, Serialize};

/// Struct representing the possible solidity types for function arguments
/// - `Uint` -> `uint256`
/// - `Address` -> `address`
/// - `Bool` -> `bool`
/// - `Bytes` -> `bytes`
/// - `String` -> `string`
/// - `Array` -> `T[]`
/// - `Tuple` -> `(X_1, ..., X_k)`
/// - `FixedArray` -> `T[k]`
/// - `FixedBytes` -> `bytesN`
#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)]
pub enum Value {
Address(Address),
Uint(U256),
Int(U256),
Bool(bool),
Bytes(Bytes),
String(String),
Array(Vec<Value>),
Tuple(Vec<Value>),
FixedArray(Vec<Value>),
FixedBytes(Bytes),
}
2 changes: 2 additions & 0 deletions crates/l2/common/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
pub mod calldata;
pub mod deposits;
pub mod prover;
pub mod state_diff;
pub mod withdrawals;
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use ethrex_common::H256;
use ethrex_l2_sdk::calldata::Value;
use serde::{Deserialize, Serialize};
use std::fmt::{Debug, Display};

use crate::calldata::Value;

/// Enum used to identify the different proving systems.
#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, Serialize, Deserialize)]
pub enum ProverType {
Expand All @@ -13,6 +14,18 @@ pub enum ProverType {
TDX,
}

impl From<ProverType> for u32 {
fn from(value: ProverType) -> u32 {
match value {
ProverType::Exec => 0,
ProverType::RISC0 => 1,
ProverType::SP1 => 2,
ProverType::Aligned => 4,
ProverType::TDX => 5,
}
}
}

impl ProverType {
/// Used to iterate through all the possible proving systems
pub fn all() -> impl Iterator<Item = ProverType> {
Expand Down
1 change: 1 addition & 0 deletions crates/l2/contracts/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ eyre.workspace = true
ethrex-l2 = { path = "../../l2" }
ethrex-sdk = { path = "../../l2/sdk" }
ethrex-common = { path = "../../common" }
ethrex-l2-common = { path = "../common" }
ethrex-rpc = { path = "../../networking/rpc" }
genesis-tool = { path = "../../../tooling/genesis" }

Expand Down
6 changes: 3 additions & 3 deletions crates/l2/contracts/bin/deployer/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ use cli::{DeployerOptions, parse_private_key};
use error::DeployerError;
use ethrex_common::{Address, U256};
use ethrex_l2::utils::test_data_io::read_genesis_file;
use ethrex_l2_common::calldata::Value;
use ethrex_l2_sdk::{
calldata::{Value, encode_calldata},
compile_contract, deploy_contract, deploy_with_proxy, get_address_from_secret_key,
initialize_contract,
calldata::encode_calldata, compile_contract, deploy_contract, deploy_with_proxy,
get_address_from_secret_key, initialize_contract,
};
use ethrex_rpc::{
EthClient,
Expand Down
3 changes: 1 addition & 2 deletions crates/l2/prover/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ ethrex-blockchain.workspace = true

# l2
ethrex-l2 = { path = "../", default-features = false }
ethrex-l2-common = {workspace = true, optional = true }
ethrex-l2-common = { workspace = true }
ethrex-sdk.workspace = true

zkvm_interface = { path = "./zkvm/interface", default-features = false }
Expand Down Expand Up @@ -63,7 +63,6 @@ sp1 = ["zkvm_interface/sp1", "dep:sp1-sdk"]

gpu = ["risc0-zkvm?/cuda", "sp1-sdk?/cuda"]
l2 = [
"dep:ethrex-l2-common",
"ethrex-vm/l2",
"zkvm_interface/l2",
"ethrex-blockchain/l2",
Expand Down
7 changes: 5 additions & 2 deletions crates/l2/prover/src/backends/exec.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
use ethrex_l2::utils::prover::proving_systems::{BatchProof, ProofCalldata, ProverType};
use ethrex_l2_sdk::calldata::Value;
use tracing::warn;

use zkvm_interface::io::{ProgramInput, ProgramOutput};

use ethrex_l2_common::{
calldata::Value,
prover::{BatchProof, ProofCalldata, ProverType},
};

pub struct ProveOutput(pub ProgramOutput);

pub fn execute(input: ProgramInput) -> Result<(), Box<dyn std::error::Error>> {
Expand Down
9 changes: 5 additions & 4 deletions crates/l2/prover/src/backends/sp1.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
use ethrex_l2::utils::prover::proving_systems::{
BatchProof, ProofBytes, ProofCalldata, ProverType,
};
use ethrex_l2_sdk::calldata::Value;
use sp1_sdk::{
EnvProver, HashableKey, ProverClient, SP1ProofWithPublicValues, SP1ProvingKey, SP1Stdin,
SP1VerifyingKey,
Expand All @@ -10,6 +6,11 @@ use std::{fmt::Debug, sync::LazyLock};
use tracing::info;
use zkvm_interface::io::ProgramInput;

use ethrex_l2_common::{
calldata::Value,
prover::{BatchProof, ProofBytes, ProofCalldata, ProverType},
};

static PROGRAM_ELF: &[u8] =
include_bytes!("../../zkvm/interface/sp1/out/riscv32im-succinct-zkvm-elf");

Expand Down
5 changes: 2 additions & 3 deletions crates/l2/prover/src/prover.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use crate::{config::ProverConfig, prove, to_batch_proof};
use ethrex_l2::{
sequencer::proof_coordinator::ProofData, utils::prover::proving_systems::BatchProof,
};
use ethrex_l2::sequencer::proof_coordinator::ProofData;
use ethrex_l2_common::prover::BatchProof;
use std::time::Duration;
use tokio::{
io::{AsyncReadExt, AsyncWriteExt},
Expand Down
1 change: 1 addition & 0 deletions crates/l2/prover/zkvm/interface/sp1/Cargo.lock

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

1 change: 0 additions & 1 deletion crates/l2/prover/zkvm/interface/src/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ use ethrex_common::types::{
BlobsBundleError, Commitment, PrivilegedL2Transaction, Proof, Receipt, Transaction,
blob_from_bytes, kzg_commitment_to_versioned_hash,
};
#[cfg(feature = "l2")]
use ethrex_l2_common::{
deposits::{DepositError, compute_deposit_logs_hash, get_block_deposits},
state_diff::{StateDiff, StateDiffError, prepare_state_diff},
Expand Down
1 change: 1 addition & 0 deletions crates/l2/sdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ edition.workspace = true
[dependencies]
ethrex-common.workspace = true
ethrex-rpc.workspace = true
ethrex-l2-common.workspace = true

ethereum-types.workspace = true
tokio.workspace = true
Expand Down
26 changes: 1 addition & 25 deletions crates/l2/sdk/src/calldata.rs
Original file line number Diff line number Diff line change
@@ -1,32 +1,8 @@
use ethrex_common::Bytes;
use ethrex_common::{Address, H32, U256};
use ethrex_l2_common::calldata::Value;
use ethrex_rpc::clients::eth::errors::CalldataEncodeError;
use keccak_hash::keccak;
use serde::{Deserialize, Serialize};

/// Struct representing the possible solidity types for function arguments
/// - `Uint` -> `uint256`
/// - `Address` -> `address`
/// - `Bool` -> `bool`
/// - `Bytes` -> `bytes`
/// - `String` -> `string`
/// - `Array` -> `T[]`
/// - `Tuple` -> `(X_1, ..., X_k)`
/// - `FixedArray` -> `T[k]`
/// - `FixedBytes` -> `bytesN`
#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)]
pub enum Value {
Address(Address),
Uint(U256),
Int(U256),
Bool(bool),
Bytes(Bytes),
String(String),
Array(Vec<Value>),
Tuple(Vec<Value>),
FixedArray(Vec<Value>),
FixedBytes(Bytes),
}

fn parse_signature(signature: &str) -> Result<(String, Vec<String>), CalldataEncodeError> {
let sig = signature.trim().trim_start_matches("function ");
Expand Down
3 changes: 2 additions & 1 deletion crates/l2/sdk/src/l1_to_l2_tx_data.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::calldata::{self, Value};
use crate::calldata::{self};
use bytes::Bytes;
use ethrex_common::{Address, U256};
use ethrex_l2_common::calldata::Value;
use ethrex_rpc::{
EthClient,
clients::{EthClientError, Overrides, eth::errors::CalldataEncodeError},
Expand Down
3 changes: 2 additions & 1 deletion crates/l2/sdk/src/sdk.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use std::{fs::read_to_string, path::Path, process::Command};

use bytes::Bytes;
use calldata::{Value, encode_calldata};
use calldata::encode_calldata;
use ethereum_types::{Address, H160, H256, U256};
use ethrex_common::types::GenericTransaction;
use ethrex_l2_common::calldata::Value;
use ethrex_rpc::clients::eth::WithdrawalProof;
use ethrex_rpc::clients::eth::{
EthClient, WrappedTransaction, errors::EthClientError, eth_sender::Overrides,
Expand Down
11 changes: 3 additions & 8 deletions crates/l2/sequencer/errors.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use crate::utils::error::UtilsError;
use crate::utils::prover::errors::SaveStateError;
use crate::utils::prover::proving_systems::ProverType;
use ethereum_types::FromStrRadixErr;
use ethrex_blockchain::error::{ChainError, InvalidForkChoice};
use ethrex_common::types::{BlobsBundleError, FakeExponentialError};
use ethrex_l2_common::deposits::DepositError;
use ethrex_l2_common::prover::ProverType;
use ethrex_l2_common::state_diff::StateDiffError;
use ethrex_l2_common::withdrawals::WithdrawalError;
use ethrex_l2_sdk::merkle_tree::MerkleError;
Expand Down Expand Up @@ -81,8 +80,6 @@ pub enum ProverServerError {
WriteError(String),
#[error("ProverServer failed to get data from Store: {0}")]
ItemNotFoundInStore(String),
#[error("ProverServer encountered a SaveStateError: {0}")]
SaveStateError(#[from] SaveStateError),
#[error("Failed to encode calldata: {0}")]
CalldataEncodeError(#[from] CalldataEncodeError),
#[error("Unexpected Error: {0}")]
Expand All @@ -109,8 +106,6 @@ pub enum ProofSenderError {
EthClientError(#[from] EthClientError),
#[error("Failed to encode calldata: {0}")]
CalldataEncodeError(#[from] CalldataEncodeError),
#[error("Failed with a SaveStateError: {0}")]
SaveStateError(#[from] SaveStateError),
#[error("{0} proof is not present")]
ProofNotPresent(ProverType),
#[error("Unexpected Error: {0}")]
Expand Down Expand Up @@ -140,9 +135,9 @@ pub enum ProofVerifierError {
#[error("ProofVerifier decoding error: {0}")]
DecodingError(String),
#[error("Failed with a SaveStateError: {0}")]
SaveStateError(#[from] SaveStateError),
#[error("Failed to encode calldata: {0}")]
CalldataEncodeError(#[from] CalldataEncodeError),
#[error("Store error: {0}")]
StoreError(#[from] StoreError),
}

#[derive(Debug, thiserror::Error)]
Expand Down
3 changes: 2 additions & 1 deletion crates/l2/sequencer/l1_committer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ use ethrex_common::{
},
};
use ethrex_l2_common::{
calldata::Value,
deposits::{compute_deposit_logs_hash, get_block_deposits},
state_diff::{StateDiff, prepare_state_diff},
withdrawals::{compute_withdrawals_merkle_root, get_block_withdrawals},
};
use ethrex_l2_sdk::calldata::{Value, encode_calldata};
use ethrex_l2_sdk::calldata::encode_calldata;
use ethrex_metrics::metrics;
#[cfg(feature = "metrics")]
use ethrex_metrics::metrics_l2::{METRICS_L2, MetricsL2BlockType};
Expand Down
Loading
Loading