Skip to content
This repository has been archived by the owner on Apr 9, 2024. It is now read-only.

Commit

Permalink
feat(acir)!: make PublicInputs use a BTreeSet rather than Vec (#99)
Browse files Browse the repository at this point in the history
  • Loading branch information
TomAFrench authored Feb 17, 2023
1 parent 2427a27 commit 53666b7
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions acir/src/circuit/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use serde::{Deserialize, Serialize};

use flate2::bufread::{DeflateDecoder, DeflateEncoder};
use flate2::Compression;
use std::collections::BTreeSet;
use std::io::prelude::*;

const VERSION_NUMBER: u32 = 0;
Expand Down Expand Up @@ -80,10 +81,10 @@ impl Circuit {
let current_witness_index = read_u32(&mut reader)?;

let num_public_inputs = read_u32(&mut reader)?;
let mut public_inputs = PublicInputs(Vec::with_capacity(num_public_inputs as usize));
let mut public_inputs = PublicInputs(BTreeSet::new());
for _ in 0..num_public_inputs {
let public_input_index = Witness(read_u32(&mut reader)?);
public_inputs.0.push(public_input_index)
public_inputs.0.insert(public_input_index);
}

let num_opcodes = read_u32(&mut reader)?;
Expand Down Expand Up @@ -127,7 +128,7 @@ impl std::fmt::Debug for Circuit {
}

#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, Default)]
pub struct PublicInputs(pub Vec<Witness>);
pub struct PublicInputs(pub BTreeSet<Witness>);

impl PublicInputs {
/// Returns the witness index of each public input
Expand All @@ -145,6 +146,8 @@ impl PublicInputs {

#[cfg(test)]
mod test {
use std::collections::BTreeSet;

use super::{
opcodes::{BlackBoxFuncCall, FunctionInput},
Circuit, Opcode, PublicInputs,
Expand Down Expand Up @@ -184,7 +187,7 @@ mod test {
let circuit = Circuit {
current_witness_index: 5,
opcodes: vec![and_opcode(), range_opcode()],
public_inputs: PublicInputs(vec![Witness(2), Witness(12)]),
public_inputs: PublicInputs(BTreeSet::from([Witness(2), Witness(12)])),
};

fn read_write(circuit: Circuit) -> (Circuit, Circuit) {
Expand All @@ -211,7 +214,7 @@ mod test {
range_opcode(),
and_opcode(),
],
public_inputs: PublicInputs(vec![Witness(2)]),
public_inputs: PublicInputs(BTreeSet::from([Witness(2)])),
};

let json = serde_json::to_string_pretty(&circuit).unwrap();
Expand All @@ -233,7 +236,7 @@ mod test {
range_opcode(),
and_opcode(),
],
public_inputs: PublicInputs(vec![Witness(2)]),
public_inputs: PublicInputs(BTreeSet::from([Witness(2)])),
};

let bytes = circuit.to_bytes();
Expand Down

0 comments on commit 53666b7

Please sign in to comment.