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

Returned values from main are set to public (Successor) #731

Merged
merged 43 commits into from
Feb 3, 2023
Merged
Show file tree
Hide file tree
Changes from 37 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
acc99cd
acir - add public_outputs field to acir structure
kevaundray Jan 12, 2023
5e3a9c8
monomorphisation:
kevaundray Jan 12, 2023
8e53b2f
evaluator - acir now has a `public_outputs` field and so we add one i…
kevaundray Jan 12, 2023
d5c5a0b
ssa - Add SetPub operation and opcode
kevaundray Jan 12, 2023
8f41456
ssa - codegen for setpub
kevaundray Jan 12, 2023
96141f7
ssa - setpub acir_gen
kevaundray Jan 12, 2023
dfaf279
Merge branch 'master' into kw/acvm3.0
kevaundray Jan 12, 2023
2211a93
Overwrite merge commit to revert change to `get_max_value`
kevaundray Jan 12, 2023
387b28e
ssa - acir_gen
kevaundray Jan 12, 2023
1a8fca5
revert: remove public_outputs field
kevaundray Jan 12, 2023
8b06277
remove the return type from the abi when converting abi parameters to…
kevaundray Jan 12, 2023
0adbf27
clippy
kevaundray Jan 12, 2023
06f792b
Merge branch 'master' into kw/fix-return-type
kevaundray Jan 12, 2023
fbf4b26
ssa - acir_gen : create witnesses for constants
kevaundray Jan 13, 2023
aff8d33
ssa - acir_gen : deref node_id when we have an array
kevaundray Jan 13, 2023
1fc37de
nargo - remove duplicates
kevaundray Jan 14, 2023
323f90d
Merge branch 'master' into kw/fix-return-type
kevaundray Jan 14, 2023
a99e485
noirc_abi - skip `return` when proving
kevaundray Jan 14, 2023
d2a8a7d
nargo/tests - remove "return" field from toml files
kevaundray Jan 14, 2023
a0a543d
cargo fmt imports
kevaundray Jan 14, 2023
d5bfaf8
remove SetPub Expression
kevaundray Jan 16, 2023
d670b8d
ssa - remove SetPub operation
kevaundray Jan 16, 2023
4d6f86c
evaluator - add a method which tells you whether a witness index corr…
kevaundray Jan 16, 2023
e4a9788
- use Operation::Return to set the values returned from main as public.
kevaundray Jan 16, 2023
05564f2
fix clippy
kevaundray Jan 16, 2023
bd9e909
ssa-integer: do not skip the return operation during integer overflow
kevaundray Jan 16, 2023
7ff696f
Merge branch 'master' into kw/fix-return-type
kevaundray Jan 17, 2023
fb7c6a3
ssa-acir_gen : replace todo with Err Result variant
kevaundray Jan 17, 2023
6316c38
Merge branch 'master' into kw/fix-return-type
kevaundray Jan 17, 2023
ffdc2d2
Merge branch 'master' into kw/fix-return-type
kevaundray Jan 17, 2023
21c0b2f
remove TODOs
kevaundray Jan 17, 2023
1c68795
Merge remote-tracking branch 'origin/master' into kw/revert-21c0b-fix…
kevaundray Feb 1, 2023
8cd6874
remove returns
kevaundray Feb 1, 2023
80cefda
delete unused `to_bytes`
kevaundray Feb 1, 2023
deae405
remove `return` from `to_le_bytes` example
kevaundray Feb 1, 2023
78fc162
reduce diff
kevaundray Feb 1, 2023
4a72ccf
move dedup methods to mod.rs file
kevaundray Feb 1, 2023
c77853d
remove TODO on return type keyword
kevaundray Feb 2, 2023
c0146b6
move deduplication code into `compile_circuit_and_witness`
kevaundray Feb 2, 2023
ba2e28b
update `num_witnesses_abi_len` parameter
kevaundray Feb 2, 2023
bb95372
fix example:
kevaundray Feb 2, 2023
5c24c36
use HashMap and check for previous insertion value
kevaundray Feb 2, 2023
5ffaad6
fix clippy
kevaundray Feb 2, 2023
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
34 changes: 33 additions & 1 deletion crates/nargo/src/cli/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use acvm::{acir::circuit::PublicInputs, FieldElement};
pub use check_cmd::check_from_path;
use clap::{App, AppSettings, Arg};
use const_format::formatcp;
Expand All @@ -9,7 +10,7 @@ use noirc_abi::{
use noirc_driver::Driver;
use noirc_frontend::graph::{CrateName, CrateType};
use std::{
collections::BTreeMap,
collections::{BTreeMap, HashSet},
fs::File,
io::Write,
path::{Path, PathBuf},
Expand Down Expand Up @@ -206,6 +207,37 @@ fn path_to_stdlib() -> PathBuf {
dirs::config_dir().unwrap().join("noir-lang").join("std/src")
}

// Removes duplicates from the list of public input witnesses
fn dedup_public_input_indices(indices: PublicInputs) -> PublicInputs {
let duplicates_removed: HashSet<_> = indices.0.into_iter().collect();
PublicInputs(duplicates_removed.into_iter().collect())
kevaundray marked this conversation as resolved.
Show resolved Hide resolved
}

// Removes duplicates from the list of public input witnesses and the
// associated list of duplicate values.
pub(crate) fn dedup_public_input_indices_values(
indices: PublicInputs,
values: Vec<FieldElement>,
) -> (PublicInputs, Vec<FieldElement>) {
// Assume that the public input index lists and the values contain duplicates
assert_eq!(indices.0.len(), values.len());

let mut public_inputs_without_duplicates = Vec::new();
let mut already_seen_public_indices = HashSet::new();

for (index, value) in indices.0.iter().zip(values) {
if !already_seen_public_indices.contains(&index) {
kevaundray marked this conversation as resolved.
Show resolved Hide resolved
already_seen_public_indices.insert(index);
public_inputs_without_duplicates.push(value)
}
}

(
PublicInputs(already_seen_public_indices.into_iter().cloned().collect()),
kevaundray marked this conversation as resolved.
Show resolved Hide resolved
public_inputs_without_duplicates,
)
}

// FIXME: I not sure that this is the right place for this tests.
#[cfg(test)]
mod tests {
Expand Down
17 changes: 13 additions & 4 deletions crates/nargo/src/cli/prove_cmd.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
use std::{collections::BTreeMap, path::PathBuf};

use acvm::acir::native_types::Witness;
use acvm::FieldElement;
use acvm::PartialWitnessGenerator;
use acvm::ProofSystemCompiler;
use clap::ArgMatches;
use noirc_abi::errors::AbiError;
use noirc_abi::input_parser::{Format, InputValue};
use std::path::Path;
use std::{
collections::BTreeMap,
path::{Path, PathBuf},
};

use super::{create_named_dir, read_inputs_from_file, write_inputs_to_file, write_to_file};
use crate::cli::dedup_public_input_indices;
use crate::{
constants::{PROOFS_DIR, PROOF_EXT, PROVER_INPUT_FILE, VERIFIER_INPUT_FILE},
errors::CliError,
Expand Down Expand Up @@ -46,9 +48,16 @@ pub fn prove_with_path<P: AsRef<Path>>(
show_ssa: bool,
allow_warnings: bool,
) -> Result<Option<PathBuf>, CliError> {
let (compiled_program, solved_witness) =
let (mut compiled_program, solved_witness) =
compile_circuit_and_witness(program_dir, show_ssa, allow_warnings)?;

// Since the public outputs are added into the public inputs list
// There can be duplicates. We keep the duplicates for when one is
// encoding the return values into the Verifier.toml
// However, for creating a proof, we remove these duplicates.
compiled_program.circuit.public_inputs =
dedup_public_input_indices(compiled_program.circuit.public_inputs);
kevaundray marked this conversation as resolved.
Show resolved Hide resolved

let backend = crate::backends::ConcreteBackend;
let proof = backend.prove_with_meta(compiled_program.circuit, solved_witness);

Expand Down
14 changes: 11 additions & 3 deletions crates/nargo/src/cli/verify_cmd.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use super::{compile_cmd::compile_circuit, read_inputs_from_file};
use super::{
compile_cmd::compile_circuit, dedup_public_input_indices_values, read_inputs_from_file,
};
use crate::{
constants::{PROOFS_DIR, PROOF_EXT, VERIFIER_INPUT_FILE},
errors::CliError,
Expand Down Expand Up @@ -59,7 +61,7 @@ pub fn verify_with_path<P: AsRef<Path>>(
}

fn verify_proof(
compiled_program: CompiledProgram,
mut compiled_program: CompiledProgram,
public_inputs: BTreeMap<String, InputValue>,
proof: Vec<u8>,
) -> Result<bool, CliError> {
Expand All @@ -71,8 +73,14 @@ fn verify_proof(
_ => CliError::from(error),
})?;

// Similarly to when proving -- we must remove the duplicate public witnesses which
// can be present because a public input can also be added as a public output.
let (dedup_public_indices, dedup_public_values) =
dedup_public_input_indices_values(compiled_program.circuit.public_inputs, public_inputs);
compiled_program.circuit.public_inputs = dedup_public_indices;

let backend = crate::backends::ConcreteBackend;
let valid_proof = backend.verify_from_cs(&proof, public_inputs, compiled_program.circuit);
let valid_proof = backend.verify_from_cs(&proof, dedup_public_values, compiled_program.circuit);

Ok(valid_proof)
}
Expand Down
1 change: 0 additions & 1 deletion crates/nargo/tests/test_data/hash_to_field/Prover.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
input = "1"
return = "0x25cebc29ded2fa515a937e2b5f674e3026c012e5b57f8a48d7dce6b7d274f9d9"
Original file line number Diff line number Diff line change
@@ -1 +1 @@
return = "5"

1 change: 0 additions & 1 deletion crates/nargo/tests/test_data/main_return/Prover.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
return = ""
x = "8"
Loading