Skip to content

Commit

Permalink
implement get random value api
Browse files Browse the repository at this point in the history
  • Loading branch information
siq1 authored and zhenfeizhang committed Nov 11, 2024
1 parent 307a014 commit 8e68847
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions expander_compiler/src/frontend/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ pub trait BasicAPI<C: Config> {
x: impl ToVariableOrValue<C::CircuitField>,
y: impl ToVariableOrValue<C::CircuitField>,
);
fn get_random_value(&mut self) -> Variable;
}

pub trait UnconstrainedAPI<C: Config> {
Expand Down
10 changes: 10 additions & 0 deletions expander_compiler/src/frontend/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,12 @@ impl<C: Config> BasicAPI<C> for Builder<C> {
let diff = self.sub(x, y);
self.assert_is_non_zero(diff);
}

fn get_random_value(&mut self) -> Variable {
self.instructions
.push(SourceInstruction::ConstantLike(Coef::Random));
self.new_var()
}
}

// write macro rules for unconstrained binary op definition
Expand Down Expand Up @@ -436,6 +442,10 @@ impl<C: Config> BasicAPI<C> for RootBuilder<C> {
) {
self.last_builder().assert_is_different(x, y)
}

fn get_random_value(&mut self) -> Variable {
self.last_builder().get_random_value()
}
}

impl<C: Config> RootBuilder<C> {
Expand Down

0 comments on commit 8e68847

Please sign in to comment.