Skip to content

Commit

Permalink
ACIR
Browse files Browse the repository at this point in the history
- Add helper methods, for converting between ACIR and R1CS
  • Loading branch information
kevaundray committed Apr 1, 2021
1 parent d59a091 commit 4092d47
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
14 changes: 14 additions & 0 deletions crates/acir/src/circuit/gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,20 @@ pub enum Gate {
Directive(Directive),
}

impl Gate {
pub fn is_arithmetic(&self) -> bool {
if let Gate::Arithmetic(_) = self {
true
} else { false}
}
pub fn arithmetic(self) -> Arithmetic {
match self {
Gate::Arithmetic(gate) => gate,
_=> panic!("tried to convert a non arithmetic gate to an Arithmetic struct")
}
}
}

#[derive(Clone, Debug)]
/// Directives do not apply any constraints.
pub enum Directive {
Expand Down
10 changes: 10 additions & 0 deletions crates/acir/src/circuit/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ pub struct Circuit {
pub public_inputs: PublicInputs,
}

impl Circuit {
pub fn num_vars(&self) -> u32 {
self.current_witness_index + 1
}
}

#[derive(Clone, Debug)]
pub struct PublicInputs(pub Vec<Witness>);

Expand All @@ -23,6 +29,10 @@ impl PublicInputs {
.map(|witness| witness.witness_index() as u32)
.collect()
}

pub fn contains(&self, index : usize) -> bool {
self.0.contains(&Witness(index as u32))
}
}
#[derive(Clone, Debug)]
pub struct Selector(pub String, pub FieldElement);
Expand Down
5 changes: 5 additions & 0 deletions crates/acir/src/native_types/witness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ impl Witness {
pub fn witness_index(&self) -> u32 {
self.0
}
pub fn as_usize(&self) -> usize {
// This is safe as long as the architecture is 32bits minimum
self.0 as usize
}


pub const fn can_defer_constraint(&self) -> bool {
true
Expand Down

0 comments on commit 4092d47

Please sign in to comment.