diff --git a/compiler/tests/asm.rs b/compiler/tests/asm.rs index 2bc8b2a8b3..12565e4eca 100644 --- a/compiler/tests/asm.rs +++ b/compiler/tests/asm.rs @@ -182,6 +182,24 @@ fn vm_to_vm_dynamic_trace_length() { gen_estark_proof(f, slice_to_vec(&i)); } +#[test] +fn vm_to_vm_to_block() { + let f = "vm_to_vm_to_block.asm"; + let i = []; + verify_asm::(f, slice_to_vec(&i)); + gen_halo2_proof(f, slice_to_vec(&i)); + gen_estark_proof(f, slice_to_vec(&i)); +} + +#[test] +fn vm_to_vm_to_vm() { + let f = "vm_to_vm_to_vm.asm"; + let i = []; + verify_asm::(f, slice_to_vec(&i)); + gen_halo2_proof(f, slice_to_vec(&i)); + gen_estark_proof(f, slice_to_vec(&i)); +} + #[test] fn test_mem_read_write() { let f = "mem_read_write.asm"; diff --git a/test_data/asm/vm_to_vm_to_block.asm b/test_data/asm/vm_to_vm_to_block.asm new file mode 100644 index 0000000000..214a70f052 --- /dev/null +++ b/test_data/asm/vm_to_vm_to_block.asm @@ -0,0 +1,66 @@ +machine Main { + + degree 256; + + Pythagoras pythagoras; + + reg pc[@pc]; + reg X[<=]; + reg Y[<=]; + reg Z[<=]; + reg A; + + instr pythagoras X, Y -> Z = pythagoras.pythagoras + instr assert_eq X, Y { X = Y } + + function main { + A <== pythagoras(3, 4); + assert_eq A, 25; + + A <== pythagoras(4, 3); + assert_eq A, 25; + + A <== pythagoras(1, 2); + assert_eq A, 5; + + return; + } +} + + +machine Pythagoras { + + Arith arith; + + reg pc[@pc]; + reg X[<=]; + reg Y[<=]; + reg Z[<=]; + reg A; + reg B; + + + instr add X, Y -> Z = arith.add + instr mul X, Y -> Z = arith.mul + + function pythagoras a: field, b: field -> field { + A <== mul(a, a); + B <== mul(b, b); + A <== add(A, B); + return A; + } +} + +machine Arith(latch, operation_id) { + + operation add<0> x1, x2 -> y; + operation mul<1> x1, x2 -> y; + + col fixed latch = [1]*; + col witness operation_id; + col witness x1; + col witness x2; + col witness y; + + y = operation_id * (x1 * x2) + (1 - operation_id) * (x1 + x2); +} diff --git a/test_data/asm/vm_to_vm_to_vm.asm b/test_data/asm/vm_to_vm_to_vm.asm new file mode 100644 index 0000000000..7033c8aae6 --- /dev/null +++ b/test_data/asm/vm_to_vm_to_vm.asm @@ -0,0 +1,73 @@ +machine Main { + + degree 256; + + Pythagoras pythagoras; + + reg pc[@pc]; + reg X[<=]; + reg Y[<=]; + reg Z[<=]; + reg A; + + instr pythagoras X, Y -> Z = pythagoras.pythagoras + instr assert_eq X, Y { X = Y } + + function main { + A <== pythagoras(3, 4); + assert_eq A, 25; + + A <== pythagoras(4, 3); + assert_eq A, 25; + + A <== pythagoras(1, 2); + assert_eq A, 5; + + return; + } +} + +machine Pythagoras { + + Arith arith; + + reg pc[@pc]; + reg X[<=]; + reg Y[<=]; + reg Z[<=]; + reg A; + reg B; + + + instr add X, Y -> Z = arith.add + instr mul X, Y -> Z = arith.mul + + function pythagoras a: field, b: field -> field { + A <== mul(a, a); + B <== mul(b, b); + A <== add(A, B); + return A; + } +} + +machine Arith { + + reg pc[@pc]; + reg X[<=]; + reg Y[<=]; + reg Z[<=]; + reg A; + + instr add X, Y -> Z { X + Y = Z } + instr mul X, Y -> Z { X * Y = Z } + + function add x: field, y: field -> field { + A <== add(x, y); + return A; + } + + function mul x: field, y: field -> field { + A <== mul(x, y); + return A; + } +} \ No newline at end of file