Bump to latest Ethers (#26)

* chore: bump ethers

* fix: adjust ethers breaking changes

1. Use the abigen'd ::deploy methods
2. Use Anvil instead of Ganache

* silence warning

* fix: replace abi with full verifier artifact

* ci: use anvil instead of the node stack

* chore: remove ethers-solc

* fix: return error instead of raise

17c0834abf
this api got deprecated and would panic instead of generating an error that can behandled

* lints

* minimfy json
This commit is contained in:
Georgios Konstantopoulos 2022-08-29 15:06:27 -07:00 committed by GitHub
parent 8f6fcaf40b
commit 06eb0759e0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 1222 additions and 905 deletions

View File

@ -19,21 +19,11 @@ jobs:
toolchain: stable toolchain: stable
override: true override: true
- name: Install node # Install for Anvil
uses: actions/setup-node@v1 - name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
with: with:
node-version: 10 version: nightly
- name: Install ganache
run: npm install -g ganache-cli
- name: Install Solc
run: |
mkdir -p "$HOME/bin"
wget -q https://github.com/ethereum/solidity/releases/download/v0.7.6/solc-static-linux -O $HOME/bin/solc
chmod u+x "$HOME/bin/solc"
export PATH=$HOME/bin:$PATH
solc --version
- uses: Swatinem/rust-cache@v1 - uses: Swatinem/rust-cache@v1
with: with:

2064
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -13,7 +13,7 @@ pub struct CircomCircuit<E: PairingEngine> {
pub witness: Option<Vec<E::Fr>>, pub witness: Option<Vec<E::Fr>>,
} }
impl<'a, E: PairingEngine> CircomCircuit<E> { impl<E: PairingEngine> CircomCircuit<E> {
pub fn get_public_inputs(&self) -> Option<Vec<E::Fr>> { pub fn get_public_inputs(&self) -> Option<Vec<E::Fr>> {
match &self.witness { match &self.witness {
None => None, None => None,

View File

@ -307,14 +307,14 @@ mod runtime {
pub fn error(store: &Store) -> Function { pub fn error(store: &Store) -> Function {
#[allow(unused)] #[allow(unused)]
#[allow(clippy::many_single_char_names)] #[allow(clippy::many_single_char_names)]
fn func(a: i32, b: i32, c: i32, d: i32, e: i32, f: i32) { fn func(a: i32, b: i32, c: i32, d: i32, e: i32, f: i32) -> Result<(), RuntimeError> {
// NOTE: We can also get more information why it is failing, see p2str etc here: // NOTE: We can also get more information why it is failing, see p2str etc here:
// https://github.com/iden3/circom_runtime/blob/master/js/witness_calculator.js#L52-L64 // https://github.com/iden3/circom_runtime/blob/master/js/witness_calculator.js#L52-L64
println!( println!(
"runtime error, exiting early: {0} {1} {2} {3} {4} {5}", "runtime error, exiting early: {0} {1} {2} {3} {4} {5}",
a, b, c, d, e, f a, b, c, d, e, f
); );
RuntimeError::raise(Box::new(ExitCode(1))); Err(RuntimeError::user(Box::new(ExitCode(1))))
} }
Function::new_native(store, func) Function::new_native(store, func)
} }

View File

@ -56,7 +56,7 @@ fn groth16_proof_wrong_input() {
let mut rng = thread_rng(); let mut rng = thread_rng();
let _params = generate_random_parameters::<Bn254, _, _>(circom, &mut rng).unwrap(); let _params = generate_random_parameters::<Bn254, _, _>(circom, &mut rng).unwrap();
builder.build().unwrap_err(); let _ = builder.build().unwrap_err();
} }
#[test] #[test]

View File

@ -6,11 +6,11 @@ use ark_bn254::Bn254;
use ark_groth16::{create_random_proof as prove, generate_random_parameters}; use ark_groth16::{create_random_proof as prove, generate_random_parameters};
use ethers::{ use ethers::{
contract::{abigen, ContractError, ContractFactory}, contract::ContractError,
prelude::abigen,
providers::{Http, Middleware, Provider}, providers::{Http, Middleware, Provider},
utils::{compile_and_launch_ganache, Ganache, Solc}, utils::Anvil,
}; };
use std::{convert::TryFrom, sync::Arc}; use std::{convert::TryFrom, sync::Arc};
#[tokio::test] #[tokio::test]
@ -35,33 +35,22 @@ async fn solidity_verifier() -> Result<()> {
let proof = prove(circom, &params, &mut rng)?; let proof = prove(circom, &params, &mut rng)?;
// launch the network & compile the verifier // launch the network & compile the verifier
let (compiled, ganache) = let anvil = Anvil::new().spawn();
compile_and_launch_ganache(Solc::new("./tests/verifier.sol"), Ganache::new()).await?; let acc = anvil.addresses()[0];
let acc = ganache.addresses()[0]; let provider = Provider::<Http>::try_from(anvil.endpoint())?;
let provider = Provider::<Http>::try_from(ganache.endpoint())?;
let provider = provider.with_sender(acc); let provider = provider.with_sender(acc);
let provider = Arc::new(provider); let provider = Arc::new(provider);
// deploy the verifier // deploy the verifier
let contract = { let contract = Groth16Verifier::deploy(provider.clone(), ())?
let contract = compiled .send()
.get("TestVerifier") .await?;
.expect("could not find contract");
let factory = ContractFactory::new(
contract.abi.clone(),
contract.bytecode.clone(),
provider.clone(),
);
let contract = factory.deploy(())?.send().await?;
let addr = contract.address();
Groth16Verifier::new(addr, provider)
};
// check the proof // check the proof
let verified = contract let verified = contract
.check_proof(proof, params.vk, inputs.as_slice()) .check_proof(proof, params.vk, inputs.as_slice())
.await?; .await?;
assert!(verified); assert!(verified);
Ok(()) Ok(())
@ -70,8 +59,8 @@ async fn solidity_verifier() -> Result<()> {
// We need to implement the conversion from the Ark-Circom's internal Ethereum types to // We need to implement the conversion from the Ark-Circom's internal Ethereum types to
// the ones expected by the abigen'd types. Could we maybe provide a convenience // the ones expected by the abigen'd types. Could we maybe provide a convenience
// macro for these, given that there's room for implementation error? // macro for these, given that there's room for implementation error?
abigen!(Groth16Verifier, "./tests/verifier_abi.json"); abigen!(Groth16Verifier, "./tests/verifier_artifact.json");
use groth16verifier_mod::{G1Point, G2Point, Proof, VerifyingKey}; use groth_16_verifier::{G1Point, G2Point, Proof, VerifyingKey};
impl From<ethereum::G1> for G1Point { impl From<ethereum::G1> for G1Point {
fn from(src: ethereum::G1) -> Self { fn from(src: ethereum::G1) -> Self {
Self { x: src.x, y: src.y } Self { x: src.x, y: src.y }

View File

@ -1 +0,0 @@
[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"uint256[]","name":"input","type":"uint256[]"},{"components":[{"components":[{"internalType":"uint256","name":"X","type":"uint256"},{"internalType":"uint256","name":"Y","type":"uint256"}],"internalType":"struct Pairing.G1Point","name":"A","type":"tuple"},{"components":[{"internalType":"uint256[2]","name":"X","type":"uint256[2]"},{"internalType":"uint256[2]","name":"Y","type":"uint256[2]"}],"internalType":"struct Pairing.G2Point","name":"B","type":"tuple"},{"components":[{"internalType":"uint256","name":"X","type":"uint256"},{"internalType":"uint256","name":"Y","type":"uint256"}],"internalType":"struct Pairing.G1Point","name":"C","type":"tuple"}],"internalType":"struct Verifier.Proof","name":"proof","type":"tuple"},{"components":[{"components":[{"internalType":"uint256","name":"X","type":"uint256"},{"internalType":"uint256","name":"Y","type":"uint256"}],"internalType":"struct Pairing.G1Point","name":"alfa1","type":"tuple"},{"components":[{"internalType":"uint256[2]","name":"X","type":"uint256[2]"},{"internalType":"uint256[2]","name":"Y","type":"uint256[2]"}],"internalType":"struct Pairing.G2Point","name":"beta2","type":"tuple"},{"components":[{"internalType":"uint256[2]","name":"X","type":"uint256[2]"},{"internalType":"uint256[2]","name":"Y","type":"uint256[2]"}],"internalType":"struct Pairing.G2Point","name":"gamma2","type":"tuple"},{"components":[{"internalType":"uint256[2]","name":"X","type":"uint256[2]"},{"internalType":"uint256[2]","name":"Y","type":"uint256[2]"}],"internalType":"struct Pairing.G2Point","name":"delta2","type":"tuple"},{"components":[{"internalType":"uint256","name":"X","type":"uint256"},{"internalType":"uint256","name":"Y","type":"uint256"}],"internalType":"struct Pairing.G1Point[]","name":"IC","type":"tuple[]"}],"internalType":"struct Verifier.VerifyingKey","name":"vk","type":"tuple"}],"name":"verify","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"}]

File diff suppressed because one or more lines are too long