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

Switch to snark-verifier Solidity contracts #61

Merged
merged 19 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from 12 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
6 changes: 3 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[submodule "contracts/lib/forge-std"]
path = contracts/lib/forge-std
url = https://github.com/foundry-rs/forge-std
[submodule "contracts"]
path = contracts
url = https://github.com/ChainSafe/spectre-contracts
28 changes: 12 additions & 16 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ members = [
"preprocessor",
"eth-types",
"contract-tests",
"test-utils",
"contracts",
# "test-utils",
# "contracts",
]

resolver = "2"
Expand Down Expand Up @@ -52,21 +52,22 @@ zkevm-hashes = { git = "https://github.com/axiom-crypto/halo2-lib", tag = "v0.4.
halo2curves = { package = "halo2curves-axiom", version = "=0.5.2" }

# verifier SDK
snark-verifier = { git = "https://github.com/axiom-crypto/snark-verifier.git", tag = "v0.1.6", default-features = false, features = [
snark-verifier = { git = "https://github.com/axiom-crypto/snark-verifier.git", tag = "v0.1.7-git", default-features = false, features = [
"display",
"loader_halo2",
"loader_evm",
"halo2-pse",
] }
snark-verifier-sdk = { git = "https://github.com/axiom-crypto/snark-verifier.git", tag = "v0.1.6", default-features = false, features = [
snark-verifier-sdk = { git = "https://github.com/axiom-crypto/snark-verifier.git", tag = "v0.1.7-git", default-features = false, features = [
"display",
"loader_halo2",
"loader_evm",
"halo2-pse",
"revm",
] }

# ethereum types
ethereum-consensus-types = { git = "https://github.com/ChainSafe/ethereum-consensus-types", branch = "capella" }
ethereum-consensus-types = { git = "https://github.com/ChainSafe/ethereum-consensus-types", branch = "deneb" }
beacon-api-client = { git = "https://github.com/ralexstokes/ethereum-consensus.git", rev = "f3bff52e9c43866f231ec40c8ab0e34125a8957f" }
ssz_rs = "0.9"

Expand All @@ -90,16 +91,11 @@ ark-std = { version = "0.4.0", features = ["print-trace"] }

[patch.crates-io]
ssz_rs = { git = "https://github.com/ralexstokes/ssz-rs", rev = "5f1ec833718efa07bbbff427ab28a1eeaa706164" }
halo2-base = { git = "https://github.com/nulltea/halo2-lib", branch = "feat/zkevm-sha256-builder" }
halo2-ecc = { git = "https://github.com/nulltea/halo2-lib", branch = "feat/zkevm-sha256-builder" }
zkevm-hashes = { git = "https://github.com/nulltea/halo2-lib", branch = "feat/zkevm-sha256-builder" }
halo2-base = { git = "https://github.com/nulltea/halo2-lib", branch = "feat/bls12-381-hash2curve" }
halo2-ecc = { git = "https://github.com/nulltea/halo2-lib", branch = "feat/bls12-381-hash2curve" }
zkevm-hashes = { git = "https://github.com/nulltea/halo2-lib", branch = "feat/bls12-381-hash2curve" }

[patch."https://github.com/axiom-crypto/halo2-lib"]
halo2-base = { git = "https://github.com/nulltea/halo2-lib", branch = "feat/zkevm-sha256-builder" }
halo2-ecc = { git = "https://github.com/nulltea/halo2-lib", branch = "feat/zkevm-sha256-builder" }
zkevm-hashes = { git = "https://github.com/nulltea/halo2-lib", branch = "feat/zkevm-sha256-builder" }


[patch."https://github.com/axiom-crypto/snark-verifier.git"]
snark-verifier = { git = "https://github.com/nulltea/snark-verifier", branch = "yul-codegen" }
snark-verifier-sdk = { git = "https://github.com/nulltea/snark-verifier", branch = "yul-codegen" }
halo2-base = { git = "https://github.com/nulltea/halo2-lib", branch = "feat/bls12-381-hash2curve" }
halo2-ecc = { git = "https://github.com/nulltea/halo2-lib", branch = "feat/bls12-381-hash2curve" }
zkevm-hashes = { git = "https://github.com/nulltea/halo2-lib", branch = "feat/bls12-381-hash2curve" }
109 changes: 0 additions & 109 deletions contract-tests/tests/rotation_input_encoding.rs

This file was deleted.

10 changes: 4 additions & 6 deletions contract-tests/tests/spectre.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ use std::path::PathBuf;
use std::sync::Arc;

use contract_tests::make_client;
use contracts::{
CommitteeUpdateMockVerifier, Spectre, SyncStepCompressedMockVerifier, SyncStepInput,
};
use contracts::{MockVerifier, Spectre};
use ethers::core::types::U256;
use ethers::providers::Middleware;
use rstest::rstest;
Expand Down Expand Up @@ -55,7 +53,7 @@ async fn test_contract_initialization_and_first_step(
assert_eq!(contract.head().call().await?, U256::from(0));

// call step with the input and proof
let step_input: SyncStepInput = witness.into();
let step_input: contracts::StepInput = witness.into();
let step_call = contract.step(step_input.clone(), Vec::new().into());
let _receipt = step_call.send().await?.confirmations(1).await?;

Expand Down Expand Up @@ -85,10 +83,10 @@ async fn deploy_spectre_mock_verifiers<M: Middleware + 'static>(
initial_sync_committee_poseidon: U256,
slots_per_period: usize,
) -> anyhow::Result<Spectre<M>> {
let step_verifier = SyncStepCompressedMockVerifier::deploy(ethclient.clone(), ())?
let step_verifier = MockVerifier::deploy(ethclient.clone(), ())?
.send()
.await?;
let update_verifier = CommitteeUpdateMockVerifier::deploy(ethclient.clone(), ())?
let update_verifier = MockVerifier::deploy(ethclient.clone(), ())?
.send()
.await?;
Ok(Spectre::deploy(
Expand Down
25 changes: 10 additions & 15 deletions contract-tests/tests/step_input_encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,18 @@ use contract_tests::make_client;
use eth_types::{Minimal, LIMB_BITS};
use ethers::contract::abigen;
use lightclient_circuits::halo2_proofs::halo2curves::bn256;
use lightclient_circuits::sync_step_circuit::StepCircuit;
use lightclient_circuits::witness::SyncStepArgs;
use rstest::rstest;
use ssz_rs::Merkleized;
use test_utils::read_test_files_and_gen_witness;

abigen!(
SyncStepExternal,
"../contracts/out/SyncStepExternal.sol/SyncStepExternal.json"
StepExternal,
"../contracts/out/StepExternal.sol/StepExternal.json";
);

// SyncStepInput type produced by abigen macro matches the solidity struct type
impl<Spec: eth_types::Spec> From<SyncStepArgs<Spec>> for SyncStepInput {
impl<Spec: eth_types::Spec> From<SyncStepArgs<Spec>> for StepInput {
fn from(args: SyncStepArgs<Spec>) -> Self {
let participation = args
.pariticipation_bits
Expand All @@ -40,13 +39,12 @@ impl<Spec: eth_types::Spec> From<SyncStepArgs<Spec>> for SyncStepInput {

let execution_payload_root: [u8; 32] = args.execution_payload_root.try_into().unwrap();

SyncStepInput {
StepInput {
attested_slot: args.attested_header.slot,
finalized_slot: args.finalized_header.slot,
participation,
finalized_header_root,
execution_payload_root,
accumulator: Default::default(),
}
}
}
Expand All @@ -59,25 +57,22 @@ async fn test_step_instance_commitment_evm_equivalence(
path: PathBuf,
) -> anyhow::Result<()> {
use contract_tests::decode_solidity_u256_array;
use ethers::types::U256;

let (witness, _) = read_test_files_and_gen_witness(&path);
let instance = StepCircuit::<Minimal, bn256::Fr>::get_instances(&witness, LIMB_BITS);
let instance = lightclient_circuits::sync_step_circuit::StepCircuit:: <Minimal,bn256::Fr> ::get_instances(&witness, LIMB_BITS);

let (_anvil_instance, ethclient) = make_client();
let contract = SyncStepExternal::deploy(ethclient, ())?.send().await?;
let contract = StepExternal::deploy(ethclient, ())?.send().await?;

let result = contract
.to_public_inputs(
SyncStepInput::from(witness),
U256::from_little_endian(&instance[0][1].to_bytes()),
.to_public_inputs_commitment(
StepInput::from(witness),
)
.call()
.await?;
let result_decoded = decode_solidity_u256_array(&result);
let result_decoded = decode_solidity_u256_array(&[result]);

assert_eq!(result_decoded[12], instance[0][0]); // public input commitment
assert_eq!(result_decoded[13], instance[0][1]); // committee poseidon
assert_eq!(result_decoded[0], instance[0][0]); // public input commitment

Ok(())
}
1 change: 1 addition & 0 deletions contracts
Submodule contracts added at 4418b0
12 changes: 0 additions & 12 deletions contracts/.gitignore

This file was deleted.

16 changes: 0 additions & 16 deletions contracts/Cargo.toml

This file was deleted.

66 changes: 0 additions & 66 deletions contracts/README.md

This file was deleted.

19 changes: 0 additions & 19 deletions contracts/foundry.toml

This file was deleted.

Loading
Loading