Skip to content

Commit

Permalink
refactor: only GraphData can be on-chain (#342)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-camuto authored Jul 7, 2023
1 parent 4ffbd68 commit 6dd9aac
Show file tree
Hide file tree
Showing 13 changed files with 478 additions and 616 deletions.
2 changes: 1 addition & 1 deletion benches/poseidon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ fn runposeidon(c: &mut Criterion) {
PoseidonChip::<PoseidonSpec, POSEIDON_WIDTH, POSEIDON_RATE, L>::run(message.to_vec())
.unwrap();

let mut image = Tensor::from(message.into_iter().map(|x| Value::known(x)));
let mut image = Tensor::from(message.into_iter().map(Value::known));
image.reshape(&[1, *size]);

let circuit = MyCircuit {
Expand Down
2 changes: 1 addition & 1 deletion examples/onnx/1l_gelu_noappx/input.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"input_data":[[0.61017877,0.21496391,0.8960367]],"input_shapes":[[3]],"output_data":[[0.44274902,0.12817383,0.73349]]}
{"input_data":[[0.61017877,0.21496391,0.8960367]],"input_shapes":[[3]],"output_data":[[0.44140625,0.12890625,0.734375]]}
2 changes: 1 addition & 1 deletion examples/onnx/1l_var/input.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"input_data":[[0.048659664,0.040321846,0.092751384,0.058180947,0.019983828,0.096692465,0.07317094,0.06064367,0.052526843]],"output_data":[[0.00010251999,0.00026655197,0.00034856796]]}
{"input_data":[[0.048659664,0.040321846,0.092751384,0.058180947,0.019983828,0.096692465,0.07317094,0.06064367,0.052526843]],"output_data":[[0.0,0.0,0.0]]}
2 changes: 1 addition & 1 deletion src/circuit/ops/hybrid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ impl<F: PrimeField + TensorType + PartialOrd> Op<F> for HybridOp {
HybridOp::Softmax { scales } => {
tensor::ops::nonlinearities::multi_dim_softmax(&x, scales.0, scales.1)
}
HybridOp::RangeCheck(..) => (x.clone(), vec![]),
HybridOp::RangeCheck(..) => (x, vec![]),
};

// convert back to felt
Expand Down
24 changes: 12 additions & 12 deletions src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -390,10 +390,10 @@ pub enum Commands {
settings_path: Option<PathBuf>,
},
#[cfg(not(target_arch = "wasm32"))]
SetupTestEVMWitness {
/// The path to the .json witness file, which should include both the network input (possibly private) and the network output (public input to the proof)
#[arg(short = 'W', long)]
witness: PathBuf,
SetupTestEVMData {
/// The path to the .json data file, which should include both the network input (possibly private) and the network output (public input to the proof)
#[arg(short = 'D', long)]
data: PathBuf,
/// The path to the .onnx model file
#[arg(short = 'M', long)]
model: PathBuf,
Expand All @@ -403,8 +403,8 @@ pub enum Commands {
/// For testing purposes only. The optional path to the .json data file that will be generated that contains the OnChain data storage information
/// derived from the file information in the data .json file.
/// Should include both the network input (possibly private) and the network output (public input to the proof)
#[arg(short = 'D', long)]
test_witness: PathBuf,
#[arg(short = 'T', long)]
test_data: PathBuf,
/// RPC URL for an Ethereum node, if None will use Anvil but WON'T persist state
#[arg(short = 'U', long)]
rpc_url: Option<String>,
Expand Down Expand Up @@ -512,13 +512,13 @@ pub enum Commands {
/// If not set will just use the default unoptimized SOLC configuration.
#[arg(long)]
optimizer_runs: Option<usize>,
/// The path to the .json witness file, which should
/// The path to the .json data file, which should
/// contain the necessary calldata and accoount addresses
/// needed need to read from all the on-chain
/// view functions that return the data that the network
/// ingests as inputs.
#[arg(short = 'W', long)]
witness: PathBuf,
#[arg(short = 'D', long)]
data: PathBuf,
// todo, optionally allow supplying proving key
},

Expand Down Expand Up @@ -595,9 +595,9 @@ pub enum Commands {
#[cfg(not(target_arch = "wasm32"))]
#[command(name = "deploy-evm-da-verifier", arg_required_else_help = true)]
DeployEvmDataAttestationVerifier {
/// The path to the .json witness file, which should include both the network input (possibly private) and the network output (public input to the proof)
#[arg(short = 'W', long)]
witness: PathBuf,
/// The path to the .json data file, which should include both the network input (possibly private) and the network output (public input to the proof)
#[arg(short = 'D', long)]
data: PathBuf,
/// The path to load circuit params from
#[arg(long)]
settings_path: PathBuf,
Expand Down
13 changes: 7 additions & 6 deletions src/eth.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::graph::input::{CallsToAccount, GraphWitness, WitnessSource};
use crate::graph::input::{CallsToAccount, GraphData};
use crate::graph::DataSource;
#[cfg(not(target_arch = "wasm32"))]
use crate::graph::GraphSettings;
use crate::pfsys::evm::{DeploymentCode, EvmVerificationError};
Expand Down Expand Up @@ -145,13 +146,13 @@ pub async fn deploy_verifier_via_solidity(
///
pub async fn deploy_da_verifier_via_solidity(
settings_path: PathBuf,
witness: PathBuf,
input: PathBuf,
sol_code_path: PathBuf,
rpc_url: Option<&str>,
) -> Result<ethers::types::Address, Box<dyn Error>> {
let (_, client) = setup_eth_backend(rpc_url).await?;

let witness = GraphWitness::from_path(witness)?;
let input = GraphData::from_path(input)?;

let settings = GraphSettings::load(&settings_path)?;

Expand All @@ -164,12 +165,12 @@ pub async fn deploy_da_verifier_via_solidity(
let mut instance_idx = 0;
let mut contract_instance_offset = 0;

if let WitnessSource::OnChain(source) = witness.input_data {
if let DataSource::OnChain(source) = input.input_data {
for call in source.calls {
calls_to_accounts.push(call);
instance_idx += 1;
}
} else if let WitnessSource::File(source) = witness.input_data {
} else if let DataSource::File(source) = input.input_data {
if settings.run_args.input_visibility.is_public() {
instance_idx += source.len();
for s in source {
Expand All @@ -178,7 +179,7 @@ pub async fn deploy_da_verifier_via_solidity(
}
}

if let WitnessSource::OnChain(source) = witness.output_data {
if let Some(DataSource::OnChain(source)) = input.output_data {
let output_scales = settings.model_output_scales;
for call in source.calls {
calls_to_accounts.push(call);
Expand Down
Loading

0 comments on commit 6dd9aac

Please sign in to comment.