Skip to content

Commit

Permalink
feat: add array methods to builder (#179)
Browse files Browse the repository at this point in the history
  • Loading branch information
jtguibas authored Oct 10, 2023
1 parent cdb1922 commit ba73659
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions plonky2x/src/backend/circuit/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ impl<L: PlonkParameters<D>, const D: usize> MockCircuitBuild<L, D> {
PublicInput::new(&self.io)
}

/// Generates a mock proof.
pub fn mock_prove(
&self,
input: &PublicInput<L, D>,
Expand Down
20 changes: 20 additions & 0 deletions plonky2x/src/frontend/builder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use super::vars::EvmVariable;
use crate::backend::circuit::{CircuitBuild, DefaultParameters, MockCircuitBuild, PlonkParameters};
use crate::frontend::hint::asynchronous::generator::AsyncHintDataRef;
use crate::frontend::vars::{BoolVariable, CircuitVariable, Variable};
use crate::prelude::ArrayVariable;
use crate::utils::eth::beacon::BeaconClient;
use crate::utils::eth::beaconchain::BeaconchainAPIClient;

Expand Down Expand Up @@ -264,6 +265,16 @@ impl<L: PlonkParameters<D>, const D: usize> CircuitBuilder<L, D> {
V::init(self)
}

/// Initializes an array of variables with no value in the circuit.
pub fn init_array<V: CircuitVariable, const N: usize>(&mut self) -> ArrayVariable<V, N> {
ArrayVariable::init(self)
}

/// Initializes an array of variables with no value in the circuit without any validity checks.
pub fn init_array_unsafe<V: CircuitVariable, const N: usize>(&mut self) -> ArrayVariable<V, N> {
ArrayVariable::init_unsafe(self)
}

/// Initializes a variable with no value in the circuit without any validity checks.
pub fn init_unsafe<V: CircuitVariable>(&mut self) -> V {
V::init_unsafe(self)
Expand All @@ -274,6 +285,15 @@ impl<L: PlonkParameters<D>, const D: usize> CircuitBuilder<L, D> {
V::constant(self, value)
}

/// Initializes an array of variables with a constant value in the circuit.
pub fn constant_array<V: CircuitVariable, const N: usize>(
&mut self,
value: &[V::ValueType<L::Field>],
) -> ArrayVariable<V, N> {
assert_eq!(value.len(), N);
ArrayVariable::constant(self, value.to_vec())
}

/// Asserts that the given variable is valid.
pub fn assert_is_valid<V: CircuitVariable>(&mut self, variable: V) {
variable.assert_is_valid(self)
Expand Down

0 comments on commit ba73659

Please sign in to comment.