Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make machine statements compatible with block statements. #1768

Closed
wants to merge 7 commits into from
Closed
2 changes: 1 addition & 1 deletion linker/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,7 @@ machine NegativeForUnsigned {
machine SubVM with latch: latch, operation_id: operation_id, min_degree: 64, max_degree: 128 {
operation add5<0> x -> y;

col witness operation_id;
let operation_id;
col fixed latch = [1]*;

col witness x;
Expand Down
24 changes: 12 additions & 12 deletions std/machines/binary.asm
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ machine ByteBinary with
{
operation run<0> P_operation, P_A, P_B -> P_C;

col fixed latch = [1]*;
col fixed operation_id = [0]*;
let latch: col = |i| 1;
let operation_id: col = |i| 0;

let bit_counts = [256, 256, 3];
let min_degree = std::array::product(bit_counts);
Expand All @@ -24,7 +24,7 @@ machine ByteBinary with
let P_A: col = a;
let P_B: col = b;
let P_operation: col = op;
col fixed P_C(i) {
let P_C: col = |i| {
match op(i) {
0 => a(i) & b(i),
1 => a(i) | b(i),
Expand All @@ -45,19 +45,19 @@ machine Binary(byte_binary: ByteBinary) with

operation xor<2> A, B -> C;

col witness operation_id;
let operation_id;
unchanged_until(operation_id, latch);

col fixed latch(i) { if (i % 4) == 3 { 1 } else { 0 } };
col fixed FACTOR(i) { 1 << (((i + 1) % 4) * 8) };
let latch: col = |i| { if (i % 4) == 3 { 1 } else { 0 } };
let FACTOR: col = |i| { 1 << (((i + 1) % 4) * 8) };

col witness A_byte;
col witness B_byte;
col witness C_byte;
let A_byte;
let B_byte;
let C_byte;

col witness A;
col witness B;
col witness C;
let A;
let B;
let C;

A' = A * (1 - latch) + A_byte * FACTOR;
B' = B * (1 - latch) + B_byte * FACTOR;
Expand Down
8 changes: 4 additions & 4 deletions std/machines/hash/poseidon_bn254.asm
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ machine PoseidonBN254 with
// hash functions.
operation poseidon_permutation<0> state[0], state[1], state[2] -> output[0];

col witness operation_id;
let operation_id;

// Using parameters from https://eprint.iacr.org/2019/458.pdf
// See https://extgit.iaik.tugraz.at/krypto/hadeshash/-/blob/master/code/poseidonperm_x5_254_3.sage
Expand All @@ -34,9 +34,9 @@ machine PoseidonBN254 with
let PARTIAL_ROUNDS = 57;
let ROWS_PER_HASH = FULL_ROUNDS + PARTIAL_ROUNDS + 1;

pol constant L0 = [1] + [0]*;
pol constant FIRSTBLOCK(i) { if i % ROWS_PER_HASH == 0 { 1 } else { 0 } };
pol constant LASTBLOCK(i) { if i % ROWS_PER_HASH == ROWS_PER_HASH - 1 { 1 } else { 0 } };
let L0: col = |i| if i == 0 { 1 } else { 0 };
let FIRSTBLOCK: col = |i| { if i % ROWS_PER_HASH == 0 { 1 } else { 0 } };
let LASTBLOCK: col = |i| { if i % ROWS_PER_HASH == ROWS_PER_HASH - 1 { 1 } else { 0 } };
// Like LASTBLOCK, but also 1 in the last row of the table
// Specified this way because we can't access the degree in the match statement
pol constant LAST = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]* + [1];
Expand Down
2 changes: 1 addition & 1 deletion std/machines/hash/poseidon_gl.asm
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ machine PoseidonGL with
// hash functions.
operation poseidon_permutation<0> state[0], state[1], state[2], state[3], state[4], state[5], state[6], state[7], state[8], state[9], state[10], state[11] -> output[0], output[1], output[2], output[3];

col witness operation_id;
let operation_id;

// Ported from:
// - https://github.com/0xPolygonHermez/zkevm-proverjs/blob/main/pil/poseidong.pil
Expand Down
2 changes: 1 addition & 1 deletion std/machines/hash/poseidon_gl_memory.asm
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ machine PoseidonGLMemory(mem: Memory, split_gl: SplitGL) with
// Reads happen at the provided time step; writes happen at the next time step.
operation poseidon_permutation<0> input_addr, output_addr, time_step ->;

col witness operation_id;
let operation_id;

// Ported from:
// - https://github.com/0xPolygonHermez/zkevm-proverjs/blob/main/pil/poseidong.pil
Expand Down
2 changes: 1 addition & 1 deletion std/machines/shift.asm
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ machine Shift(byte_shift: ByteShift) with

operation shr<1> A, B -> C;

col witness operation_id;
let operation_id;
unchanged_until(operation_id, latch);

col fixed latch(i) { if (i % 4) == 3 { 1 } else { 0 } };
Expand Down
2 changes: 1 addition & 1 deletion test_data/asm/block_machine_cache_miss.asm
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ machine Arith with
operation double<0> x -> y;
operation square<1> x -> y;

col witness operation_id;
let operation_id;
col fixed latch = [1]*;
col fixed X(i) {i};
col fixed DOUBLE(i) {2*i};
Expand Down
2 changes: 1 addition & 1 deletion test_data/asm/book/instructions.asm
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ machine SubMachine with
latch: latch,
operation_id: operation_id
{
col witness operation_id;
let operation_id;
col fixed latch = [1]*;

operation add<0> x, y -> z;
Expand Down
2 changes: 1 addition & 1 deletion test_data/asm/book/instructions2.asm
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ machine SubMachine with
latch: latch,
operation_id: operation_id
{
col witness operation_id;
let operation_id;
col fixed latch = [1]*;

operation add<0> x, y -> z;
Expand Down
2 changes: 1 addition & 1 deletion test_data/asm/dynamic_vadcop.asm
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ machine Arith with
operation mul<1> x[0], x[1] -> y;

col fixed latch = [1]*;
col witness operation_id;
let operation_id;
col witness x[2];
col witness y;

Expand Down
2 changes: 1 addition & 1 deletion test_data/asm/multiple_signatures.asm
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ machine Add with
// The compiler enforces that there is an operation ID if there are
// multiple operations, even though we want the constraints to be
// the same in both cases...
col witness operation_id;
let operation_id;
let latch = 1;

// A and B provided => C will be the sum.
Expand Down
2 changes: 1 addition & 1 deletion test_data/asm/permutations/link_merging.asm
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ machine SubMachine with
latch: latch,
operation_id: operation_id
{
col witness operation_id;
let operation_id;
col fixed latch = [1]*;

operation add<0> x, y -> z;
Expand Down
2 changes: 1 addition & 1 deletion test_data/asm/permutations/vm_to_block_multiple_links.asm
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ machine Arith with

operation sub<1> z, x -> y;

col witness operation_id;
let operation_id;
col fixed latch = [1]*;
col witness x;
col witness y;
Expand Down
2 changes: 1 addition & 1 deletion test_data/asm/side_effects.asm
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ machine MemoryProxy with
{
operation mstore<0> addr, step, value ->;

col witness operation_id;
let operation_id;
col fixed latch = [1]*;

Byte2 byte2;
Expand Down
2 changes: 1 addition & 1 deletion test_data/asm/vm_instr_param_mapping.asm
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ machine AddVM with
{
operation add<0> x,y -> z;

col witness operation_id;
let operation_id;
col fixed latch = [1]*;

col witness x;
Expand Down
2 changes: 1 addition & 1 deletion test_data/asm/vm_to_block_array.asm
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ machine Arith with
operation mul<1> x[0], x[1] -> y;

col fixed latch = [1]*;
col witness operation_id;
let operation_id;
col witness x[2];
col witness y;

Expand Down
2 changes: 1 addition & 1 deletion test_data/asm/vm_to_block_multiple_interfaces.asm
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ machine Arith with

operation sub<1> z, x -> y;

col witness operation_id;
let operation_id;
col fixed latch = [1]*;
col witness x;
col witness y;
Expand Down
4 changes: 2 additions & 2 deletions test_data/asm/vm_to_block_to_block.asm
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ machine Inc with
{
operation inc<0> x -> y;

col witness operation_id;
let operation_id;
col fixed latch = [1]*;
col witness x;
col witness y;
Expand All @@ -24,7 +24,7 @@ machine Assert1 with
// Increment x by calling into inc machine
link => y = inc.inc(x);

col witness operation_id;
let operation_id;
col fixed latch = [1]*;
col witness x;
col witness y;
Expand Down
4 changes: 2 additions & 2 deletions test_data/asm/vm_to_block_unique_interface.asm
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ machine Binary with

operation or<1> x, y -> z;

col witness operation_id;
let operation_id;
col fixed latch = [1]*;
col witness x;
col witness y;
Expand All @@ -28,7 +28,7 @@ machine Arith with

operation sub<1> x, y -> z;

col witness operation_id;
let operation_id;
col fixed latch = [1]*;
col witness x;
col witness y;
Expand Down
2 changes: 1 addition & 1 deletion test_data/asm/vm_to_vm_to_block.asm
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ machine Arith with
operation mul<1> x1, x2 -> y;

col fixed latch = [1]*;
col witness operation_id;
let operation_id;
col witness x1;
col witness x2;
col witness y;
Expand Down
Loading