ChainSafe / ChainSafe/ProtoBanshee

Retrieve beacon state from consensus client

Open
#47 3 comments 0 reactions 0 assignees Claimed by @araskachoi View on GitHub
non-zk
Dominant language
Rust
Stars
0
Forks
0
PR merge metrics
No merged PRs in 30d

Description

Implement tooling to retrieve `BeaconState` from the consensus client and import it as [`zkcasper_circuits::Block`](https://github.com/ChainSafe/banshee-zk/blob/7dd9f6f90689995d4b01d1ce38cfe8ef43dbee31/zkcasper-circuits/src/witness/block.rs#L7). The goal is to be able to import the data for proving from the Rust whenever needed.

### Notes
- a pure Rust solutions, integrating with Rust-written client e.g. Lighthouse is desirable
- currently, there are 2 features that aren't supported by _founded_ Rust tooling:
1. get generalized indices ([example](https://github.com/ChainSafe/banshee-zk/blob/7dd9f6f90689995d4b01d1ce38cfe8ef43dbee31/preprocessor/scripts/generateMerkleTrace.ts#L57))
2. generate/verify Merkle multi proof and therefore generate computation trace ([example](https://github.com/ChainSafe/banshee-zk/blob/7dd9f6f90689995d4b01d1ce38cfe8ef43dbee31/preprocessor/scripts/merkleTrace.ts#L17))
- for (1) calculating gindexes isn't too complicated thus can be ported in Rust with relative ease, this is not the case for (2)
- as a workaround, while this tooling is not developed for Rust we can call js/ts over CLI or import everything as JSON

### Scope:
1. request `BeaconState` from a consensus client running locally, e.g. (ideally, a request is invoked from Rust using [beacon-APIs](https://ethereum.github.io/beacon-APIs))
- are there other ways to export BeaconState from Lodestar?
- could we embed Lodestar into TS script to pass the instance of BeaconState directly?
- can we ask Lodestar to write BeaconState to JSON file (or other encoding)?
- does Lodestar store BeaconState in some cache? if yes can we access it and recode from Rust/TS?
2. deserialize [`BeaconState`](https://github.com/ralexstokes/ethereum-consensus/blob/main/src/phase0/beacon_state.rs#L51) in Rust and convert it in validators into `Block` using [Block::from_beacon_state](https://github.com/ChainSafe/banshee-zk/blob/0000d2cbb8ba228327349a268c3824678276ac68/zkcasper-circuits/src/witness/block.rs#L28)
3. need to prepare `MerkleTrace` and since Rust tools aren't ready yet (currently in development) a possible workaround would be to call `generateMerkleTrace.ts` script from Rust
- if we get BeaconState from API we need to write it locally for TS script to read, this is inefficient but it's a temporary measure
- to call TS script from Rust the easiest way would be to simply execute the `npx tsx scripts/generateMerkleTrace.ts` via [`std::process::Command`](https://doc.rust-lang.org/std/process/struct.Command.html) and read `merkle_trace.json`
4. need to generate committees from validators
- TBD

### [Spec](https://hackmd.io/@timofey/rJ3f6B0B3)
- https://github.com/ethereum/consensus-specs/blob/v1.3.0/ssz/merkle-proofs.md
- https://eth2book.info/capella/part2/building_blocks/merkleization

### References
- Zipline preprocessing https://github.com/ChainSafe/Zipline/tree/main/preprocessor
- open PR to add Merkle multiproofs into ssz-rs https://github.com/ralexstokes/ssz-rs/pull/2
- asses the possibility to adapt https://github.com/antouhou/rs-merkle to Eth context
- Lighthouse Merkle single proofs impl https://github.com/sigp/lighthouse/tree/stable/consensus/merkle_proof
- Beacon API spec https://ethereum.github.io/beacon-APIs

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.