Skip to content

Commit d382a38

Browse files
authored
Make latch semantic clearer (#2358)
Depends on #2360 Changes the semantics of the `PhantomBusInteraction.latch` field slightly, to make my life easier with #2351. Basically, we want it to be exactly what the RHS selector would have been in a lookup / permutation: A fixed column latch for a lookup, and equal to the multiplicity for the permutation. This way, witgen can treat it just like it treats selectors now. Eventually, I think we should remove the latch again. The permutation latch is equal to the multiplicity anyway, and the lookup latch should be detectable by looking for a constraint like `(1 - latch) * multiplicity = 0;`.
1 parent fd576d5 commit d382a38

File tree

5 files changed

+15
-11
lines changed

5 files changed

+15
-11
lines changed

linker/src/lib.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -330,26 +330,26 @@ fn receive(
330330
latch: Expression,
331331
interaction_id: u32,
332332
) -> Expression {
333-
let (function, identity) = match identity_type {
333+
let (function, arguments) = match identity_type {
334334
InteractionType::Lookup => (
335335
SymbolPath::from_str("std::protocols::lookup_via_bus::lookup_receive")
336336
.unwrap()
337337
.into(),
338-
lookup(lhs, rhs),
338+
vec![interaction_id.into(), lookup(lhs, rhs), latch],
339339
),
340340
InteractionType::Permutation => (
341341
SymbolPath::from_str("std::protocols::permutation_via_bus::permutation_receive")
342342
.unwrap()
343343
.into(),
344-
permutation(lhs, rhs),
344+
vec![interaction_id.into(), permutation(lhs, rhs)],
345345
),
346346
};
347347

348348
Expression::FunctionCall(
349349
SourceRef::unknown(),
350350
FunctionCall {
351351
function: Box::new(Expression::Reference(SourceRef::unknown(), function)),
352-
arguments: vec![interaction_id.into(), identity, latch],
352+
arguments,
353353
},
354354
)
355355
}

std/prelude.asm

+5-2
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,12 @@ enum Constr {
4646
/// A "phantom" bus interaction, i.e., an annotation for witness generation.
4747
/// The actual constraint should be enforced via other constraints.
4848
/// Contains:
49-
/// - An expression for the multiplicity.
49+
/// - An expression for the multiplicity. Negative for bus receives.
5050
/// - The tuple added to the bus.
51-
/// - An expression for the latch, a binary expression which indicates where the multiplicity can be non-zero.
51+
/// - An expression for the latch. This should be exactly what the RHS selector
52+
/// would be in an equivalent lookup or permutation:
53+
/// - It should always evaluate to a binary value.
54+
/// - If it evaluates to zero, the multiplicity must be zero.
5255
/// WARNING: As of now, this annotation is largely ignored. When using the bus,
5356
/// make sure that you also add phantom lookup / permutation constraints.
5457
PhantomBusInteraction(expr, expr[], expr)

std/protocols/bus.asm

+3-2
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,11 @@ let compute_next_z: expr, expr, expr[], expr, Ext<expr>, Ext<expr>, Ext<expr> ->
125125

126126
/// Convenience function for bus interaction to send columns
127127
let bus_send: expr, expr[], expr -> () = constr |id, tuple, multiplicity| {
128-
bus_interaction(id, tuple, multiplicity, 1);
128+
// For bus sends, the multiplicity always equals the latch
129+
bus_interaction(id, tuple, multiplicity, multiplicity);
129130
};
130131

131132
/// Convenience function for bus interaction to receive columns
132133
let bus_receive: expr, expr[], expr, expr -> () = constr |id, tuple, multiplicity, latch| {
133-
bus_interaction(id, tuple, -1 * multiplicity, latch);
134+
bus_interaction(id, tuple, -multiplicity, latch);
134135
};

std/protocols/permutation_via_bus.asm

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ let permutation_send: expr, Constr -> () = constr |id, permutation_constraint| {
1515
/// Given an ID and permutation constraints, receives the (ID, permutation_constraint.rhs...) tuple from the bus
1616
/// with a prover-provided multiplicity if permutation_constraint.rhs_selector is 1.
1717
/// Also adds an annotation for witness generation.
18-
let permutation_receive: expr, Constr, expr -> () = constr |id, permutation_constraint, latch| {
18+
let permutation_receive: expr, Constr -> () = constr |id, permutation_constraint| {
1919
let (lhs_selector, lhs, rhs_selector, rhs) = unpack_permutation_constraint(permutation_constraint);
2020
21-
bus_receive(id, rhs, rhs_selector, latch);
21+
bus_receive(id, rhs, rhs_selector, rhs_selector);
2222
2323
// Add an annotation for witness generation
2424
to_phantom_permutation(permutation_constraint);

test_data/std/bus_permutation.asm

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,5 @@ machine Main with degree: 8 {
1818
let ID = 123;
1919
let permutation_constraint = sel $ [x, y] is sub_sel $ [sub_x, sub_y];
2020
permutation_send(ID, permutation_constraint);
21-
permutation_receive(ID, permutation_constraint, 1);
21+
permutation_receive(ID, permutation_constraint);
2222
}

0 commit comments

Comments
 (0)