Skip to content

Commit 7b9c8fe

Browse files
committed
revert unwanted changes
1 parent 589b7c2 commit 7b9c8fe

File tree

5 files changed

+61
-153
lines changed

5 files changed

+61
-153
lines changed

Cargo.toml

+23-5
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,17 @@ eth-types = { path = "eth-types" }
3939
contracts = { path = "contracts" }
4040
preprocessor = { path = "preprocessor" }
4141

42-
halo2curves = { package = "halo2curves-axiom", version = "=0.5.2" }
4342

44-
ssz_rs = { git = "https://github.com/ralexstokes/ssz-rs", rev = "5f1ec833718efa07bbbff427ab28a1eeaa706164" }
45-
halo2-base = { git = "https://github.com/nulltea/halo2-lib", branch = "feat/bls12-381-hash2curve" }
46-
halo2-ecc = { git = "https://github.com/nulltea/halo2-lib", branch = "feat/bls12-381-hash2curve" }
47-
zkevm-hashes = { git = "https://github.com/nulltea/halo2-lib", branch = "feat/bls12-381-hash2curve" }
43+
# halo2
44+
halo2-base = { git = "https://github.com/axiom-crypto/halo2-lib", tag = "v0.4.1", default-features = false, features = [
45+
"halo2-pse",
46+
"display",
47+
"jemallocator",
48+
] }
49+
halo2-ecc = { git = "https://github.com/axiom-crypto/halo2-lib", tag = "v0.4.1", default-features = false }
50+
zkevm-hashes = { git = "https://github.com/axiom-crypto/halo2-lib", tag = "v0.4.1", default-features = false }
51+
52+
halo2curves = { package = "halo2curves-axiom", version = "=0.5.2" }
4853

4954
# verifier SDK
5055
snark-verifier = { git = "https://github.com/axiom-crypto/snark-verifier.git", tag = "v0.1.7-git", default-features = false, features = [
@@ -64,6 +69,7 @@ snark-verifier-sdk = { git = "https://github.com/axiom-crypto/snark-verifier.git
6469
# ethereum types
6570
ethereum-consensus-types = { git = "https://github.com/ChainSafe/ethereum-consensus-types", branch = "capella" }
6671
beacon-api-client = { git = "https://github.com/ralexstokes/ethereum-consensus.git", rev = "f3bff52e9c43866f231ec40c8ab0e34125a8957f" }
72+
ssz_rs = "0.9"
6773

6874
# crypto
6975
group = "0.13"
@@ -81,3 +87,15 @@ getset = "0.1.2"
8187
log = "0.4.14"
8288
hex = "0.4"
8389
ark-std = { version = "0.4.0", features = ["print-trace"] }
90+
91+
92+
[patch.crates-io]
93+
ssz_rs = { git = "https://github.com/ralexstokes/ssz-rs", rev = "5f1ec833718efa07bbbff427ab28a1eeaa706164" }
94+
halo2-base = { git = "https://github.com/nulltea/halo2-lib", branch = "feat/bls12-381-hash2curve" }
95+
halo2-ecc = { git = "https://github.com/nulltea/halo2-lib", branch = "feat/bls12-381-hash2curve" }
96+
zkevm-hashes = { git = "https://github.com/nulltea/halo2-lib", branch = "feat/bls12-381-hash2curve" }
97+
98+
[patch."https://github.com/axiom-crypto/halo2-lib"]
99+
halo2-base = { git = "https://github.com/nulltea/halo2-lib", branch = "feat/bls12-381-hash2curve" }
100+
halo2-ecc = { git = "https://github.com/nulltea/halo2-lib", branch = "feat/bls12-381-hash2curve" }
101+
zkevm-hashes = { git = "https://github.com/nulltea/halo2-lib", branch = "feat/bls12-381-hash2curve" }

contracts/src/lib.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,11 @@
1-
// replace this crate with the actual contracts crate to run integration tests
1+
/*
2+
As a user looking to run contract integration tests it is recommended
3+
that you delete this crate (the 'contracts' crate) and replace it with
4+
the contracts crate found here:
5+
6+
https://github.com/ChainSafe/spectre-contracts/tree/a430caeb3678582b73e3ee73b6f001bd9d1e75ca
7+
8+
To run the contract integration tests afterwards, run:
9+
10+
cargo test -- --features contracts
11+
*/

lightclient-circuits/proof.txt

-23.1 KB
Binary file not shown.

lightclient-circuits/src/committee_update_circuit.rs

+27-147
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,17 @@ use halo2_ecc::{
2929
fields::FieldChip,
3030
};
3131
use itertools::Itertools;
32-
use serde::{Deserialize, Serialize};
3332
use ssz_rs::Merkleized;
34-
use std::{
35-
env::var,
36-
fs::File,
37-
io::{Read, Result as IoResult, Write},
38-
iter,
39-
marker::PhantomData,
40-
vec,
41-
};
42-
33+
use std::{env::var, iter, marker::PhantomData, vec};
34+
35+
/// `CommitteeUpdateCircuit` maps next sync committee SSZ root in the finalized state root to the corresponding Poseidon commitment to the public keys.
36+
///
37+
/// Assumes that public keys are BLS12-381 points on G1; `sync_committee_branch` is exactly `S::SYNC_COMMITTEE_PUBKEYS_DEPTH` hashes in lenght.
38+
///
39+
/// The circuit exposes two public inputs:
40+
/// - `poseidon_commit` is a Poseidon "onion" commitment to the X coordinates of sync committee public keys. Coordinates are expressed as big-integer with two limbs of LIMB_BITS * 2 bits.
41+
/// - `committee_root_ssz` is a Merkle SSZ root of the list of sync committee public keys.
42+
/// - `finalized_header_root` is a Merkle SSZ root of the finalized header.
4343
#[derive(Clone, Debug, Default)]
4444
pub struct CommitteeUpdateCircuit<S: Spec, F: Field> {
4545
_f: PhantomData<F>,
@@ -268,57 +268,25 @@ impl<S: Spec> AppCircuit for CommitteeUpdateCircuit<S, bn256::Fr> {
268268

269269
#[cfg(test)]
270270
mod tests {
271-
fn write_struct_to_file<T: Serialize>(data: &T, file_path: &str) -> IoResult<()> {
272-
let encoded: Vec<u8> = bincode::serialize(data).expect("Failed to serialize");
273-
let mut file = File::create(file_path)?;
274-
file.write_all(&encoded)?;
275-
Ok(())
276-
}
277-
278-
fn read_struct_from_file<T: for<'de> Deserialize<'de>>(file_path: &str) -> IoResult<T> {
279-
let mut file = File::open(file_path)?;
280-
let mut buffer = Vec::new();
281-
file.read_to_end(&mut buffer)?;
282-
283-
// Deserialization can use the buffer's data, no lifetime issue
284-
let decoded: T = bincode::deserialize(&buffer)
285-
.map_err(|e| std::io::Error::new(std::io::ErrorKind::InvalidData, e))?;
286-
287-
Ok(decoded)
288-
}
289-
use std::{fs, io::Cursor};
271+
use std::fs;
290272

291273
use crate::{
292-
aggregation_circuit::AggregationConfigPinning, gadget::crypto::ShaFlexGateManager,
293-
util::Halo2ConfigPinning, witness::CommitteeUpdateArgs,
274+
aggregation_circuit::AggregationConfigPinning, util::Halo2ConfigPinning,
275+
witness::CommitteeUpdateArgs,
294276
};
295277

296278
use super::*;
297-
use bn256::G1Affine;
279+
use ark_std::{end_timer, start_timer};
298280
use eth_types::Testnet;
299-
use ff::Field;
300281
use halo2_base::{
301-
gates::circuit::{builder::BaseCircuitBuilder, BaseCircuitParams},
302282
halo2_proofs::{
283+
dev::MockProver,
303284
halo2curves::bn256::Fr,
304-
plonk::{create_proof, keygen_vk, verify_proof, Circuit, ProvingKey, VerifyingKey},
305-
poly::{
306-
commitment::Params,
307-
kzg::{
308-
commitment::{KZGCommitmentScheme, ParamsKZG},
309-
multiopen::{ProverSHPLONK, VerifierSHPLONK},
310-
strategy::SingleStrategy,
311-
},
312-
VerificationStrategy,
313-
},
314-
transcript::{
315-
Blake2bRead, Blake2bWrite, Challenge255, TranscriptReadBuffer,
316-
TranscriptWriterBuffer,
317-
},
285+
plonk::ProvingKey,
286+
poly::{commitment::Params, kzg::commitment::ParamsKZG},
318287
},
319288
utils::fs::gen_srs,
320289
};
321-
use rand::rngs::OsRng;
322290
use snark_verifier_sdk::evm::{evm_verify, gen_evm_proof_shplonk};
323291
use snark_verifier_sdk::{halo2::aggregation::AggregationCircuit, CircuitExt, Snark};
324292

@@ -343,113 +311,25 @@ mod tests {
343311
}
344312

345313
#[test]
346-
fn test_prove_and_verify_plonk() {
314+
fn test_committee_update_circuit() {
347315
const K: u32 = 20;
348-
let mut file = File::open("./params/kzg_bn254_20.srs").expect("Failed to open params!");
349-
350-
let mut buffer = Vec::new();
351-
352-
file.read_to_end(&mut buffer)
353-
.expect("Failed to read params!");
354-
355-
let params: ParamsKZG<Bn256> =
356-
ParamsKZG::read(&mut Cursor::new(&buffer)).expect("Failed to read buffer :(");
357-
358-
const PINNING_PATH: &str = "./config/committee_update_20.json";
359-
const PKEY_PATH: &str = "../build/committee_update_20.pkey";
360-
361-
let pk = CommitteeUpdateCircuit::<Testnet, Fr>::create_pk(
362-
&params,
363-
PKEY_PATH,
364-
PINNING_PATH,
365-
&CommitteeUpdateArgs::<Testnet>::default(),
366-
None,
367-
);
368-
369-
println!("[Ok] Proving Key");
370-
371316
let witness = load_circuit_args();
317+
let params: ParamsKZG<Bn256> = gen_srs(K);
372318

373319
let circuit = CommitteeUpdateCircuit::<Testnet, Fr>::create_circuit(
374-
CircuitBuilderStage::Prover,
375-
Some(Eth2ConfigPinning::from_path(PINNING_PATH)),
320+
CircuitBuilderStage::Mock,
321+
None,
376322
&witness,
377323
&params,
378324
)
379-
.expect("Failed to construct circuit");
380-
381-
println!("[Ok] Construct Circuit");
382-
383-
let reader: Vec<u8> = vec![];
384-
let mut transcript_writer: Blake2bWrite<Vec<u8>, G1Affine, Challenge255<G1Affine>> =
385-
Blake2bWrite::init(reader);
386-
println!("[Ok] Read Transcript");
387-
388-
let vk: &VerifyingKey<G1Affine> = pk.get_vk();
389-
390-
let circuit_params = circuit.params();
391-
//let vk_serialized = vk.to_bytes(halo2_base::halo2_proofs::SerdeFormat::RawBytes);
392-
393-
let witness_serialized = bincode::serialize(&witness).unwrap();
394-
let witness_deserialized: CommitteeUpdateArgs<Testnet> =
395-
bincode::deserialize(&witness_serialized).unwrap();
396-
397-
/*
398-
let instances = circuit.instances();
399-
let instances_ref: Vec<&[Fr]> = instances.iter().map(|inner| inner.as_slice()).collect();
400-
let instances_nested_ref: Vec<&[&[Fr]]> = instances_ref
401-
.iter()
402-
.map(|inner| std::slice::from_ref(inner))
403-
.collect();
404-
405-
create_proof::<
406-
KZGCommitmentScheme<Bn256>,
407-
ProverSHPLONK<Bn256>,
408-
Challenge255<G1Affine>,
409-
OsRng,
410-
Blake2bWrite<Vec<u8>, G1Affine, Challenge255<G1Affine>>,
411-
_,
412-
>(
413-
&params,
414-
&pk,
415-
&[circuit],
416-
&instances_nested_ref,
417-
OsRng,
418-
&mut transcript_writer,
419-
)
420-
.expect("Failed to generate proof!");
421-
422-
let reader_final = transcript_writer.finalize();
423-
424-
println!("[Ok] Proof");
425-
426-
let mut transcript_reader = Blake2bRead::init(&reader_final[..]);
325+
.unwrap();
427326

428-
write_struct_to_file(&reader_final, "proof.txt").expect("Failed to write proof");
429-
write_struct_to_file(&instances, "instances.txt").expect("Failed to write instances");
430-
write_struct_to_file(
431-
&vk.to_bytes(halo2_base::halo2_proofs::SerdeFormat::RawBytes),
432-
"vk.txt",
433-
)
434-
.expect("Failed to write vk");
435-
436-
verify_proof::<
437-
_,
438-
VerifierSHPLONK<Bn256>,
439-
Challenge255<G1Affine>,
440-
Blake2bRead<_, G1Affine, Challenge255<G1Affine>>,
441-
SingleStrategy<Bn256>,
442-
>(
443-
&params,
444-
&vk,
445-
SingleStrategy::new(&params),
446-
&instances_nested_ref,
447-
&mut transcript_reader,
448-
)
449-
.expect("Failed to verify!");
327+
let instance = CommitteeUpdateCircuit::<Testnet, Fr>::get_instances(&witness, LIMB_BITS);
450328

451-
println!("[Yippie]");
452-
*/
329+
let timer = start_timer!(|| "committee_update mock prover");
330+
let prover = MockProver::<Fr>::run(K, &circuit, instance).unwrap();
331+
prover.assert_satisfied();
332+
end_timer!(timer);
453333
}
454334

455335
#[test]

lightclient-circuits/vk.txt

-257 KB
Binary file not shown.

0 commit comments

Comments
 (0)