Skip to content

Commit 83beca3

Browse files
authored
Refactor and pull updates from ZKasper development (#19)
* remove ssz-multiproofs and refactor guests to avoid features * bump some crates and remove ssz-multiproof to be a dependency * switch to new iD in contract
1 parent 3b07d6a commit 83beca3

File tree

32 files changed

+788
-1500
lines changed

32 files changed

+788
-1500
lines changed

Cargo.lock

Lines changed: 536 additions & 421 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[workspace]
22
resolver = "2"
3-
members = ["cli", "guests/membership", "guests/balance_and_exits", "crates/ssz-multiproofs", "crates/gindices", "crates/guest-io", "crates/test-utils", "crates/beacon-state"]
3+
members = ["cli", "guests/membership", "guests/balance_and_exits", "crates/gindices", "crates/guest-io", "crates/test-utils", "crates/beacon-state"]
44

55
[workspace.package]
66
version = "0.1.0"
@@ -9,16 +9,15 @@ license = "Apache-2.0"
99

1010
[workspace.dependencies]
1111
gindices.path = "./crates/gindices"
12-
ssz-multiproofs.path = "./crates/ssz-multiproofs"
1312
guest-io.path = "./crates/guest-io"
1413
membership_builder.path = "./guests/membership"
1514
balance_and_exits_builder.path = "./guests/balance_and_exits"
1615
test-utils.path = "./crates/test-utils"
1716
beacon-state.path = "./crates/beacon-state"
1817

1918
alloy = { version = "0.15", features = ["full"] }
20-
alloy-primitives = { version = "1.0", default-features = false, features = ["rlp", "serde", "std"] }
21-
alloy-sol-types = { version = "1.0" }
19+
alloy-primitives = { version = "1.2.1", default-features = false, features = ["rlp", "serde", "std"] }
20+
alloy-sol-types = { version = "1.2.1" }
2221
anyhow = { version = "1.0.75" }
2322
bincode = { version = "1.3" }
2423
bytemuck = { version = "1.14" }
@@ -29,13 +28,14 @@ risc0-build = { version = "2.1", features = ["docker"] }
2928
risc0-build-ethereum = { git = "https://github.com/risc0/risc0-ethereum", tag = "v2.1.0" }
3029
risc0-ethereum-contracts = { git = "https://github.com/risc0/risc0-ethereum", tag = "v2.1.0" }
3130
risc0-steel = { git = "https://github.com/risc0/risc0-ethereum", tag = "v2.1.0", default-features = false }
32-
risc0-zkvm = { version = "2.1" }
33-
risc0-zkp = { version = "2.0.1" }
34-
risc0-zkvm-platform = { version = "2.0.2", default-features = false }
31+
risc0-zkvm = { version = "2.3.1" }
32+
risc0-zkp = { version = "2.0.2" }
33+
risc0-zkvm-platform = { version = "2.0.3", default-features = false }
3534
revm = { version = "23.1", default-features = false, features = ["std"] }
3635

3736
ethereum-consensus = { git = "https://github.com/ralexstokes/ethereum-consensus.git", rev = "ade5ce6c4a19107c1059e5338d8f18855bd2d931", default-features = false, features = ["serde"] }
3837
ssz_rs = { git = "https://github.com/willemolding/ssz-rs", rev = "d939604c3693aadaff63dcacf9a810d8845fafef"}
38+
ssz-multiproofs = { git = "https://github.com/boundless-xyz/Signal-Ethereum", tag = "v1.0.0" }
3939

4040
serde = { version = "1.0", features = ["derive", "std"] }
4141
serde_json = "1.0.133"

cli/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ edition = { workspace = true }
55

66
[features]
77
default = []
8-
sepolia = ["guest-io/sepolia", "membership_builder/sepolia"]
98

109
[dependencies]
1110
ssz-multiproofs.workspace = true

cli/src/main.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,19 @@ use alloy::{
1919
signers::local::PrivateKeySigner,
2020
};
2121
use anyhow::{Context, Result};
22-
use balance_and_exits_builder::{BALANCE_AND_EXITS_ELF, BALANCE_AND_EXITS_ID};
22+
use balance_and_exits_builder::{
23+
MAINNET_ELF as BALANCE_AND_EXITS_ELF, MAINNET_ID as BALANCE_AND_EXITS_ID,
24+
};
2325
use beacon_client::BeaconClient;
2426
use clap::Parser;
2527
use ethereum_consensus::phase0::mainnet::{HistoricalBatch, SLOTS_PER_HISTORICAL_ROOT};
26-
use guest_io::{ETH_SEPOLIA_CHAIN_SPEC, WITHDRAWAL_CREDENTIALS, WITHDRAWAL_VAULT_ADDRESS};
27-
use membership_builder::{VALIDATOR_MEMBERSHIP_ELF, VALIDATOR_MEMBERSHIP_ID};
28+
use guest_io::{
29+
mainnet::{WITHDRAWAL_CREDENTIALS, WITHDRAWAL_VAULT_ADDRESS},
30+
ETH_SEPOLIA_CHAIN_SPEC,
31+
};
32+
use membership_builder::{
33+
MAINNET_ELF as VALIDATOR_MEMBERSHIP_ELF, MAINNET_ID as VALIDATOR_MEMBERSHIP_ID,
34+
};
2835
use risc0_ethereum_contracts::encode_seal;
2936
use risc0_steel::{ethereum::EthEvmEnv, Account};
3037
use risc0_zkvm::{default_prover, ExecutorEnv, ProverOpts, Receipt, VerifierContext};
@@ -283,6 +290,7 @@ async fn build_membership_input<'a>(
283290

284291
tracing::info!("Building input. This may take a few minutes...");
285292
Input::build_continuation(
293+
WITHDRAWAL_CREDENTIALS,
286294
&prior_beacon_state,
287295
prior_max_validator_index,
288296
&beacon_state,
@@ -366,6 +374,7 @@ async fn build_aggregate_input<'a>(
366374
let evm_input = env.into_input().await?;
367375

368376
let input = guest_io::balance_and_exits::Input::build(
377+
WITHDRAWAL_CREDENTIALS,
369378
&beacon_block_header.message,
370379
&beacon_state,
371380
evm_input,

contracts/src/SecondOpinionOracle.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ contract SecondOpinionOracle is ISecondOpinionOracle, IOracleProofReceiver {
4141
uint256 public immutable genesis_block_timestamp;
4242

4343
/// @notice Image ID of the only zkVM guest to accept verification from.
44-
bytes32 public constant imageId = ImageID.BALANCE_AND_EXITS_ID;
44+
bytes32 public constant imageId = ImageID.MAINNET_ID;
4545

4646
/// @notice Seconds per slot
4747
uint256 public constant SECONDS_PER_SLOT = 12;

contracts/src/TestVerifier.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ contract TestVerifier is ITestVerifier {
2727
IRiscZeroVerifier public immutable verifier;
2828

2929
/// @notice Image ID of the only zkVM guest to accept verification from.
30-
bytes32 public constant imageId = ImageID.BALANCE_AND_EXITS_ID;
30+
bytes32 public constant imageId = ImageID.MAINNET_ID;
3131

3232
/// @notice Initialize the contract, binding it to a specified RISC Zero verifier.
3333
constructor(IRiscZeroVerifier _verifier) {

crates/guest-io/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ edition = "2021"
66
[features]
77
default = []
88
builder = ["ssz-multiproofs/builder", "dep:ssz_rs", "dep:ethereum-consensus", "dep:gindices", "dep:beacon-state", "risc0-steel/host"]
9-
sepolia = []
109

1110
[dependencies]
1211
ssz-multiproofs = { workspace = true }

crates/guest-io/src/io.rs

Lines changed: 12 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ pub struct InputWithReceipt<T> {
3939
}
4040

4141
pub mod validator_membership {
42-
4342
use risc0_zkvm::serde::to_vec;
4443

4544
use super::*;
@@ -104,6 +103,7 @@ pub mod validator_membership {
104103
self_program_id
105104
))]
106105
pub fn build_continuation<D: Into<Digest>>(
106+
withdrawal_credentials: B256,
107107
prior_beacon_state: &BeaconState,
108108
prior_max_validator_index: u64,
109109
beacon_state: &BeaconState,
@@ -127,9 +127,7 @@ pub mod validator_membership {
127127
.validators()
128128
.iter()
129129
.take((prior_max_validator_index + 1) as usize)
130-
.map(|v| {
131-
v.withdrawal_credentials.as_slice() == crate::WITHDRAWAL_CREDENTIALS.as_slice()
132-
})
130+
.map(|v| v.withdrawal_credentials.as_slice() == withdrawal_credentials.as_slice())
133131
.collect::<BitVec<u32, Lsb0>>();
134132

135133
let (cont_type, hist_summary_multiproof) = if slot == prior_slot {
@@ -144,7 +142,7 @@ pub mod validator_membership {
144142
);
145143
let hist_summary_multiproof = MultiproofBuilder::new()
146144
.with_gindex(historical_batch_gindices::state_roots(prior_slot).try_into()?)
147-
.build(&historical_batch, Option::<(_, usize)>::None)?;
145+
.build(&historical_batch)?;
148146
(ContinuationType::LongRange, Some(hist_summary_multiproof))
149147
} else {
150148
return Err(Error::MissingHistoricalBatch);
@@ -259,6 +257,7 @@ pub mod balance_and_exits {
259257
impl Input<'_> {
260258
#[tracing::instrument(skip(block_header, beacon_state, evm_input))]
261259
pub fn build(
260+
withdrawal_credentials: B256,
262261
block_header: &BeaconBlockHeader,
263262
beacon_state: &BeaconState,
264263
evm_input: EthEvmInput,
@@ -268,17 +267,15 @@ pub mod balance_and_exits {
268267
let membership = beacon_state
269268
.validators()
270269
.iter()
271-
.map(|v| {
272-
v.withdrawal_credentials.as_slice() == crate::WITHDRAWAL_CREDENTIALS.as_slice()
273-
})
270+
.map(|v| v.withdrawal_credentials.as_slice() == withdrawal_credentials.as_slice())
274271
.collect::<BitVec<u32, Lsb0>>();
275272

276273
tracing::info!("{} Lido validators detected", membership.count_ones());
277274

278275
let block_multiproof = MultiproofBuilder::new()
279276
.with_gindex(beacon_block_gindices::slot().try_into()?)
280277
.with_gindex(beacon_block_gindices::state_root().try_into()?)
281-
.build(block_header, Option::<(_, usize)>::None)?;
278+
.build(block_header)?;
282279

283280
let state_multiproof_builder = MultiproofBuilder::new()
284281
.with_gindex(beacon_state_gindices::validator_count().try_into()?)
@@ -330,50 +327,12 @@ fn build_with_versioned_state(
330327
builder: MultiproofBuilder,
331328
beacon_state: &BeaconState,
332329
) -> Result<Multiproof<'static>> {
333-
use beacon_state::mainnet::ElectraBeaconState;
334-
335330
match beacon_state {
336-
BeaconState::Phase0(b) => Ok(builder.build(
337-
b,
338-
Some((
339-
BeaconState::generalized_index(&["validators".into()]).unwrap(),
340-
beacon_state.validators().clone(),
341-
)),
342-
)?),
343-
BeaconState::Altair(b) => Ok(builder.build(
344-
b,
345-
Some((
346-
BeaconState::generalized_index(&["validators".into()]).unwrap(),
347-
beacon_state.validators().clone(),
348-
)),
349-
)?),
350-
BeaconState::Bellatrix(b) => Ok(builder.build(
351-
b,
352-
Some((
353-
BeaconState::generalized_index(&["validators".into()]).unwrap(),
354-
beacon_state.validators().clone(),
355-
)),
356-
)?),
357-
BeaconState::Capella(b) => Ok(builder.build(
358-
b,
359-
Some((
360-
BeaconState::generalized_index(&["validators".into()]).unwrap(),
361-
beacon_state.validators().clone(),
362-
)),
363-
)?),
364-
BeaconState::Deneb(b) => Ok(builder.build(
365-
b,
366-
Some((
367-
BeaconState::generalized_index(&["validators".into()]).unwrap(),
368-
beacon_state.validators().clone(),
369-
)),
370-
)?),
371-
BeaconState::Electra(b) => Ok(builder.build(
372-
b,
373-
Some((
374-
ElectraBeaconState::generalized_index(&["validators".into()]).unwrap(),
375-
beacon_state.validators().clone(),
376-
)),
377-
)?),
331+
BeaconState::Phase0(b) => Ok(builder.build(b)?),
332+
BeaconState::Altair(b) => Ok(builder.build(b)?),
333+
BeaconState::Bellatrix(b) => Ok(builder.build(b)?),
334+
BeaconState::Capella(b) => Ok(builder.build(b)?),
335+
BeaconState::Deneb(b) => Ok(builder.build(b)?),
336+
BeaconState::Electra(b) => Ok(builder.build(b)?),
378337
}
379338
}

crates/guest-io/src/lib.rs

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,31 +15,38 @@
1515
mod error;
1616
mod io;
1717

18-
use alloy_primitives::{address, Address};
1918
use revm::primitives::hardfork::SpecId;
2019
use risc0_steel::config::{ChainSpec, ForkCondition};
2120
use risc0_steel::ethereum::EthChainSpec;
2221
pub use risc0_steel::ethereum::ETH_SEPOLIA_CHAIN_SPEC;
2322
use std::collections::BTreeMap;
2423
use std::sync::LazyLock;
2524

26-
#[cfg(not(feature = "sepolia"))] // mainnet
27-
pub const WITHDRAWAL_CREDENTIALS: alloy_primitives::B256 = alloy_primitives::B256::new([
28-
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xb9, 0xd7, 0x93, 0x48,
29-
0x78, 0xb5, 0xfb, 0x96, 0x10, 0xb3, 0xfe, 0x8a, 0x5e, 0x44, 0x1e, 0x8f, 0xad, 0x7e, 0x29, 0x3f,
30-
]);
25+
pub mod mainnet {
26+
use alloy_primitives::{address, Address};
3127

32-
#[cfg(not(feature = "sepolia"))] // mainnet
33-
pub const WITHDRAWAL_VAULT_ADDRESS: Address = address!("b9d7934878b5fb9610b3fe8a5e441e8fad7e293f");
28+
pub const WITHDRAWAL_CREDENTIALS: alloy_primitives::B256 = alloy_primitives::B256::new([
29+
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xb9, 0xd7, 0x93,
30+
0x48, 0x78, 0xb5, 0xfb, 0x96, 0x10, 0xb3, 0xfe, 0x8a, 0x5e, 0x44, 0x1e, 0x8f, 0xad, 0x7e,
31+
0x29, 0x3f,
32+
]);
3433

35-
#[cfg(feature = "sepolia")]
36-
pub const WITHDRAWAL_CREDENTIALS: alloy_primitives::B256 = alloy_primitives::B256::new([
37-
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xde, 0x73, 0x18, 0xaf,
38-
0xa6, 0x7e, 0xad, 0x6d, 0x6b, 0xbc, 0x82, 0x24, 0xdf, 0xce, 0x5e, 0xd6, 0xe4, 0xb8, 0x6d, 0x76,
39-
]);
34+
pub const WITHDRAWAL_VAULT_ADDRESS: Address =
35+
address!("b9d7934878b5fb9610b3fe8a5e441e8fad7e293f");
36+
}
4037

41-
#[cfg(feature = "sepolia")]
42-
pub const WITHDRAWAL_VAULT_ADDRESS: Address = address!("De7318Afa67eaD6d6bbC8224dfCe5ed6e4b86d76");
38+
pub mod sepolia {
39+
use alloy_primitives::{address, Address};
40+
41+
pub const WITHDRAWAL_CREDENTIALS: alloy_primitives::B256 = alloy_primitives::B256::new([
42+
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xde, 0x73, 0x18,
43+
0xaf, 0xa6, 0x7e, 0xad, 0x6d, 0x6b, 0xbc, 0x82, 0x24, 0xdf, 0xce, 0x5e, 0xd6, 0xe4, 0xb8,
44+
0x6d, 0x76,
45+
]);
46+
47+
pub const WITHDRAWAL_VAULT_ADDRESS: Address =
48+
address!("De7318Afa67eaD6d6bbC8224dfCe5ed6e4b86d76");
49+
}
4350

4451
pub static ANVIL_CHAIN_SPEC: LazyLock<EthChainSpec> = LazyLock::new(|| ChainSpec {
4552
chain_id: 31337,

crates/ssz-multiproofs/Cargo.toml

Lines changed: 0 additions & 30 deletions
This file was deleted.

0 commit comments

Comments
 (0)