-
Notifications
You must be signed in to change notification settings - Fork 11
Description
Currently we have (using the merkletree gadget as example):
struct MerkleProofGadget { // contains the config params
max_depth: usize,
}
impl MerkleProofGadget {
fn eval(&self, builder) -> Result<MerkleProofTarget> {
// logic of the gadget
}
}
struct MerkleProofTarget {
max_depth: usize,
enabled: BoolTarget,
root: HashOutTarget,
key: ValueTarget,
value: ValueTarget,
existence: BoolTarget,
siblings: Vec<HashOutTarget>,
case_ii_selector: BoolTarget,
other_key: ValueTarget,
other_value: ValueTarget,
}
impl MerkleProofTarget{
fn set_targets(&self, partial_witness, inputs) -> Result<()> {
// assign inputs to the targets
}
}Then to use it we have to do:
let targets = MerkleProofGadget { max_depth }.eval(&mut builder)?;
targets.set_targets( &mut pw, true, true, tree2.root(), proof.clone(), key, value)?;I find the eval naming confusing, since it makes it look like the method is "evaluating", when actually it is setting the targets and the gadget logic (ie. building the gadget/circuit logic).
Since the other method is set_targets, maybe an option would be using add_targets instead of eval, but not convinced; maybe something else like build_circuit (although in some cases will not be a 'circuit' but a 'gadget'). Then maybe something like build_logic or targets_logic or similar. Or, since we're already in the SomethingGadget context, can be directly SomethingGadget::build().
Also we can group the two structs to simplify a bit the interfaces, something like:
struct MerkleProofGadget {
max_depth: usize,
enabled: BoolTarget,
root: HashOutTarget,
key: ValueTarget,
value: ValueTarget,
existence: BoolTarget,
siblings: Vec<HashOutTarget>,
case_ii_selector: BoolTarget,
other_key: ValueTarget,
other_value: ValueTarget,
}
impl MerkleProofGadget {
// NOTE: here the name 'build' could be 'build_logic', 'define_logic', 'define_gadget', etc
fn build(builder, params) -> Result<Self> {
// logic of the gadget
}
fn set_targets(&self, partial_witness, inputs) -> Result<()> {
// assign inputs to the targets
}
}Then we would use it as
let targets = MerkleProofGadget::build(&mut builder, max_depth)?;
targets.set_targets( &mut pw, true, true, tree2.root(), proof.clone(), key, value)?;Opening this issue to have a separate thread to discuss it, hoping to include it
in the refactor (#171).