From 392142a18946ac4d99bc92a0a3d70fb7acc8a0f0 Mon Sep 17 00:00:00 2001 From: roshan <19766713+rpalakkal@users.noreply.github.com> Date: Wed, 10 Jan 2024 13:04:44 -0500 Subject: [PATCH] feat: axiom-client-sdk cli --- axiom-client-derive/src/input.rs | 4 +- axiom-client-derive/src/lib.rs | 5 + axiom-client-sdk/Cargo.toml | 3 + axiom-client-sdk/data/account_age_input.json | 4 + axiom-client-sdk/data/quickstart_input.json | 8 ++ .../{src => }/examples/account_age.rs | 34 +----- .../{src => }/examples/quickstart.rs | 39 +----- axiom-client-sdk/readme.md | 11 ++ axiom-client-sdk/src/api.rs | 24 ++-- axiom-client-sdk/src/cmd.rs | 112 ++++++++++++++++++ axiom-client-sdk/src/compute.rs | 31 ++--- axiom-client-sdk/src/examples/mod.rs | 2 - axiom-client-sdk/src/lib.rs | 21 +++- axiom-client-sdk/src/subquery/account.rs | 16 +-- axiom-client-sdk/src/subquery/header.rs | 16 +-- axiom-client-sdk/src/subquery/mapping.rs | 14 +-- axiom-client-sdk/src/subquery/mod.rs | 59 +-------- axiom-client-sdk/src/subquery/receipt.rs | 24 ++-- axiom-client-sdk/src/subquery/storage.rs | 14 +-- axiom-client-sdk/src/subquery/tx.rs | 16 +-- axiom-client-sdk/src/utils/mod.rs | 17 +-- axiom-client/src/subquery/mod.rs | 17 ++- 22 files changed, 272 insertions(+), 219 deletions(-) create mode 100644 axiom-client-sdk/data/account_age_input.json create mode 100644 axiom-client-sdk/data/quickstart_input.json rename axiom-client-sdk/{src => }/examples/account_age.rs (67%) rename axiom-client-sdk/{src => }/examples/quickstart.rs (82%) create mode 100644 axiom-client-sdk/readme.md create mode 100644 axiom-client-sdk/src/cmd.rs delete mode 100644 axiom-client-sdk/src/examples/mod.rs diff --git a/axiom-client-derive/src/input.rs b/axiom-client-derive/src/input.rs index 9610034..16867ef 100644 --- a/axiom-client-derive/src/input.rs +++ b/axiom-client-derive/src/input.rs @@ -50,7 +50,7 @@ pub fn impl_new_struct(ast: &ItemStruct) -> Result { .zip(field_types.iter()) .map(|(name, field_type)| { quote! { - #name: <#field_type as axiom_client::input::raw_input::RawInput>::FEType, + #name: <#field_type as axiom_client::input::raw_input::RawInput>::FEType, } }) .collect(); @@ -218,7 +218,7 @@ pub fn impl_flatten_and_raw_input(ast: &DeriveInput) -> TokenStream { } } - impl #old_impl_generics crate::compute::AxiomComputeInput for #raw_circuit_name_ident #old_ty_generics { + impl #old_impl_generics axiom_client_sdk::compute::AxiomComputeInput for #raw_circuit_name_ident #old_ty_generics { type LogicInput = #raw_circuit_name_ident #old_ty_generics; type Input = #name #ty_generics; } diff --git a/axiom-client-derive/src/lib.rs b/axiom-client-derive/src/lib.rs index 7eaa733..6a79ebe 100644 --- a/axiom-client-derive/src/lib.rs +++ b/axiom-client-derive/src/lib.rs @@ -14,6 +14,7 @@ mod input; pub fn AxiomComputeInput(_args: TokenStream, input: TokenStream) -> TokenStream { let input_clone = input.clone(); let ast = parse_macro_input!(input_clone as ItemStruct); + let name = ast.ident.clone(); let new_struct = impl_new_struct(&ast); if let Err(err) = new_struct { return err.into(); @@ -27,6 +28,10 @@ pub fn AxiomComputeInput(_args: TokenStream, input: TokenStream) -> TokenStream #ast #new_struct #flatten + + fn main() { + axiom_client_sdk::cmd::run_cli::<#name>(); + } } .into() } diff --git a/axiom-client-sdk/Cargo.toml b/axiom-client-sdk/Cargo.toml index 74c965c..3390a5a 100644 --- a/axiom-client-sdk/Cargo.toml +++ b/axiom-client-sdk/Cargo.toml @@ -12,3 +12,6 @@ ethers = "2.0" anyhow = "1.0.75" serde = { version = "1.0", features = ["derive"] } lazy_static = "1.4.0" +clap = {version = "4.4.7", features = ["derive"]} +clap-num = "=1.0.2" +serde_json = "1.0.111" diff --git a/axiom-client-sdk/data/account_age_input.json b/axiom-client-sdk/data/account_age_input.json new file mode 100644 index 0000000..05e2720 --- /dev/null +++ b/axiom-client-sdk/data/account_age_input.json @@ -0,0 +1,4 @@ +{ + "addr": "0x897dDbe14c9C7736EbfDC58461355697FbF70048", + "claimed_block_number": 9173677 +} \ No newline at end of file diff --git a/axiom-client-sdk/data/quickstart_input.json b/axiom-client-sdk/data/quickstart_input.json new file mode 100644 index 0000000..f235055 --- /dev/null +++ b/axiom-client-sdk/data/quickstart_input.json @@ -0,0 +1,8 @@ +{ + "addr": "0x8dde5d4a8384f403f888e1419672d94c570440c9", + "block": 9730000, + "tx_block_number": 9728956, + "tx_idx": 10, + "slot": "0x0000000000000000000000000000000000000000000000000000000000000002", + "mapping_slot": "0x0000000000000000000000000000000000000000000000000000000000000001" +} \ No newline at end of file diff --git a/axiom-client-sdk/src/examples/account_age.rs b/axiom-client-sdk/examples/account_age.rs similarity index 67% rename from axiom-client-sdk/src/examples/account_age.rs rename to axiom-client-sdk/examples/account_age.rs index 388458c..cfd3756 100644 --- a/axiom-client-sdk/src/examples/account_age.rs +++ b/axiom-client-sdk/examples/account_age.rs @@ -1,21 +1,16 @@ use std::fmt::Debug; -use axiom_client::{ - axiom_eth::halo2_base::{ +use axiom_client_sdk::{ + axiom::{AxiomAPI, AxiomComputeFn, AxiomResult}, + halo2_base::{ gates::{GateChip, GateInstructions, RangeInstructions}, AssignedValue, }, - subquery::account::AccountField, + subquery::AccountField, + AxiomComputeInput, Fr, }; -use axiom_client_derive::AxiomComputeInput; use ethers::types::Address; -use crate::{ - api::AxiomAPI, - compute::{AxiomComputeFn, AxiomResult}, - Fr, -}; - #[AxiomComputeInput] pub struct AccountAgeInput { pub addr: Address, @@ -24,7 +19,7 @@ pub struct AccountAgeInput { impl AxiomComputeFn for AccountAgeInput { fn compute( - api: &mut AxiomAPI, + api: &mut AxiomAPI, assigned_inputs: AccountAgeCircuitInput>, ) -> Vec { let gate = GateChip::new(); @@ -49,20 +44,3 @@ impl AxiomComputeFn for AccountAgeInput { ] } } - -#[cfg(test)] -mod tests { - use std::str::FromStr; - - use super::*; - use crate::axiom_compute_tests; - - fn inputs() -> AccountAgeInput { - AccountAgeInput { - addr: Address::from_str("0x897dDbe14c9C7736EbfDC58461355697FbF70048").unwrap(), - claimed_block_number: 9173677, - } - } - - axiom_compute_tests!(AccountAgeInput, inputs, 12); -} diff --git a/axiom-client-sdk/src/examples/quickstart.rs b/axiom-client-sdk/examples/quickstart.rs similarity index 82% rename from axiom-client-sdk/src/examples/quickstart.rs rename to axiom-client-sdk/examples/quickstart.rs index 5045c52..04b75a9 100644 --- a/axiom-client-sdk/src/examples/quickstart.rs +++ b/axiom-client-sdk/examples/quickstart.rs @@ -1,19 +1,13 @@ use std::{fmt::Debug, str::FromStr}; -use axiom_client::{ - axiom_codec::HiLo, - axiom_eth::halo2_base::AssignedValue, - subquery::{account::AccountField, header::HeaderField, tx::TxField}, +use axiom_client_sdk::{ + axiom::{AxiomAPI, AxiomComputeFn, AxiomResult}, + halo2_base::AssignedValue, + subquery::{AccountField, HeaderField, TxField}, + AxiomComputeInput, Fr, HiLo, }; -use axiom_client_derive::AxiomComputeInput; use ethers::types::{Address, H256}; -use crate::{ - api::AxiomAPI, - compute::{AxiomComputeFn, AxiomResult}, - Fr, -}; - #[AxiomComputeInput] pub struct QuickstartInput { pub block: u64, @@ -26,7 +20,7 @@ pub struct QuickstartInput { impl AxiomComputeFn for QuickstartInput { fn compute( - api: &mut AxiomAPI, + api: &mut AxiomAPI, assigned_inputs: QuickstartCircuitInput>, ) -> Vec { // fetch block header data @@ -105,24 +99,3 @@ impl AxiomComputeFn for QuickstartInput { vec![] } } - -#[cfg(test)] -mod tests { - use std::str::FromStr; - - use super::*; - use crate::axiom_compute_tests; - - fn inputs() -> QuickstartInput { - QuickstartInput { - addr: Address::from_str("0x8dde5d4a8384f403f888e1419672d94c570440c9").unwrap(), - block: 9730000, - tx_block_number: 9728956, - tx_idx: 10, - slot: H256::from_low_u64_be(2), - mapping_slot: H256::from_low_u64_be(1), - } - } - - axiom_compute_tests!(QuickstartInput, inputs, 12); -} diff --git a/axiom-client-sdk/readme.md b/axiom-client-sdk/readme.md new file mode 100644 index 0000000..f3b9c21 --- /dev/null +++ b/axiom-client-sdk/readme.md @@ -0,0 +1,11 @@ +# axiom-client-sdk + +## Usage + +See [./examples/account_age.rs] for an example Axiom compute circuit. To run the `account_age` circuit: + +``` +cargo run --example account_age -- --input data/quickstart_input.json -k 12 -p +``` + +where `PROVIDER_URI` is a JSON-RPC URL, and `CMD` is `mock`, `prove`, `keygen`, or `run`. \ No newline at end of file diff --git a/axiom-client-sdk/src/api.rs b/axiom-client-sdk/src/api.rs index f65dd1f..4cc3897 100644 --- a/axiom-client-sdk/src/api.rs +++ b/axiom-client-sdk/src/api.rs @@ -9,7 +9,7 @@ use axiom_client::{ subquery::caller::SubqueryCaller, utils::{from_hi_lo, to_hi_lo}, }; -use ethers::providers::JsonRpcClient; +use ethers::providers::Http; use crate::{ subquery::{ @@ -23,17 +23,17 @@ use crate::{ Fr, }; -pub struct AxiomAPI<'a, P: JsonRpcClient> { +pub struct AxiomAPI<'a> { pub builder: &'a mut RlcCircuitBuilder, pub range: &'a RangeChip, - pub subquery_caller: Arc>>, + pub subquery_caller: Arc>>, } -impl<'a, P: JsonRpcClient> AxiomAPI<'a, P> { +impl<'a> AxiomAPI<'a> { pub fn new( builder: &'a mut RlcCircuitBuilder, range: &'a RangeChip, - subquery_caller: Arc>>, + subquery_caller: Arc>>, ) -> Self { Self { builder, @@ -42,7 +42,7 @@ impl<'a, P: JsonRpcClient> AxiomAPI<'a, P> { } } - pub fn subquery_caller(&self) -> Arc>> { + pub fn subquery_caller(&self) -> Arc>> { self.subquery_caller.clone() } @@ -64,12 +64,12 @@ impl<'a, P: JsonRpcClient> AxiomAPI<'a, P> { &mut self, block_number: AssignedValue, addr: AssignedValue, - ) -> Account

{ + ) -> Account { let ctx = self.builder.base.main(0); get_account(ctx, self.subquery_caller.clone(), block_number, addr) } - pub fn get_header(&mut self, block_number: AssignedValue) -> Header

{ + pub fn get_header(&mut self, block_number: AssignedValue) -> Header { let ctx = self.builder.base.main(0); get_header(ctx, self.subquery_caller.clone(), block_number) } @@ -79,7 +79,7 @@ impl<'a, P: JsonRpcClient> AxiomAPI<'a, P> { block_number: AssignedValue, addr: AssignedValue, mapping_slot: HiLo>, - ) -> SolidityMapping

{ + ) -> SolidityMapping { let ctx = self.builder.base.main(0); get_mapping( ctx, @@ -94,7 +94,7 @@ impl<'a, P: JsonRpcClient> AxiomAPI<'a, P> { &mut self, block_number: AssignedValue, tx_idx: AssignedValue, - ) -> Receipt

{ + ) -> Receipt { let ctx = self.builder.base.main(0); get_receipt(ctx, self.subquery_caller.clone(), block_number, tx_idx) } @@ -103,12 +103,12 @@ impl<'a, P: JsonRpcClient> AxiomAPI<'a, P> { &mut self, block_number: AssignedValue, addr: AssignedValue, - ) -> Storage

{ + ) -> Storage { let ctx = self.builder.base.main(0); get_storage(ctx, self.subquery_caller.clone(), block_number, addr) } - pub fn get_tx(&mut self, block_number: AssignedValue, tx_idx: AssignedValue) -> Tx

{ + pub fn get_tx(&mut self, block_number: AssignedValue, tx_idx: AssignedValue) -> Tx { let ctx = self.builder.base.main(0); get_tx(ctx, self.subquery_caller.clone(), block_number, tx_idx) } diff --git a/axiom-client-sdk/src/cmd.rs b/axiom-client-sdk/src/cmd.rs new file mode 100644 index 0000000..f1fa99f --- /dev/null +++ b/axiom-client-sdk/src/cmd.rs @@ -0,0 +1,112 @@ +use std::{env, fmt::Debug, fs, path::PathBuf}; + +use axiom_client::axiom_eth::halo2_base::{gates::circuit::BaseCircuitParams, AssignedValue}; +pub use clap::Parser; +use clap::Subcommand; +use ethers::providers::{Http, Provider}; + +use crate::{ + compute::{AxiomCompute, AxiomComputeFn}, + Fr, +}; + +#[derive(Clone, Copy, Debug, Subcommand)] +pub enum SnarkCmd { + /// Run the mock prover + Mock, + /// Generate new proving & verifying keys + Keygen, + /// Generate a new proof + Prove, + /// Generate an Axiom compute query + Run, +} + +impl std::fmt::Display for SnarkCmd { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + Self::Mock => write!(f, "mock"), + Self::Keygen => write!(f, "keygen"), + Self::Prove => write!(f, "prove"), + Self::Run => write!(f, "run"), + } + } +} + +#[derive(Parser, Debug)] +#[command(author, version, about, long_about = None)] +/// Command-line helper for building Axiom compute circuits +pub struct Cli { + #[command(subcommand)] + pub command: SnarkCmd, + #[arg(short = 'k', long = "degree")] + pub degree: u32, + #[arg(short = 'p', long = "provider")] + pub provider: Option, + #[arg(short, long = "input")] + pub input_path: Option, +} + +pub fn run_cli() +where + A::Input: Default + Debug, + A::Input>: Debug, +{ + let cli = Cli::parse(); + match cli.command { + SnarkCmd::Mock | SnarkCmd::Prove | SnarkCmd::Run => { + if cli.input_path.is_none() { + panic!("The `input_path` argument is required for the selected command."); + } + } + _ => {} + } + let input_path = cli.input_path.unwrap(); + let json_str = fs::read_to_string(input_path).expect("Unable to read file"); + let input: A::LogicInput = serde_json::from_str(&json_str).expect("Unable to parse JSON"); + if cli.provider.is_none() && env::var("PROVIDER_URI").is_err() { + panic!("The `provider` argument is required for the selected command. Either pass it as an argument or set the `PROVIDER_URI` environment variable."); + } + let provider_uri = cli + .provider + .unwrap_or_else(|| env::var("PROVIDER_URI").unwrap()); + let provider = Provider::::try_from(provider_uri).unwrap(); + + let params = BaseCircuitParams { + k: 12, + num_advice_per_phase: vec![4], + num_fixed: 1, + num_lookup_advice_per_phase: vec![1], + lookup_bits: Some(11), + num_instance_columns: 1, + }; + match cli.command { + SnarkCmd::Mock => { + AxiomCompute::::new() + .use_inputs(input) + .use_params(params) + .use_provider(provider) + .mock(); + } + SnarkCmd::Keygen => { + AxiomCompute::::new() + .use_params(params) + .use_provider(provider) + .keygen(); + } + SnarkCmd::Prove => { + let compute = AxiomCompute::::new() + .use_params(params) + .use_provider(provider); + let (_vk, pk) = compute.keygen(); + compute.use_inputs(input).prove(pk); + } + SnarkCmd::Run => { + let compute = AxiomCompute::::new() + .use_params(params) + .use_provider(provider); + let (_vk, pk) = compute.keygen(); + compute.use_inputs(input).run(pk); + } + } +} diff --git a/axiom-client-sdk/src/compute.rs b/axiom-client-sdk/src/compute.rs index 1bd6bf9..01f55ee 100644 --- a/axiom-client-sdk/src/compute.rs +++ b/axiom-client-sdk/src/compute.rs @@ -22,27 +22,28 @@ use axiom_client::{ types::{AxiomCircuitParams, AxiomV2CircuitOutput}, utils::to_hi_lo, }; -use ethers::providers::{Http, JsonRpcClient, Provider}; +use ethers::providers::{Http, Provider}; +use serde::{de::DeserializeOwned, Serialize}; use crate::{api::AxiomAPI, Fr}; pub trait AxiomComputeInput: Clone + Default + Debug { - type LogicInput: Clone + Debug + Into>; + type LogicInput: Clone + Debug + Serialize + DeserializeOwned + Into>; type Input: Clone + InputFlatten; - type ProviderType: JsonRpcClient + Clone = Http; + // type ProviderType: JsonRpcClient + Clone = Http; } pub trait AxiomComputeFn: AxiomComputeInput { - type Provider: JsonRpcClient + Clone = Self::ProviderType; + // type Provider: JsonRpcClient + Clone = Self::ProviderType; fn compute( - api: &mut AxiomAPI, + api: &mut AxiomAPI, assigned_inputs: Self::Input>, ) -> Vec; } #[derive(Debug, Clone)] pub struct AxiomCompute { - provider: Option>, + provider: Option>, params: Option, input: Option, } @@ -57,7 +58,7 @@ impl Default for AxiomCompute { } } -impl AxiomCircuitScaffold for AxiomCompute +impl AxiomCircuitScaffold for AxiomCompute where A::Input: Default + Debug, A::Input>: Debug, @@ -68,7 +69,7 @@ where fn virtual_assign_phase0( builder: &mut RlcCircuitBuilder, range: &RangeChip, - subquery_caller: Arc>>, + subquery_caller: Arc>>, callback: &mut Vec>>, assigned_inputs: Self::InputWitness, ) { @@ -94,7 +95,7 @@ where Self::default() } - pub fn set_provider(&mut self, provider: Provider) { + pub fn set_provider(&mut self, provider: Provider) { self.provider = Some(provider); } @@ -106,7 +107,7 @@ where self.input = Some(input); } - pub fn use_provider(mut self, provider: Provider) -> Self { + pub fn use_provider(mut self, provider: Provider) -> Self { self.set_provider(provider); self } @@ -137,14 +138,14 @@ where let provider = self.provider.clone().unwrap(); let params = self.params.clone().unwrap(); let converted_input = self.input.clone().map(|input| input.into()); - mock::(provider, AxiomCircuitParams::Base(params), converted_input); + mock::(provider, AxiomCircuitParams::Base(params), converted_input); } pub fn keygen(&self) -> (VerifyingKey, ProvingKey) { self.check_provider_and_params_set(); let provider = self.provider.clone().unwrap(); let params = self.params.clone().unwrap(); - keygen::(provider, AxiomCircuitParams::Base(params), None) + keygen::(provider, AxiomCircuitParams::Base(params), None) } pub fn prove(&self, pk: ProvingKey) -> Snark { @@ -152,7 +153,7 @@ where let provider = self.provider.clone().unwrap(); let params = self.params.clone().unwrap(); let converted_input = self.input.clone().map(|input| input.into()); - prove::( + prove::( provider, AxiomCircuitParams::Base(params), converted_input, @@ -165,7 +166,7 @@ where let provider = self.provider.clone().unwrap(); let params = self.params.clone().unwrap(); let converted_input = self.input.clone().map(|input| input.into()); - run::( + run::( provider, AxiomCircuitParams::Base(params), converted_input, @@ -173,7 +174,7 @@ where ) } - pub fn circuit(&self) -> AxiomCircuit { + pub fn circuit(&self) -> AxiomCircuit { self.check_provider_and_params_set(); let provider = self.provider.clone().unwrap(); let params = self.params.clone().unwrap(); diff --git a/axiom-client-sdk/src/examples/mod.rs b/axiom-client-sdk/src/examples/mod.rs deleted file mode 100644 index 581cbb2..0000000 --- a/axiom-client-sdk/src/examples/mod.rs +++ /dev/null @@ -1,2 +0,0 @@ -mod account_age; -mod quickstart; diff --git a/axiom-client-sdk/src/lib.rs b/axiom-client-sdk/src/lib.rs index eb86589..09833be 100644 --- a/axiom-client-sdk/src/lib.rs +++ b/axiom-client-sdk/src/lib.rs @@ -1,10 +1,19 @@ #![allow(incomplete_features)] #![feature(associated_type_defaults)] -pub mod api; -pub mod compute; -pub mod examples; +mod api; -pub use axiom_client::axiom_eth::halo2curves::bn256::Fr; -pub mod subquery; +pub use axiom_client::{axiom_codec::HiLo, axiom_eth::halo2curves::bn256::Fr}; + +pub(crate) mod utils; +pub use axiom_client::{self, axiom_eth::halo2_base}; +pub use axiom_client_derive::AxiomComputeInput; -pub mod utils; +pub mod axiom { + pub use crate::{ + api::AxiomAPI, + compute::{AxiomCompute, AxiomComputeFn, AxiomResult}, + }; +} +pub mod cmd; +pub mod compute; +pub mod subquery; diff --git a/axiom-client-sdk/src/subquery/account.rs b/axiom-client-sdk/src/subquery/account.rs index 41967ff..ad56739 100644 --- a/axiom-client-sdk/src/subquery/account.rs +++ b/axiom-client-sdk/src/subquery/account.rs @@ -3,25 +3,25 @@ use std::sync::{Arc, Mutex}; use axiom_client::{ axiom_codec::HiLo, axiom_eth::halo2_base::{AssignedValue, Context}, - subquery::{account::AccountField, caller::SubqueryCaller, types::AssignedAccountSubquery}, + subquery::{caller::SubqueryCaller, types::AssignedAccountSubquery, AccountField}, }; -use ethers::providers::JsonRpcClient; +use ethers::providers::Http; use crate::Fr; -pub struct Account<'a, P: JsonRpcClient> { +pub struct Account<'a> { pub block_number: AssignedValue, pub addr: AssignedValue, ctx: &'a mut Context, - caller: Arc>>, + caller: Arc>>, } -pub fn get_account( +pub fn get_account( ctx: &mut Context, - caller: Arc>>, + caller: Arc>>, block_number: AssignedValue, addr: AssignedValue, -) -> Account

{ +) -> Account { Account { block_number, addr, @@ -30,7 +30,7 @@ pub fn get_account( } } -impl<'a, P: JsonRpcClient> Account<'a, P> { +impl<'a> Account<'a> { pub fn call(self, field: AccountField) -> HiLo> { let field_constant = self.ctx.load_constant(Fr::from(field)); let mut subquery_caller = self.caller.lock().unwrap(); diff --git a/axiom-client-sdk/src/subquery/header.rs b/axiom-client-sdk/src/subquery/header.rs index e0d15d4..89ceaba 100644 --- a/axiom-client-sdk/src/subquery/header.rs +++ b/axiom-client-sdk/src/subquery/header.rs @@ -3,23 +3,23 @@ use std::sync::{Arc, Mutex}; use axiom_client::{ axiom_codec::{special_values::HEADER_LOGS_BLOOM_FIELD_IDX_OFFSET, HiLo}, axiom_eth::halo2_base::{AssignedValue, Context}, - subquery::{caller::SubqueryCaller, header::HeaderField, types::AssignedHeaderSubquery}, + subquery::{caller::SubqueryCaller, types::AssignedHeaderSubquery, HeaderField}, }; -use ethers::providers::JsonRpcClient; +use ethers::providers::Http; use crate::Fr; -pub struct Header<'a, P: JsonRpcClient> { +pub struct Header<'a> { pub block_number: AssignedValue, ctx: &'a mut Context, - caller: Arc>>, + caller: Arc>>, } -pub fn get_header( +pub fn get_header( ctx: &mut Context, - caller: Arc>>, + caller: Arc>>, block_number: AssignedValue, -) -> Header

{ +) -> Header { Header { block_number, ctx, @@ -27,7 +27,7 @@ pub fn get_header( } } -impl<'a, P: JsonRpcClient> Header<'a, P> { +impl<'a> Header<'a> { pub fn call(self, field: HeaderField) -> HiLo> { let field_constant = self.ctx.load_constant(Fr::from(field)); let mut subquery_caller = self.caller.lock().unwrap(); diff --git a/axiom-client-sdk/src/subquery/mapping.rs b/axiom-client-sdk/src/subquery/mapping.rs index b648f28..5368291 100644 --- a/axiom-client-sdk/src/subquery/mapping.rs +++ b/axiom-client-sdk/src/subquery/mapping.rs @@ -5,25 +5,25 @@ use axiom_client::{ axiom_eth::halo2_base::{AssignedValue, Context}, subquery::{caller::SubqueryCaller, types::AssignedSolidityNestedMappingSubquery}, }; -use ethers::providers::JsonRpcClient; +use ethers::providers::Http; use crate::Fr; -pub struct SolidityMapping<'a, P: JsonRpcClient> { +pub struct SolidityMapping<'a> { pub block_number: AssignedValue, pub addr: AssignedValue, pub mapping_slot: HiLo>, ctx: &'a mut Context, - caller: Arc>>, + caller: Arc>>, } -pub fn get_mapping( +pub fn get_mapping( ctx: &mut Context, - caller: Arc>>, + caller: Arc>>, block_number: AssignedValue, addr: AssignedValue, mapping_slot: HiLo>, -) -> SolidityMapping

{ +) -> SolidityMapping { SolidityMapping { block_number, addr, @@ -33,7 +33,7 @@ pub fn get_mapping( } } -impl<'a, P: JsonRpcClient> SolidityMapping<'a, P> { +impl<'a> SolidityMapping<'a> { pub fn nested(self, keys: Vec>>) -> HiLo> { if keys.is_empty() || keys.len() > MAX_SOLIDITY_MAPPING_KEYS { panic!( diff --git a/axiom-client-sdk/src/subquery/mod.rs b/axiom-client-sdk/src/subquery/mod.rs index a4f71a8..bd2d295 100644 --- a/axiom-client-sdk/src/subquery/mod.rs +++ b/axiom-client-sdk/src/subquery/mod.rs @@ -1,63 +1,8 @@ -// use axiom_client::{ -// axiom_codec::constants::MAX_SOLIDITY_MAPPING_KEYS, -// axiom_eth::{halo2_base::AssignedValue, utils::hilo::HiLo}, -// subquery::{account::AccountField, header::HeaderField}, -// }; - -// use crate::Fr; - -// pub trait SubqueryCall { -// fn call(&self) -> HiLo>; -// } - -// #[derive(Clone)] -// pub struct HeaderSubquery { -// pub block_number: AssignedValue, -// pub field_idx: HeaderField, -// } - -// #[derive(Clone)] -// pub struct AccountSubquery { -// pub block_number: AssignedValue, -// pub addr: AssignedValue, -// pub field_idx: AccountField, -// } - -// #[derive(Clone)] -// pub struct StorageSubquery { -// pub block_number: AssignedValue, -// pub addr: AssignedValue, -// pub slot: HiLo>, -// } - -// #[derive(Clone)] -// pub struct TxSubquery { -// pub block_number: AssignedValue, -// pub tx_idx: AssignedValue, -// pub field_or_calldata_idx: AssignedValue, -// } - -// #[derive(Clone)] -// pub struct ReceiptSubquery { -// pub block_number: AssignedValue, -// pub tx_idx: AssignedValue, -// pub field_or_log_idx: AssignedValue, -// pub topic_or_data_or_address_idx: AssignedValue, -// pub event_schema: HiLo>, -// } - -// #[derive(Clone)] -// pub struct SolidityNestedMappingSubquery { -// pub block_number: AssignedValue, -// pub addr: AssignedValue, -// pub mapping_slot: HiLo>, -// pub mapping_depth: AssignedValue, -// pub keys: [HiLo>; MAX_SOLIDITY_MAPPING_KEYS], -// } - pub mod account; pub mod header; pub mod mapping; pub mod receipt; pub mod storage; pub mod tx; + +pub use axiom_client::subquery::{AccountField, HeaderField, ReceiptField, TxField}; diff --git a/axiom-client-sdk/src/subquery/receipt.rs b/axiom-client-sdk/src/subquery/receipt.rs index 2e99155..628ec15 100644 --- a/axiom-client-sdk/src/subquery/receipt.rs +++ b/axiom-client-sdk/src/subquery/receipt.rs @@ -15,33 +15,33 @@ use axiom_client::{ }, utils::encode_h256_to_hilo, }, - subquery::{caller::SubqueryCaller, receipt::ReceiptField, types::AssignedReceiptSubquery}, + subquery::{caller::SubqueryCaller, types::AssignedReceiptSubquery, ReceiptField}, }; -use ethers::{providers::JsonRpcClient, types::H256}; +use ethers::{providers::Http, types::H256}; use crate::Fr; -pub struct Receipt<'a, P: JsonRpcClient> { +pub struct Receipt<'a> { pub block_number: AssignedValue, pub tx_idx: AssignedValue, ctx: &'a mut Context, - caller: Arc>>, + caller: Arc>>, } -pub struct Log<'a, P: JsonRpcClient> { +pub struct Log<'a> { pub block_number: AssignedValue, pub tx_idx: AssignedValue, pub field_or_log_idx: AssignedValue, ctx: &'a mut Context, - caller: Arc>>, + caller: Arc>>, } -pub fn get_receipt( +pub fn get_receipt( ctx: &mut Context, - caller: Arc>>, + caller: Arc>>, block_number: AssignedValue, tx_idx: AssignedValue, -) -> Receipt

{ +) -> Receipt { Receipt { block_number, tx_idx, @@ -50,7 +50,7 @@ pub fn get_receipt( } } -impl<'a, P: JsonRpcClient> Receipt<'a, P> { +impl<'a> Receipt<'a> { pub fn call(self, field: ReceiptField) -> HiLo> { let field_constant = self.ctx.load_constant(Fr::from(field)); let mut subquery_caller = self.caller.lock().unwrap(); @@ -67,7 +67,7 @@ impl<'a, P: JsonRpcClient> Receipt<'a, P> { subquery_caller.call(self.ctx, subquery) } - pub fn log(self, log_idx: AssignedValue) -> Log<'a, P> { + pub fn log(self, log_idx: AssignedValue) -> Log<'a> { let log_offset = self .ctx .load_constant(Fr::from(RECEIPT_LOG_IDX_OFFSET as u64)); @@ -103,7 +103,7 @@ impl<'a, P: JsonRpcClient> Receipt<'a, P> { } } -impl<'a, P: JsonRpcClient> Log<'a, P> { +impl<'a> Log<'a> { pub fn topic( self, topic_idx: AssignedValue, diff --git a/axiom-client-sdk/src/subquery/storage.rs b/axiom-client-sdk/src/subquery/storage.rs index 32fe8b4..9646d0b 100644 --- a/axiom-client-sdk/src/subquery/storage.rs +++ b/axiom-client-sdk/src/subquery/storage.rs @@ -5,23 +5,23 @@ use axiom_client::{ axiom_eth::halo2_base::{AssignedValue, Context}, subquery::{caller::SubqueryCaller, types::AssignedStorageSubquery}, }; -use ethers::providers::JsonRpcClient; +use ethers::providers::Http; use crate::Fr; -pub struct Storage<'a, P: JsonRpcClient> { +pub struct Storage<'a> { pub block_number: AssignedValue, pub addr: AssignedValue, ctx: &'a mut Context, - caller: Arc>>, + caller: Arc>>, } -pub fn get_storage( +pub fn get_storage( ctx: &mut Context, - caller: Arc>>, + caller: Arc>>, block_number: AssignedValue, addr: AssignedValue, -) -> Storage

{ +) -> Storage { Storage { block_number, addr, @@ -30,7 +30,7 @@ pub fn get_storage( } } -impl<'a, P: JsonRpcClient> Storage<'a, P> { +impl<'a> Storage<'a> { pub fn slot(self, slot: HiLo>) -> HiLo> { let mut subquery_caller = self.caller.lock().unwrap(); let subquery = AssignedStorageSubquery { diff --git a/axiom-client-sdk/src/subquery/tx.rs b/axiom-client-sdk/src/subquery/tx.rs index 31a0676..73c581b 100644 --- a/axiom-client-sdk/src/subquery/tx.rs +++ b/axiom-client-sdk/src/subquery/tx.rs @@ -9,25 +9,25 @@ use axiom_client::{ gates::{GateChip, GateInstructions}, AssignedValue, Context, }, - subquery::{caller::SubqueryCaller, tx::TxField, types::AssignedTxSubquery}, + subquery::{caller::SubqueryCaller, types::AssignedTxSubquery, TxField}, }; -use ethers::providers::JsonRpcClient; +use ethers::providers::Http; use crate::Fr; -pub struct Tx<'a, P: JsonRpcClient> { +pub struct Tx<'a> { pub block_number: AssignedValue, pub tx_idx: AssignedValue, ctx: &'a mut Context, - caller: Arc>>, + caller: Arc>>, } -pub fn get_tx( +pub fn get_tx( ctx: &mut Context, - caller: Arc>>, + caller: Arc>>, block_number: AssignedValue, tx_idx: AssignedValue, -) -> Tx

{ +) -> Tx { Tx { block_number, tx_idx, @@ -36,7 +36,7 @@ pub fn get_tx( } } -impl<'a, P: JsonRpcClient> Tx<'a, P> { +impl<'a> Tx<'a> { pub fn call(self, field: TxField) -> HiLo> { let field_constant = self.ctx.load_constant(Fr::from(field)); let mut subquery_caller = self.caller.lock().unwrap(); diff --git a/axiom-client-sdk/src/utils/mod.rs b/axiom-client-sdk/src/utils/mod.rs index f6e8aa6..3277384 100644 --- a/axiom-client-sdk/src/utils/mod.rs +++ b/axiom-client-sdk/src/utils/mod.rs @@ -1,11 +1,3 @@ -use std::env; - -use ethers::providers::{Http, Provider}; - -pub fn provider() -> Provider { - Provider::::try_from(env::var("PROVIDER_URI").expect("PROVIDER_URI not set")).unwrap() -} - #[macro_export] macro_rules! axiom_compute_tests { ($input_struct:ident, $inputs:ident, $k: expr) => { @@ -20,6 +12,15 @@ macro_rules! axiom_compute_tests { } } + use std::env; + + use ethers::providers::{Http, Provider}; + + pub fn provider() -> Provider { + Provider::::try_from(env::var("PROVIDER_URI").expect("PROVIDER_URI not set")) + .unwrap() + } + #[test] fn mock() { $crate::compute::AxiomCompute::<$input_struct>::new() diff --git a/axiom-client/src/subquery/mod.rs b/axiom-client/src/subquery/mod.rs index 3233cec..dc10aae 100644 --- a/axiom-client/src/subquery/mod.rs +++ b/axiom-client/src/subquery/mod.rs @@ -1,9 +1,14 @@ -pub mod account; -pub mod header; -pub mod mapping; -pub mod receipt; -pub mod storage; -pub mod tx; +pub(crate) mod account; +pub(crate) mod header; +pub(crate) mod mapping; +pub(crate) mod receipt; +pub(crate) mod storage; +pub(crate) mod tx; + +pub use account::AccountField; +pub use header::HeaderField; +pub use receipt::ReceiptField; +pub use tx::TxField; pub mod caller; pub mod keccak;