Skip to content

Commit 41adcd0

Browse files
authored
Fix small field arith machine for bus linker mode (#2339)
Same change as #2297. I opened #2340 to track fixing the root cause. With this change, we can have the BabyBear RISC-V machine with a bus: ```rs cargo run -r --features plonky3 --bin powdr-rs compile riscv/tests/riscv_data/keccak-o output --field bb cargo run -r --features plonky3 pil output/keccak.asm -o output -f --field bb --prove-with plonky3 --linker-mode bus ```
1 parent d382a38 commit 41adcd0

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

std/machines/small_field/arith.asm

+11-4
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ machine Arith(byte: Byte, byte2: Byte2) with
2323
// Allow this machine to be connected via a permutation
2424
call_selectors: sel,
2525
{
26-
require_field_bits(18, || "Arith equires a field that fits any 18-Bit value.");
26+
require_field_bits(18, || "Arith requires a field that fits any 18-Bit value.");
2727

2828
col witness is_division;
2929

@@ -127,9 +127,16 @@ machine Arith(byte: Byte, byte2: Byte2) with
127127

128128
// All input & output limbs are range-constrained to be bytes.
129129

130-
link => byte.check(sum(4, |i| x1[i] * CLK8[i]) + sum(4, |i| y1[i] * CLK8[4 + i]));
131-
link => byte.check(sum(4, |i| x2[i] * CLK8[i]) + sum(4, |i| y2[i] * CLK8[4 + i]));
132-
link => byte.check(sum(4, |i| y3[i] * CLK8[i]));
130+
// sum0 (and the others) used to be inlined inside `byte2.check(...)`,
131+
// but that causes an issue in the bus linker mode due to the expressions
132+
// being copied syntactically before resolving the closures.
133+
// Moving these expressions out of the link fixes it.
134+
let sum0 = sum(4, |i| x1[i] * CLK8[i]) + sum(4, |i| y1[i] * CLK8[4 + i]);
135+
link => byte.check(sum0);
136+
let sum1 = sum(4, |i| x2[i] * CLK8[i]) + sum(4, |i| y2[i] * CLK8[4 + i]);
137+
link => byte.check(sum1);
138+
let sum2 = sum(4, |i| y3[i] * CLK8[i]);
139+
link => byte.check(sum2);
133140

134141
// Constrain x1 * y1 + x2 - y2 * 2**16 - y3 = 0
135142

0 commit comments

Comments
 (0)