Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing/Adding Prover to make it compatible with Go node #36

Merged
merged 25 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,16 @@ beacon-api-client = { git = "https://github.com/ralexstokes/ethereum-consensus.g
ssz_rs = "0.9"

# crypto
group = "0.12"
group = "0.13"
num-bigint = { version = "0.4", features = ["rand"] }
pasta_curves = "0.4.1"
ff = "0.12"
pasta_curves = "0.5.1"
ff = "0.13"
sha2 = { version = "0.10.6", features = ["compress"] }
uint = "0.9.1"
ark-std = { version = "0.4.0", features = ["print-trace"] }

# misc
itertools = "0.11.0"
itertools = "0.12.0"
serde = { version = "1.0.130", features = ["derive"] }
serde_json = "1.0.78"
log = "0.4.14"
Expand Down
6 changes: 3 additions & 3 deletions contracts/snark-verifiers/committee_update_aggregated.sol

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions contracts/snark-verifiers/sync_step.sol

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ setup-committee-update network:
cargo run -r -- circuit committee-update -p ./build/committee_update_$1.pkey -k 18 \
--verifier-k 25 --verifier-pk-path ./build/committee_update_verifier_$1.pkey setup

gen-step-evm-verifier:
cargo run -r -- circuit sync-step -c ./lightclient-circuits/config/sync_step.json -o evm-verifier ./contracts/snark-verifiers/sync_step.yul
gen-step-evm-verifier network:
cargo run -r -- circuit sync-step --pk-path ./build/sync_step_$1.pkey gen-verifier --solidity-out ./contracts/snark-verifiers/sync_step.yul

gen-rotation-evm-verifier:
cargo run -r -- circuit aggregation -c ./lightclient-circuits/config/aggregation.json --app-pk-path ./build/committee_update.pkey --app-config-path ./lightclient-circuits/config/committee_update.json -i ./rotation -o evm-verifier ./contracts/snark-verifiers/committee_update_aggregated.yul
gen-rotation-evm-verifier network:
cargo run -r -- circuit committee-update --pk-path ./build/committee_update_$1.pkey --verifier-pk-path ./build/committee_update_verifier_$1.pkey gen-verifier --solidity-out ./contracts/snark-verifiers/committee_update_aggregated.yul

build-contracts:
cd contracts && forge build
Expand Down
2 changes: 1 addition & 1 deletion lightclient-circuits/config/committee_update_18.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@
262133
]
]
}
}
31 changes: 31 additions & 0 deletions lightclient-circuits/config/committee_update_mainnet.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"params": {
"k": 18,
"num_advice_per_phase": [
12
],
"num_fixed": 1,
"num_lookup_advice_per_phase": [
1,
0,
0
],
"lookup_bits": 8,
"num_instance_columns": 1
},
"break_points": [
[
262134,
262132,
262134,
262132,
262133,
262132,
262132,
262133,
262132,
262134,
262133
]
]
}
22 changes: 11 additions & 11 deletions lightclient-circuits/config/committee_update_verifier_25.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"params": {
"degree": 25,
"num_advice": 1,
"num_lookup_advice": 1,
"num_fixed": 1,
"lookup_bits": 8
},
"break_points": [
[]
]
}
"params": {
"degree": 25,
"num_advice": 1,
"num_lookup_advice": 1,
"num_fixed": 1,
"lookup_bits": 8
},
"break_points": [
[]
]
}
12 changes: 12 additions & 0 deletions lightclient-circuits/config/committee_update_verifier_mainnet.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"params": {
"degree": 25,
"num_advice": 1,
"num_lookup_advice": 1,
"num_fixed": 1,
"lookup_bits": 8
},
"break_points": [
[]
]
}
25 changes: 25 additions & 0 deletions lightclient-circuits/config/sync_step_mainnet.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"params": {
"k": 22,
"num_advice_per_phase": [
6
],
"num_fixed": 1,
"num_lookup_advice_per_phase": [
1,
0,
0
],
"lookup_bits": 8,
"num_instance_columns": 1
},
"break_points": [
[
4194292,
4194294,
4194292,
4194293,
4194293
]
]
}
3 changes: 2 additions & 1 deletion lightclient-circuits/src/util/circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,5 +294,6 @@ where
C: Circuit<Fr>,
P: AsRef<Path>,
{
read_pk::<C>(fname.as_ref(), c.params()).expect("proving key should exist")
read_pk::<C>(fname.as_ref(), c.params())
.expect(format!("proving key: {:?} should exist", fname.as_ref().to_str()).as_str())
}
1 change: 1 addition & 0 deletions prover/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ reqwest = "0.11.22"
beacon-api-client.workspace = true
ethereum-consensus-types.workspace = true
futures = "0.3.29"
ssz_rs.workspace = true

[build-dependencies]
cli-batteries = "=0.4"
48 changes: 39 additions & 9 deletions prover/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,12 @@ where

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these changes will conflict with #37 tho fixes are pretty much same, consider taking version from #37 when merging

Ok(())
}
OperationCmd::GenVerifier(args) => {
gen_evm_verifier::<StepCircuit<S, Fr>>(&params, &pk_path, args.solidity_out)
}
OperationCmd::GenVerifier(args) => gen_evm_verifier::<StepCircuit<S, Fr>>(
&params,
&pk_path,
args.solidity_out,
None,
),
}
}
ProofCmd::CommitteeUpdate {
Expand All @@ -78,10 +81,11 @@ where
verifier_pk_path,
pk_path,
} => {
let params = gen_srs(k);
let cfg_path = get_config_path(&pk_path, &base_args.config_dir);
match operation {
OperationCmd::Setup => {
let params: ParamsKZG<Bn256> = gen_srs(k);

let pk = CommitteeUpdateCircuit::<S, Fr>::create_pk(
&params,
&pk_path,
Expand All @@ -98,9 +102,9 @@ where
)
.map_err(|e| eyre::eyre!("Failed to generate proof: {}", e))?;

let verifier_params = gen_srs(verifier_k);
let verifier_cfg_path =
get_config_path(&verifier_pk_path, &base_args.config_dir);
let verifier_params = gen_srs(verifier_k);

AggregationCircuit::create_pk(
&verifier_params,
Expand All @@ -112,7 +116,31 @@ where
Ok(())
}
OperationCmd::GenVerifier(args) => {
gen_evm_verifier::<StepCircuit<S, Fr>>(&params, &pk_path, args.solidity_out)
let params: ParamsKZG<Bn256> = gen_srs(k);

let pk = CommitteeUpdateCircuit::<S, Fr>::create_pk(
&params,
&pk_path,
&cfg_path,
&Default::default(),
);

let dummy_snark = CommitteeUpdateCircuit::<S, Fr>::gen_snark_shplonk(
&params,
&pk,
&cfg_path,
None::<String>,
&Default::default(),
)
.map_err(|e| eyre::eyre!("Failed to generate proof: {}", e))?;

let verifier_params = gen_srs(verifier_k);
gen_evm_verifier::<AggregationCircuit>(
&verifier_params,
&verifier_pk_path,
args.solidity_out,
Some(vec![dummy_snark]),
)
}
}
}
Expand All @@ -132,14 +160,16 @@ fn gen_evm_verifier<Circuit: AppCircuit>(
params: &ParamsKZG<Bn256>,
pk_path: &Path,
mut path_out: PathBuf,
witness_args: Option<Circuit::Witness>,
) -> eyre::Result<()>
where
Circuit::Witness: Default,
<Circuit as AppCircuit>::Witness: Default,
{
let pk = Circuit::read_pk(params, pk_path, &Default::default());
let witness_args = witness_args.unwrap_or_default();
let pk = Circuit::read_pk(params, pk_path, &witness_args);

let deplyment_code =
Circuit::gen_evm_verifier_shplonk(params, &pk, Some(path_out.clone()), &Default::default())
Circuit::gen_evm_verifier_shplonk(params, &pk, Some(path_out.clone()), &witness_args)
.map_err(|e| eyre::eyre!("Failed to EVM verifier: {}", e))?;
println!("yul size: {}", deplyment_code.len());
path_out.set_extension("yul");
Expand Down
2 changes: 1 addition & 1 deletion prover/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ async fn app(options: Cli) -> eyre::Result<()> {
args::Spec::Testnet => spec_app::<eth_types::Testnet>(op.proof, &options.args)
.await
.unwrap(),
args::Spec::Mainnet => spec_app::<eth_types::Testnet>(op.proof, &options.args)
args::Spec::Mainnet => spec_app::<eth_types::Mainnet>(op.proof, &options.args)
.await
.unwrap(),
},
Expand Down
18 changes: 9 additions & 9 deletions prover/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ pub(crate) async fn gen_evm_proof_rotation_circuit_with_witness_handler(

let (snark, verifier_filename) = match spec {
Spec::Minimal => {
let mut update = serde_json::from_slice(&light_client_update).unwrap();
let mut update = ssz_rs::deserialize(&light_client_update).unwrap();
let witness = rotation_args_from_update(&mut update).await.unwrap();
let snark = gen_committee_update_snark::<eth_types::Minimal>(
PathBuf::from("./lightclient-circuits/config/committee_update_minimal.json"),
Expand All @@ -178,7 +178,7 @@ pub(crate) async fn gen_evm_proof_rotation_circuit_with_witness_handler(
(snark, "committee_update_verifier_minimal")
}
Spec::Testnet => {
let mut update = serde_json::from_slice(&light_client_update).unwrap();
let mut update = ssz_rs::deserialize(&light_client_update).unwrap();
let witness = rotation_args_from_update(&mut update).await.unwrap();
let snark = gen_committee_update_snark::<eth_types::Testnet>(
PathBuf::from("./lightclient-circuits/config/committee_update_testnet.json"),
Expand All @@ -189,7 +189,7 @@ pub(crate) async fn gen_evm_proof_rotation_circuit_with_witness_handler(
(snark, "committee_update_verifier_testnet")
}
Spec::Mainnet => {
let mut update = serde_json::from_slice(&light_client_update).unwrap();
let mut update = ssz_rs::deserialize(&light_client_update).unwrap();
let witness = rotation_args_from_update(&mut update).await.unwrap();
let snark = gen_committee_update_snark::<eth_types::Mainnet>(
PathBuf::from("./lightclient-circuits/config/committee_update_mainnet.json"),
Expand Down Expand Up @@ -297,8 +297,8 @@ pub(crate) async fn gen_evm_proof_step_circuit_with_witness_handler(

let (proof, instances) = match spec {
Spec::Minimal => {
let update = serde_json::from_slice(&light_client_finality_update).unwrap();
let pubkeys = serde_json::from_slice(&pubkeys).unwrap();
let update = ssz_rs::deserialize(&light_client_finality_update).unwrap();
let pubkeys = ssz_rs::deserialize(&pubkeys).unwrap();
let witness = step_args_from_finality_update(update, pubkeys, domain)
.await
.unwrap();
Expand All @@ -311,8 +311,8 @@ pub(crate) async fn gen_evm_proof_step_circuit_with_witness_handler(
)
}
Spec::Testnet => {
let update = serde_json::from_slice(&light_client_finality_update).unwrap();
let pubkeys = serde_json::from_slice(&pubkeys).unwrap();
let update = ssz_rs::deserialize(&light_client_finality_update).unwrap();
let pubkeys = ssz_rs::deserialize(&pubkeys).unwrap();
let witness = step_args_from_finality_update(update, pubkeys, domain)
.await
.unwrap();
Expand All @@ -325,8 +325,8 @@ pub(crate) async fn gen_evm_proof_step_circuit_with_witness_handler(
)
}
Spec::Mainnet => {
let update = serde_json::from_slice(&light_client_finality_update).unwrap();
let pubkeys = serde_json::from_slice(&pubkeys).unwrap();
let update = ssz_rs::deserialize(&light_client_finality_update).unwrap();
let pubkeys = ssz_rs::deserialize(&pubkeys).unwrap();
let witness = step_args_from_finality_update(update, pubkeys, domain)
.await
.unwrap();
Expand Down
Loading