Skip to content

Commit cf140f4

Browse files
authored
Willem/multiproof experiments (#18)
* avoid recomputing proof indices * add pivot feature to builder * remove progress bar and add features to support different chains * update with simplfied api * add faster strat for multiproof builder
1 parent ecfda33 commit cf140f4

File tree

16 files changed

+315
-269
lines changed

16 files changed

+315
-269
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ target/
2020
.idea
2121
*.bin
2222
*.input
23+
*.proof
2324
*.pb
2425

2526
contracts/dependencies/

.vscode/settings.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"rust-analyzer.linkedProjects": [
33
"./Cargo.toml",
4-
// "./guests/membership/guest/Cargo.toml",
5-
// "./guests/balance_and_exits/guest/Cargo.toml",
4+
"./guests/membership/guest/Cargo.toml",
5+
"./guests/balance_and_exits/guest/Cargo.toml",
66
],
77
"rust-analyzer.check.extraEnv": {
88
"RISC0_SKIP_BUILD": "1",

Cargo.lock

Lines changed: 1 addition & 47 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,15 @@ cargo risczero --version
107107

108108
This repo uses [just](https://github.com/casey/just) as a command runner. Installation instructions [here](https://github.com/casey/just?tab=readme-ov-file#installation)
109109

110-
It also uses git-lfs to manage cached inputs. Ensure this is installed.
110+
## Running tests
111+
112+
Use
113+
114+
```shell
115+
just test
116+
```
117+
118+
Attempting to run tests with `cargo test` will fail unless they can generate proofs locally.
111119

112120
## Usage
113121

@@ -142,62 +150,55 @@ See the [deployment guide](./docs/deployment-guide.md) for instructions on deplo
142150

143151
### Simple Usage via CLI
144152

145-
Using the justfile scripts provides a simple way to get started and examples of using the CLI. These will write intermediate files into the current directory.
153+
Using the justfile scripts provides a simple way to get started and examples of using the CLI. These will write intermediate proof files into the current directory.
146154
These are mostly included for example usage of the CLI. For a production deployment use the CLI directly as required.
147155

148156
#### Initial membership proof
149157

150-
The repo comes with the mainnet inputs built for slot 11494239.
151-
152158
To create a proof run
153159

154160
```shell
155-
just prove_membership_init 11494239
161+
just prove_membership_init <slot>
156162
```
157163

158164
#### Updating a membership proof
159165

160-
Update an existing membership proof to a newer beacon chain slot, e.g. to slot 11495000, you will need to build the inputs and then build a proof. Run
166+
Update an existing membership proof to a newer beacon chain slot you will need to build the inputs and then build a proof. Run
161167

162168
```shell
163-
just build_input_continuation 11494239 11495000
164-
just prove_membership_continuation 11494239 11495000
169+
just prove_membership_continuation <slot> <new_slot>
165170
```
166171

167-
This will write a new proof that composes the old one and proves the membership of all validators up to slot 11495000. There is no need to update membership proofs but it is a good way to save proving cycles.
172+
This will write a new proof that composes the old one and proves the membership of all validators up to slot `new_slot`. There is no need to update membership proofs but it is a good way to save proving cycles.
168173

169174
#### Building an aggregate oracle proof
170175

171176
To build a proof at this new slot ready to submit on-chain run:
172177

173178
```shell
174-
just build_input_aggregation 11495000
175-
just prove_aggregate 11495000
179+
just prove_aggregate <slot>
176180
```
177181

178-
This requires that a membership proof (either initial or continuation) for slot 1100 has already been created. It will write to file a proof and report ready to submit on-chain
182+
This requires that a membership proof (either initial or continuation) for `slot` has already been created. It will write to file a proof and report ready to submit on-chain
179183

180-
> [!NOTE]
181-
> For slots containing many Lido validators this will take a long time to build the SSZ proof input locally (hours) and to generate the proof (minutes on Bonsai)
182184

183185
Submit on-chain with:
184186

185187
```shell
186-
just submit 11495000
188+
just submit <slot>
187189
```
188190

189191
#### More advanced usage
190192

191193
Using the CLI directly provides more flexibility. See the help and subcommands help
192194

193195
```
194-
> cargo run --help
196+
> cargo run -- --help
195197
CLI for generating and submitting Lido oracle proofs
196198
197199
Usage: cli [OPTIONS] --slot <SLOT> <COMMAND>
198200
199201
Commands:
200-
build Build an input for a proof
201202
prove Generate a proof from a given input
202203
submit Submit an aggregation proof to the oracle contract
203204
help Print this message or the help of the given subcommand(s)

cli/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ sepolia = ["guest-io/sepolia", "membership_builder/sepolia"]
99

1010
[dependencies]
1111
ssz-multiproofs.workspace = true
12-
guest-io = { workspace = true, features = ["builder", "progress-bar"] }
12+
guest-io = { workspace = true, features = ["builder"] }
1313
membership_builder.workspace = true
1414
balance_and_exits_builder.workspace = true
1515
beacon-state = { workspace = true }

cli/src/beacon_client.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
use alloy::hex::FromHex;
16+
use alloy_primitives::B256;
1517
use beacon_state::mainnet::BeaconState;
1618
use ethereum_consensus::{
1719
phase0::SignedBeaconBlockHeader, primitives::Root, types::mainnet::BeaconBlock, Fork,
@@ -119,12 +121,15 @@ impl BeaconClient {
119121
Ok(result.data.header)
120122
}
121123

122-
/// Retrieves block details for given block id.
124+
/// Retrieves block hash for given beacon block id (e.g. slot).
123125
#[tracing::instrument(skip(self), fields(block_id = %block_id))]
124-
pub async fn get_block(&self, block_id: impl Display) -> Result<BeaconBlock, Error> {
126+
pub async fn get_eth1_block_hash_at_slot(&self, block_id: impl Display) -> Result<B256, Error> {
125127
let path = format!("eth/v2/beacon/blocks/{block_id}");
126-
let result: Response<GetBlockResponse> = self.http_get(&path).await?;
127-
Ok(result.data.message)
128+
let result: serde_json::Value = self.http_get(&path).await?;
129+
let hash_str = result["data"]["message"]["body"]["eth1_data"]["block_hash"]
130+
.as_str()
131+
.unwrap();
132+
Ok(B256::from_hex(&hash_str.trim_start_matches("0x")).unwrap())
128133
}
129134

130135
#[tracing::instrument(skip(self), fields(state_id = %state_id))]

0 commit comments

Comments
 (0)