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

feat(l2): prove deposits #2209

Draft
wants to merge 204 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
204 commits
Select commit Hold shift + click to select a range
94fb3e3
add indexdb
xqft Jan 14, 2025
2847cf8
rename InnerIndexDB to AuxIndexDB
xqft Jan 14, 2025
89ba179
add IndexDBError
xqft Jan 15, 2025
f5192c4
change Revm EVM error to ours
xqft Jan 15, 2025
9616b7d
replace from_exec impl with indexdb
xqft Jan 15, 2025
9d97192
Merge branch 'main' into l2/touched_state
xqft Jan 15, 2025
253ab7f
WIP add PreExecDB
xqft Jan 17, 2025
966706e
WIP add proofs in from_store()
xqft Jan 17, 2025
2135a08
WIP remove internal mutability
xqft Jan 17, 2025
eabd6a3
refactor
xqft Jan 17, 2025
9ffbc44
replace PreExecDB with CacheDB
xqft Jan 17, 2025
a308649
nits
xqft Jan 20, 2025
b0d214f
fix filter
xqft Jan 20, 2025
1b64809
add nonce and balance validations during pre-exec
xqft Jan 20, 2025
dd75353
put proofs inside executiondb
xqft Jan 20, 2025
389ddab
fix errors
xqft Jan 20, 2025
fec82ef
remove optiona_balance_check feature
xqft Jan 20, 2025
0405835
remove unused errors
xqft Jan 20, 2025
987e359
fix filter
xqft Jan 20, 2025
4a0a715
add db verification
xqft Jan 20, 2025
eb98e53
remove unused imports
xqft Jan 20, 2025
892060a
update sp1 prover
xqft Jan 20, 2025
d9aee43
Merge branch 'main' into l2/touched_state
xqft Jan 20, 2025
6f2169c
remove revm types
xqft Jan 21, 2025
d0669bf
add bench crate
xqft Jan 13, 2025
321d260
make a blocking rpc client
xqft Jan 21, 2025
76c5cff
create ToExecDB trait
xqft Jan 22, 2025
fdf6d9f
remove unnecessary store_wrapper
xqft Jan 22, 2025
297b7f4
WIP optimizing rpc db
xqft Jan 23, 2025
6a7c60c
cache storage
xqft Jan 23, 2025
c18e753
add timeout and retry
xqft Jan 23, 2025
e5f9876
update cargo lock
xqft Jan 23, 2025
b8c953e
remove blocking rpc
xqft Jan 24, 2025
f84063e
refactor rpc
xqft Jan 24, 2025
664804d
add storageAt request
xqft Jan 24, 2025
de11b0a
fix access list
xqft Jan 24, 2025
90d71a4
fetch latest block number
xqft Jan 24, 2025
99938c0
reqwest optimizations
xqft Jan 24, 2025
c7c6100
convert to exec db
xqft Jan 27, 2025
e918786
refactor retry logic
xqft Jan 27, 2025
ca13ac0
remove max retries
xqft Jan 27, 2025
d75f543
write db to file
xqft Jan 27, 2025
0ca8b8b
remove unnecesary nodes
xqft Jan 27, 2025
9133af8
add bincode
xqft Jan 27, 2025
e29975c
use rpc cache approach
xqft Jan 27, 2025
e99df38
remove use
xqft Jan 27, 2025
6e4e9ff
rewrite verify_db fn'
xqft Jan 28, 2025
119304e
cache block hashes
xqft Jan 28, 2025
d1d4aee
handle null storage values
xqft Jan 28, 2025
c4c2bc0
handle non-existing accounts
xqft Jan 29, 2025
0c35fcd
fix skipping an accounts proof
xqft Jan 29, 2025
3135fb7
Merge branch 'main' into l2/rpc_bench
xqft Jan 29, 2025
c5feb83
remove diff
xqft Jan 29, 2025
21e1d31
take into account non existing accounts
xqft Jan 30, 2025
86956e9
add potential child nodes, clean up
xqft Feb 4, 2025
753d2a2
add execute function to prover
xqft Feb 5, 2025
ef3a507
fix refcell borrow panics
xqft Feb 5, 2025
116a24f
process withdrawals with executiondb
xqft Feb 6, 2025
29abe57
fix beacon root call
xqft Feb 7, 2025
0a5979a
remove unused parameter
xqft Feb 7, 2025
b55abdd
add prove cli arg
xqft Feb 7, 2025
fda180f
better print in fetch
xqft Feb 7, 2025
97caa91
deactivate l2 feature in sp1
xqft Feb 7, 2025
cb38e96
refactor update tries
xqft Feb 7, 2025
2d577af
add missing imports
xqft Feb 7, 2025
8cd7710
add comments
xqft Feb 7, 2025
191cd87
remove unused dep
xqft Feb 7, 2025
ec38aeb
add cache
xqft Feb 7, 2025
e0a8074
update risc0 program
xqft Feb 7, 2025
7f64f16
Merge branch 'main' into l2/rpc_bench
xqft Feb 7, 2025
9025469
comment out gas
xqft Feb 7, 2025
a424818
fmt
xqft Feb 10, 2025
32da4e9
some clippy
xqft Feb 10, 2025
c078ba7
add timing
xqft Feb 10, 2025
2446201
update sp1
xqft Feb 10, 2025
21e2022
add makefile
xqft Feb 10, 2025
fae29b3
add env vars
xqft Feb 10, 2025
0718fe1
downgrade sp1
xqft Feb 10, 2025
b5c239e
add prove rules
xqft Feb 10, 2025
d639371
disable default features for core and vm
xqft Feb 10, 2025
79b3b7a
remove c-kzg dep from zkvm programs
xqft Feb 10, 2025
95fac58
fix imports
xqft Feb 10, 2025
e9173dc
fix elapsed time disp
xqft Feb 10, 2025
e560183
bump risc0
xqft Feb 10, 2025
febe737
add support for risc0
xqft Feb 10, 2025
075ac72
add block num env var
xqft Feb 10, 2025
77f88dc
remove exclusive compile err
xqft Feb 10, 2025
bc41c07
fix prev commit
xqft Feb 10, 2025
ec24436
fix cache deser
xqft Feb 10, 2025
7574ddd
Revert "fix cache deser"
xqft Feb 10, 2025
0838863
comment out requests_hash conditional serde
xqft Feb 10, 2025
0a4314f
bump sp1 version
xqft Feb 10, 2025
a86e66b
serialize into json
xqft Feb 11, 2025
58a741b
change file extension
xqft Feb 11, 2025
4c10ab7
create file
xqft Feb 11, 2025
71913fa
better final print
xqft Feb 11, 2025
8cc38b9
Merge branch 'main' into l2/rpc_bench
xqft Feb 11, 2025
603306f
Merge remote-tracking branch 'origin/main' into l2/rpc_bench
Oppen Feb 12, 2025
005f619
fix build (fails perf-sp1 and perf-risc0 tests)
Oppen Feb 12, 2025
9ae47e1
fix test build
Oppen Feb 12, 2025
e576b2b
fix beacon root call executing on perf_zkvm tests
xqft Feb 12, 2025
bf0779c
fix prover mode name
Oppen Feb 14, 2025
c6e86ab
WIP add pico prover
xqft Feb 11, 2025
816c6af
patch secp256k1
xqft Feb 12, 2025
4db7737
finish adding pico prover backend
xqft Feb 12, 2025
8144ced
fix building pico elf
xqft Feb 13, 2025
a99bb95
add pico target to bench crate
xqft Feb 13, 2025
fbf0915
fix pico elf in backedn
xqft Feb 13, 2025
b1434f6
TEMP conditional risc0 code
xqft Feb 13, 2025
5107a65
write input to pico prover
xqft Feb 14, 2025
f5ecbc6
WIP refactor proving backends
xqft Feb 17, 2025
7411407
finish sp1 backend refactor
xqft Feb 18, 2025
930719c
finish risc0 backend refactor
xqft Feb 18, 2025
54a46b0
make risc0 backend fns public
xqft Feb 18, 2025
afbcea9
proof calldata
xqft Feb 21, 2025
922d341
integrate backends
xqft Feb 24, 2025
05a7c59
remobe build_* features
xqft Feb 24, 2025
ed0143b
finish pico backend impl
xqft Feb 25, 2025
148f708
add perf_pico test
xqft Feb 25, 2025
c60da19
Merge branch 'main' into l2/pico
xqft Feb 25, 2025
85ea8c6
fix some merge artifacts
xqft Feb 25, 2025
e8165d3
fix interface build.rs
xqft Feb 25, 2025
a02beef
fix commands/prove
xqft Feb 25, 2025
43e7eab
update featue on ci job
xqft Feb 25, 2025
eed9b79
add pico verifier contract interface
xqft Feb 26, 2025
a12e173
add l2 prover nightly workflow
xqft Feb 26, 2025
2eee520
Remove l2/metrics from cmd/ethrex/Cargo.toml
jrchatruc Feb 26, 2025
27bc7e6
fix workflow
xqft Feb 26, 2025
49e8fb4
specify toolchain
xqft Feb 26, 2025
e1cab97
Merge branch 'main' into l2/pico
xqft Feb 26, 2025
0f8e489
add clippy component
xqft Feb 26, 2025
56c2563
fix merge errors and warnings
xqft Feb 26, 2025
d5952a8
remove zkvm deps from l2
xqft Feb 26, 2025
89254fb
remove unnecesary features from ethrex-l2
xqft Feb 26, 2025
3e98eda
fix cmdg
xqft Feb 26, 2025
f551434
update onchainproposer interface
xqft Feb 26, 2025
5a70026
update deployer.rs to deploy pico verifier
xqft Feb 26, 2025
ca5404a
fix clippy
xqft Feb 26, 2025
5d7e609
fix ci
xqft Feb 26, 2025
50ceccc
alternative way of installing pico-cli
xqft Feb 26, 2025
3c4d0ed
fix doc in contract interface
xqft Feb 26, 2025
3bdff50
fmt
xqft Feb 26, 2025
a7a04ed
compile pico contract
xqft Feb 26, 2025
751edcf
compile with --via-ir
xqft Feb 26, 2025
8bb3eb0
branch evm
xqft Feb 26, 2025
7e5b0c8
update env example
xqft Feb 27, 2025
0bf1e99
Merge branch 'main' into l2/pico
xqft Feb 27, 2025
3cdd476
install pico-cli in lint job
xqft Feb 27, 2025
741cf74
fix integration test
xqft Feb 27, 2025
81444e8
Merge branch 'main' into l2/pico
xqft Feb 27, 2025
de3f6a4
pin alloy-rpc-types-engine version
xqft Feb 27, 2025
2c36c7c
Merge branch 'main' into l2/pico
xqft Mar 4, 2025
6f3a441
Merge branch 'main' into l2/pico
xqft Mar 4, 2025
64b3311
remove alloy-rpc-types-engines
xqft Mar 6, 2025
7324ea5
Merge branch 'main' into l2/pico
xqft Mar 6, 2025
2483df5
fix pico program
xqft Mar 6, 2025
2d7dfab
remove alloy dep
xqft Mar 6, 2025
cfbdbdf
update test nightly job
xqft Mar 7, 2025
ebb93aa
add pico varaibles to env
xqft Mar 7, 2025
c02a499
Merge branch 'main' into l2/pico
xqft Mar 7, 2025
634d0e8
fix import
xqft Mar 7, 2025
b468485
fix toolchain test pico:
xqft Mar 7, 2025
1fdf050
Merge branch 'main' into l2/pico
xqft Mar 10, 2025
437e022
fix dep
xqft Mar 10, 2025
87ab7a0
remove fast proof from pico execution()
xqft Mar 10, 2025
9778048
fix warnings
xqft Mar 10, 2025
f28a4c7
Merge branch 'main' into l2/pico
xqft Mar 11, 2025
789a580
Merge branch 'main' into l2/pico
xqft Mar 11, 2025
48ca720
remove get_gas() and add todos
xqft Mar 11, 2025
ff20745
re-add bincode
xqft Mar 11, 2025
aa6909d
Merge branch 'main' into l2/pico
xqft Mar 12, 2025
3c318dd
add pico proof to save state
xqft Mar 12, 2025
9291b6c
remove duplicated feature
xqft Mar 12, 2025
c81a94c
Merge branch 'main' into l2/pico
xqft Mar 13, 2025
9913775
add deposit hash calculation
xqft Mar 12, 2025
65a02a1
add deposits to the rest of backends
xqft Mar 12, 2025
ee05472
Update lib.rs
xqft Mar 12, 2025
83a9e1e
add deposits check on public inputs
xqft Mar 13, 2025
f63f54b
fix docs
xqft Mar 13, 2025
ac9c84b
Merge branch 'main' into l2/pico
xqft Mar 13, 2025
12afe00
fix unkown revert
xqft Mar 13, 2025
3f305a2
Merge branch 'main' into l2/pico
xqft Mar 13, 2025
293ca95
fix
xqft Mar 14, 2025
c46b4e5
Merge branch 'main' into l2/pico
xqft Mar 14, 2025
0582eb7
Merge branch 'l2/fix_prover_l2_mode' into l2/prove_deposits
xqft Mar 14, 2025
d9050d0
replace mock backend with exec
xqft Mar 14, 2025
0cf3f53
update docs
xqft Mar 14, 2025
abf9423
Merge branch 'main' into l2/pico
xqft Mar 14, 2025
08d0242
revert removal of prover config
xqft Mar 14, 2025
8b14c89
Merge branch 'main' into l2/pico
xqft Mar 14, 2025
a8bbee6
fix prover backends conditional
xqft Mar 14, 2025
f64086d
set exec backend as default for ethrex l2 cli
xqft Mar 14, 2025
cc46d00
remove pico as a backend for ethrex_l2 cli prove command
xqft Mar 14, 2025
c0287a6
ethrex l2 cli prove command will use only sp1 backend
xqft Mar 14, 2025
d1b6358
update l2 prover workflow
xqft Mar 14, 2025
882c9c7
fixes
xqft Mar 14, 2025
e5bdc7a
fmt
xqft Mar 14, 2025
5707ffa
fix clippy
xqft Mar 14, 2025
13f68d6
remove prove command
xqft Mar 14, 2025
c84ec64
fmt
xqft Mar 14, 2025
e631e90
add succint toolchain to lint job
xqft Mar 17, 2025
a88acf6
Merge branch 'main' into l2/prove_deposits
xqft Mar 17, 2025
b5875c1
Merge branch 'l2/pico' into l2/prove_deposits
xqft Mar 17, 2025
5ff98b0
Merge branch 'main' into l2/prove_deposits
xqft Mar 18, 2025
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
1,706 changes: 788 additions & 918 deletions Cargo.lock

Large diffs are not rendered by default.

24 changes: 22 additions & 2 deletions crates/l2/contracts/src/l1/OnChainProposer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ contract OnChainProposer is IOnChainProposer, ReentrancyGuard {
//risc0
bytes calldata risc0BlockProof,
bytes32 risc0ImageId,
bytes32 risc0JournalDigest,
bytes calldata risc0Journal,
//sp1
bytes32 sp1ProgramVKey,
bytes calldata sp1PublicValues,
Expand All @@ -219,7 +219,16 @@ contract OnChainProposer is IOnChainProposer, ReentrancyGuard {
"OnChainProposer: block not committed"
);

// TODO: unify public inputs in single parameter

if (PICOVERIFIER != DEV_MODE) {
bytes32 picoDepositsLogHash = bytes32(picoPublicValues[64:96]);
require(
blockCommitments[blockNumber].depositLogs ==
picoDepositsLogHash,
"OnChainProposer: wrong deposits log hash for pico public inputs"
);

// If the verification fails, it will revert.
IPicoVerifier(PICOVERIFIER).verifyPicoProof(
picoRiscvVkey,
Expand All @@ -229,15 +238,26 @@ contract OnChainProposer is IOnChainProposer, ReentrancyGuard {
}

if (R0VERIFIER != DEV_MODE) {
bytes32 risc0DepositsLogHash = bytes32(risc0Journal[64:96]);
require(
blockCommitments[blockNumber].depositLogs ==
risc0DepositsLogHash,
"OnChainProposer: wrong deposits log hash for risc0 public inputs"
);
// If the verification fails, it will revert.
IRiscZeroVerifier(R0VERIFIER).verify(
risc0BlockProof,
risc0ImageId,
risc0JournalDigest
sha256(risc0Journal)
);
}

if (SP1VERIFIER != DEV_MODE) {
bytes32 sp1DepositsLogHash = bytes32(sp1PublicValues[64:96]);
require(
blockCommitments[blockNumber].depositLogs == sp1DepositsLogHash,
"OnChainProposer: wrong deposits log hash for sp1 public inputs"
);
// If the verification fails, it will revert.
ISP1Verifier(SP1VERIFIER).verifyProof(
sp1ProgramVKey,
Expand Down
4 changes: 2 additions & 2 deletions crates/l2/contracts/src/l1/interfaces/IOnChainProposer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ interface IOnChainProposer {
/// ----------------------------------------------------------------------
/// @param risc0BlockProof is the proof of the block to be verified.
/// @param risc0ImageId Digest of the zkVM imageid.
/// @param risc0JournalDigest Digest of the public_inputs aka journal
/// @param risc0Journal public_inputs aka journal
/// ----------------------------------------------------------------------
/// @param sp1ProgramVKey Public verifying key
/// @param sp1PublicValues Values used to perform the execution
Expand All @@ -81,7 +81,7 @@ interface IOnChainProposer {
//risc0
bytes calldata risc0BlockProof,
bytes32 risc0ImageId,
bytes32 risc0JournalDigest,
bytes calldata risc0Journal,
//sp1
bytes32 sp1ProgramVKey,
bytes calldata sp1PublicValues,
Expand Down
6 changes: 3 additions & 3 deletions crates/l2/prover/src/backends/risc0.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub fn verify(receipt: &Receipt) -> Result<(), Box<dyn std::error::Error>> {
pub fn to_calldata(receipt: Receipt) -> Result<ProofCalldata, Box<dyn std::error::Error>> {
let seal = encode_seal(&receipt)?;
let image_id = ZKVM_RISC0_PROGRAM_ID;
let journal_digest = receipt.journal.digest().as_bytes().to_vec();
let journal = receipt.journal.bytes;

// convert image_id into bytes
let image_id = {
Expand All @@ -59,11 +59,11 @@ pub fn to_calldata(receipt: Receipt) -> Result<ProofCalldata, Box<dyn std::error

// bytes calldata seal,
// bytes32 imageId,
// bytes32 journalDigest
// bytes journal
let calldata = vec![
Value::Bytes(seal.into()),
Value::FixedBytes(image_id.into()),
Value::FixedBytes(journal_digest.into()),
Value::Bytes(journal.into()),
];

Ok(ProofCalldata {
Expand Down
4 changes: 4 additions & 0 deletions crates/l2/prover/zkvm/interface/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ ethrex-vm = { path = "../../../../vm", default-features = false }
ethrex-rlp = { path = "../../../../common/rlp", default-features = false }
ethrex-storage = { path = "../../../../storage", default-features = false }
ethrex-trie = { path = "../../../../common/trie", default-features = false }
keccak-hash = "0.11.0"

# Temporarily pin version because 0.11.1 breaks compilation
# alloy-rpc-types-engine = "=0.11.0"

# Temporarily pin version because 0.11.1 breaks compilation
# alloy-rpc-types-engine = "=0.11.0"
Expand Down
2 changes: 1 addition & 1 deletion crates/l2/prover/zkvm/interface/pico/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ edition = "2024"
[dependencies]
pico-sdk = { git = "https://github.com/brevis-network/pico" }
zkvm_interface = { path = "../" }

cfg-if = "1.0.0"
ethrex-common = { path = "../../../../../common", default-features = false }
ethrex-rlp = { path = "../../../../../common/rlp" }
ethrex-vm = { path = "../../../../../vm", default-features = false }
Expand Down
28 changes: 23 additions & 5 deletions crates/l2/prover/zkvm/interface/pico/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use pico_sdk::io::{commit, read_as};

use ethrex_blockchain::{validate_block, validate_gas_used};
use ethrex_vm::backends::revm::{REVM, db::EvmState};
use ethrex_vm::backends::revm::{db::EvmState, REVM};
use zkvm_interface::{
io::{ProgramInput, ProgramOutput},
trie::{update_tries, verify_db},
Expand Down Expand Up @@ -61,8 +61,26 @@ pub fn main() {
panic!("invalid final state trie");
}

commit(&ProgramOutput {
initial_state_hash,
final_state_hash,
});
cfg_if::cfg_if! {
if #[cfg(feature = "l2")] {
let deposits = get_block_deposits(&block);
let deposit_logs_hash = get_deposit_hash(
deposits
.iter()
.filter_map(|tx| tx.get_deposit_hash())
.collect(),
).expect("failed to calculate deposit logs hash");

commit(&ProgramOutput {
initial_state_hash,
final_state_hash,
deposit_logs_hash
});
} else {
commit(&ProgramOutput {
initial_state_hash,
final_state_hash,
});
}
}
}
1 change: 1 addition & 0 deletions crates/l2/prover/zkvm/interface/risc0/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ edition = "2021"
[dependencies]
risc0-zkvm = { version = "1.2.2", default-features = false, features = ["std"] }
zkvm_interface = { path = "../" }
cfg-if = "1.0.0"

ethrex-common = { path = "../../../../../common", default-features = false }
ethrex-rlp = { path = "../../../../../common/rlp" }
Expand Down
31 changes: 26 additions & 5 deletions crates/l2/prover/zkvm/interface/risc0/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
use risc0_zkvm::guest::env;

use ethrex_blockchain::{validate_block, validate_gas_used};
use ethrex_vm::{backends::revm::db::EvmState, backends::revm::REVM};
use ethrex_vm::{backends::revm::REVM, backends::revm::db::EvmState};

use zkvm_interface::{
io::{ProgramInput, ProgramOutput},
trie::{update_tries, verify_db},
};

#[cfg(feature = "l2")]
use zkvm_interface::deposits::{get_block_deposits, get_deposit_hash};

fn main() {
let ProgramInput {
block,
Expand Down Expand Up @@ -58,8 +61,26 @@ fn main() {
panic!("invalid final state trie");
}

env::commit(&ProgramOutput {
initial_state_hash,
final_state_hash,
});
cfg_if::cfg_if! {
if #[cfg(feature = "l2")] {
let deposits = get_block_deposits(&block);
let deposit_logs_hash = get_deposit_hash(
deposits
.iter()
.filter_map(|tx| tx.get_deposit_hash())
.collect(),
).expect("failed to calculate deposit logs hash");

env::commit(&ProgramOutput {
initial_state_hash,
final_state_hash,
deposit_logs_hash
});
} else {
env::commit(&ProgramOutput {
initial_state_hash,
final_state_hash,
});
}
}
}
Loading
Loading