-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* RPC as a lib * Add new RPC endpoints to allow for proof gen with witnesses already supplied * Witness <> Arg conversion. Needs Cleanup * Some cleanup * Change state id to head * Remove sync commitee rs lib * Update SSZ and ethereum consensus crates * fix test compilation * clippy * More clippy * reexport jsonrpc_v2 lib * fix prover * clippy * break up rotation args gen * lightcleint update to args * Remove all beacon fetching out of the prover node * simplify generic * verifier contract gen fixes * add rpc endpoint for calculating poseidon committment * clippy
- Loading branch information
Showing
31 changed files
with
1,104 additions
and
377 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,29 +24,14 @@ incremental = true | |
[workspace.dependencies] | ||
lightclient-circuits = { path = "lightclient-circuits" } | ||
test-utils = { path = "test-utils" } | ||
ethereum-consensus-types = { git = "ssh://[email protected]/sygmaprotocol/Zipline.git", rev = "27e8a01" } | ||
ethereum-consensus-types = { git = "ssh://[email protected]/sygmaprotocol/Zipline.git", rev = "5ecf28d24690862814a7ebc5385c7e5c2eeb6e3d" } | ||
eth-types = { path = "eth-types" } | ||
contracts = { path = "contracts" } | ||
preprocessor = { path = "preprocessor" } | ||
ssz-rs = { git = "https://github.com/ralexstokes/ssz-rs", rev = "adf1a0b14cef90b9536f28ef89da1fab316465e1" } | ||
zipline-test-utils = { package = "test-utils", git = "ssh://[email protected]/sygmaprotocol/Zipline.git", rev = "27e8a01" } | ||
light-client-verifier = { git = "ssh://[email protected]/sygmaprotocol/Zipline.git", rev = "27e8a01" } | ||
sync-committee-primitives = { git = "https://github.com/polytope-labs/sync-committee-rs", version = "0.1.0" } | ||
halo2curves = { git = "https://github.com/privacy-scaling-explorations/halo2curves", tag = "0.3.1" } | ||
halo2-base = { git = "https://github.com/axiom-crypto/halo2-lib", branch = "community-edition", default-features = false, features = [ | ||
"halo2-pse", | ||
"display", | ||
] } | ||
snark-verifier-sdk = { git = "https://github.com/axiom-crypto/snark-verifier.git", branch = "community-edition", default-features = false, features = [ | ||
"display", | ||
"loader_halo2", | ||
"loader_evm", | ||
"halo2-pse", | ||
] } | ||
|
||
[patch."https://github.com/privacy-scaling-explorations/halo2curves"] | ||
halo2curves = { git = "https://github.com/sygmaprotocol/halo2curves", branch = "dev/bls12_381" } | ||
# halo2curves = { path = "../halo2curves" } | ||
zipline-test-utils = { package = "test-utils", git = "ssh://[email protected]/sygmaprotocol/Zipline.git", rev = "5ecf28d24690862814a7ebc5385c7e5c2eeb6e3d" } | ||
zipline-cryptography = { package = "cryptography", git = "ssh://[email protected]/sygmaprotocol/Zipline.git", rev = "5ecf28d24690862814a7ebc5385c7e5c2eeb6e3d" } | ||
light-client-verifier = { git = "ssh://[email protected]/sygmaprotocol/Zipline.git", rev = "5ecf28d24690862814a7ebc5385c7e5c2eeb6e3d" } | ||
beacon-api-client = { git = "https://github.com/ralexstokes/ethereum-consensus.git", rev = "f3bff52e9c43866f231ec40c8ab0e34125a8957f" } | ||
|
||
# halo2 | ||
halo2_proofs = { git = "https://github.com/privacy-scaling-explorations/halo2.git", tag = "v2023_02_02", features = [ | ||
|
@@ -75,12 +60,7 @@ snark-verifier-sdk = { git = "https://github.com/axiom-crypto/snark-verifier.git | |
] } | ||
halo2_solidity_verifier = { git = "https://github.com/privacy-scaling-explorations/halo2-solidity-verifier", branch = "ac/initial-verifier-PR" } | ||
|
||
# ethereum types | ||
sync-committee-primitives = { git = "https://github.com/polytope-labs/sync-committee-rs", version = "0.1.0" } | ||
sync-committee-prover = { git = "https://github.com/polytope-labs/sync-committee-rs", version = "0.1.0", features = [ | ||
"testnet", | ||
] } | ||
ssz-rs = { git = "https://github.com/ralexstokes/ssz-rs", rev = "adf1a0b14cef90b9536f28ef89da1fab316465e1" } | ||
ssz_rs = "0.9" | ||
|
||
# crypto | ||
group = "0.12" | ||
|
@@ -111,9 +91,5 @@ poseidon = { git = "https://github.com/timoftime/halo2-lib", rev = "95bf9a5ce6b6 | |
snark-verifier = { git = "https://github.com/timoftime/snark-verifier", branch = "timoftime/bump-revm" } | ||
snark-verifier-sdk = { git = "https://github.com/timoftime/snark-verifier", branch = "timoftime/bump-revm" } | ||
|
||
[patch."https://github.com/ralexstokes/ssz-rs"] | ||
ssz-rs = { git = "https://github.com/polytope-labs/ssz-rs", branch = "main" } | ||
|
||
[patch."https://github.com/polytope-labs/sync-committee-rs"] | ||
sync-committee-prover = { git = "https://github.com/timoftime/sync-committee-rs", branch = "dev/accept-ssz" } | ||
sync-committee-primitives = { git = "https://github.com/timoftime/sync-committee-rs", branch = "dev/accept-ssz" } | ||
[patch.crates-io] | ||
ssz_rs = { git = "https://github.com/ralexstokes/ssz-rs", rev = "5f1ec833718efa07bbbff427ab28a1eeaa706164" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,109 @@ | ||
use ethers::contract::abigen; | ||
|
||
abigen!(Spectre, "./out/Spectre.sol/Spectre.json"); | ||
|
||
abigen!(StepVerifier, "./out/sync_step.sol/Verifier.json"); | ||
#![feature(generic_const_exprs)] | ||
use std::ops::Deref; | ||
|
||
use ethers::contract::abigen; | ||
use halo2_base::utils::ScalarField; | ||
use halo2curves::bls12_381::{self}; | ||
use halo2curves::bn256::Fr; | ||
use itertools::Itertools; | ||
use lightclient_circuits::{ | ||
poseidon::fq_array_poseidon_native, | ||
witness::{CommitteeRotationArgs, SyncStepArgs}, | ||
}; | ||
use ssz_rs::{Merkleized, Vector}; | ||
abigen!( | ||
Spectre, | ||
"./out/Spectre.sol/Spectre.json"; | ||
StepVerifier, | ||
"./out/sync_step.sol/Verifier.json"; | ||
CommitteeUpdateVerifier, | ||
"./out/committee_update_aggregated.sol/Verifier.json" | ||
); | ||
|
||
abigen!( | ||
"./out/committee_update_aggregated.sol/Verifier.json"; | ||
StepMockVerifier, | ||
"./out/SyncStepMockVerifier.sol/SyncStepMockVerifier.json" | ||
); | ||
|
||
abigen!( | ||
"./out/SyncStepMockVerifier.sol/SyncStepMockVerifier.json"; | ||
CommitteeUpdateMockVerifier, | ||
"./out/CommitteeUpdateMockVerifier.sol/CommitteeUpdateMockVerifier.json" | ||
"./out/CommitteeUpdateMockVerifier.sol/CommitteeUpdateMockVerifier.json"; | ||
RotateExternal, | ||
"./out/RotateExternal.sol/RotateExternal.json"; | ||
SyncStepExternal, | ||
"./out/SyncStepExternal.sol/SyncStepExternal.json"; | ||
); | ||
|
||
// SyncStepInput type produced by abigen macro matches the solidity struct type | ||
impl<Spec: eth_types::Spec> From<SyncStepArgs<Spec>> for SyncStepInput { | ||
fn from(args: SyncStepArgs<Spec>) -> Self { | ||
let participation = args | ||
.pariticipation_bits | ||
.iter() | ||
.map(|v| *v as u64) | ||
.sum::<u64>(); | ||
|
||
let finalized_header_root: [u8; 32] = args | ||
.finalized_header | ||
.clone() | ||
.hash_tree_root() | ||
.unwrap() | ||
.deref() | ||
.try_into() | ||
.unwrap(); | ||
|
||
let execution_payload_root: [u8; 32] = args.execution_payload_root.try_into().unwrap(); | ||
|
||
SyncStepInput { | ||
attested_slot: args.attested_header.slot, | ||
finalized_slot: args.finalized_header.slot, | ||
participation, | ||
finalized_header_root, | ||
execution_payload_root, | ||
} | ||
} | ||
} | ||
|
||
// CommitteeRotationArgs type produced by abigen macro matches the solidity struct type | ||
impl<Spec: eth_types::Spec> From<CommitteeRotationArgs<Spec, Fr>> for RotateInput | ||
where | ||
[(); Spec::SYNC_COMMITTEE_SIZE]:, | ||
{ | ||
fn from(args: CommitteeRotationArgs<Spec, Fr>) -> Self { | ||
let poseidon_commitment_le = poseidon_committee_commitment_from_compressed( | ||
&args | ||
.pubkeys_compressed | ||
.iter() | ||
.cloned() | ||
.map(|mut b| { | ||
b.reverse(); | ||
b | ||
}) | ||
.collect_vec(), | ||
); | ||
|
||
let mut pk_vector: Vector<Vector<u8, 48>, { Spec::SYNC_COMMITTEE_SIZE }> = args | ||
.pubkeys_compressed | ||
.iter() | ||
.cloned() | ||
.map(|v| v.try_into().unwrap()) | ||
.collect_vec() | ||
.try_into() | ||
.unwrap(); | ||
|
||
let sync_committee_ssz = pk_vector | ||
.hash_tree_root() | ||
.unwrap() | ||
.deref() | ||
.try_into() | ||
.unwrap(); | ||
|
||
RotateInput { | ||
sync_committee_ssz, | ||
sync_committee_poseidon: poseidon_commitment_le, | ||
} | ||
} | ||
} | ||
|
||
pub fn poseidon_committee_commitment_from_compressed(pubkeys_compressed: &[Vec<u8>]) -> [u8; 32] { | ||
let pubkeys_x = pubkeys_compressed.iter().cloned().map(|mut bytes| { | ||
bytes[47] &= 0b00011111; | ||
bls12_381::Fq::from_bytes_le(&bytes) | ||
}); | ||
let poseidon_commitment = fq_array_poseidon_native::<Fr>(pubkeys_x).unwrap(); | ||
poseidon_commitment.to_bytes_le().try_into().unwrap() | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.