From 166cd2d1cb947d977ad9fc4fbd658a37981eeaef Mon Sep 17 00:00:00 2001 From: Prabhat1308 Date: Sun, 9 Jun 2024 22:50:12 +0530 Subject: [PATCH] change code to use addressing helpers in all opcodes Signed-off-by: Prabhat1308 --- circuits/helpers/src/addressing_helper.nr | 2 +- circuits/helpers/src/lib.nr | 129 ---------------- circuits/helpers/src/permutation.nr | 54 ------- circuits/instr/and/src/main.nr | 80 +++++----- circuits/instr/asl/src/main.nr | 170 +++++++++++++++++----- circuits/instr/bit/src/main.nr | 48 +++--- circuits/instr/clc/src/main.nr | 129 +++++++++------- circuits/instr/cld/src/main.nr | 136 ++++++++++------- circuits/instr/cli/src/main.nr | 135 ++++++++++------- circuits/instr/clv/src/main.nr | 135 ++++++++++------- circuits/instr/dec/src/main.nr | 48 +++--- circuits/instr/dex/src/main.nr | 121 +++++++++------ circuits/instr/dey/src/main.nr | 134 ++++++++++------- circuits/instr/inc/src/main.nr | 51 ++++--- circuits/instr/inx/src/main.nr | 136 ++++++++++------- circuits/instr/iny/src/main.nr | 134 ++++++++++------- circuits/instr/lda/src/main.nr | 80 +++++----- circuits/instr/ldx/src/main.nr | 56 +++---- circuits/instr/ldy/src/main.nr | 56 +++---- circuits/instr/lsr/src/main.nr | 170 +++++++++++++++++----- circuits/instr/rol/src/main.nr | 170 +++++++++++++++++----- circuits/instr/ror/src/main.nr | 170 +++++++++++++++++----- circuits/instr/sec/src/main.nr | 124 ++++++++++------ circuits/instr/sed/src/main.nr | 133 ++++++++++------- circuits/instr/sei/src/main.nr | 122 ++++++++++------ circuits/instr/sta/src/main.nr | 72 ++++----- circuits/instr/stx/src/main.nr | 40 ++--- circuits/instr/sty/src/main.nr | 40 ++--- circuits/instr/tax/src/main.nr | 123 ++++++++++------ circuits/instr/tay/src/main.nr | 123 ++++++++++------ circuits/instr/txa/src/main.nr | 125 ++++++++++------ circuits/instr/tya/src/main.nr | 124 ++++++++++------ 32 files changed, 2059 insertions(+), 1311 deletions(-) diff --git a/circuits/helpers/src/addressing_helper.nr b/circuits/helpers/src/addressing_helper.nr index e8c70be..7a2871f 100644 --- a/circuits/helpers/src/addressing_helper.nr +++ b/circuits/helpers/src/addressing_helper.nr @@ -11,7 +11,7 @@ pub fn is_acc(opcode: Field) -> bool { res } pub fn is_imp(opcode: Field) -> bool { - let opcode_vec = [202, 136, 24, 216, 88, 184, 232, 200, 56, 248, 120, 170, 168, 138]; + let opcode_vec = [202, 136, 24, 216, 88, 184, 232, 200, 56, 248, 120, 170, 168, 138,152]; let mut res = false; for i in 0..opcode_vec.len() { if opcode == opcode_vec[i] { diff --git a/circuits/helpers/src/lib.nr b/circuits/helpers/src/lib.nr index 9f0e4de..69ce73e 100644 --- a/circuits/helpers/src/lib.nr +++ b/circuits/helpers/src/lib.nr @@ -254,55 +254,6 @@ pub fn set_interrupt_bit(mut status: Status) -> Status { status } -// code to call functions -// need to be removed after the logic has transaferred completely to helper -pub fn acc(op_sorted_addr: [Field; 1], op_sorted_val: [Field; 1], op_sorted_op_rw: [Field; 1]) { - addressing::acc(op_sorted_addr, op_sorted_val, op_sorted_op_rw) -} -pub fn imp(op_sorted_addr: [Field; 2], op_sorted_val: [Field; 2], op_sorted_op_rw: [Field; 2]) { - addressing::imp(op_sorted_addr, op_sorted_val, op_sorted_op_rw) -} -pub fn imm(op_sorted_addr: [Field; 2], op_sorted_val: [Field; 2], op_sorted_op_rw: [Field; 2]) -> Field { - addressing::imm(op_sorted_addr, op_sorted_val, op_sorted_op_rw) -} -pub fn zpo(op_sorted_addr: [Field; 3], op_sorted_val: [Field; 3], op_sorted_op_rw: [Field; 3]) -> Field { - addressing::zpo(op_sorted_addr, op_sorted_val, op_sorted_op_rw) -} -pub fn zpx_zpy( - mode: Field, - op_sorted_addr: [Field; 5], - op_sorted_val: [Field; 5], - op_sorted_op_rw: [Field; 5] -) -> Field { - addressing::zpx_zpy(mode, op_sorted_addr, op_sorted_val, op_sorted_op_rw) -} -pub fn rel(op_sorted_addr: [Field; 3], op_sorted_val: [Field; 3], op_sorted_op_rw: [Field; 3]) -> Field { - addressing::rel(op_sorted_addr, op_sorted_val, op_sorted_op_rw) -} -pub fn abs(op_sorted_addr: [Field; 6], op_sorted_val: [Field; 6], op_sorted_op_rw: [Field; 6]) -> Field { - addressing::abs(op_sorted_addr, op_sorted_val, op_sorted_op_rw) -} -pub fn abx_aby( - mode: Field, - op_sorted_addr: [Field; 8], - op_sorted_val: [Field; 8], - op_sorted_op_rw: [Field; 8] -) -> [Field; 2] { - addressing::abx_aby(mode, op_sorted_addr, op_sorted_val, op_sorted_op_rw) -} -pub fn ind(op_sorted_addr: [Field; 8], op_sorted_val: [Field; 8], op_sorted_op_rw: [Field; 8]) -> Field { - addressing::ind(op_sorted_addr, op_sorted_val, op_sorted_op_rw) -} -pub fn idx(op_sorted_addr: [Field; 7], op_sorted_val: [Field; 7], op_sorted_op_rw: [Field; 7]) -> Field { - addressing::idx(op_sorted_addr, op_sorted_val, op_sorted_op_rw) -} -pub fn idy( - op_sorted_addr: [Field; 7], - op_sorted_val: [Field; 7], - op_sorted_op_rw: [Field; 7] -) -> [Field; 2] { - addressing::idy(op_sorted_addr, op_sorted_val, op_sorted_op_rw) -} // addressing helper function to select the addressing based on the mode pub fn addressing_helpers( @@ -563,22 +514,6 @@ pub fn addressing_helpers( } } -pub fn compute_permutation_9( - r: Field, - op_sorted_step: [Field; 9], - op_sorted_addr: [Field; 9], - op_sorted_val: [Field; 9], - op_sorted_op_rw: [Field; 9] -) -> Field { - permutation::compute_9( - r, - op_sorted_step, - op_sorted_addr, - op_sorted_val, - op_sorted_op_rw - ) -} - pub fn compute_permutation_21( r: Field, op_sorted_step: [Field; 21], @@ -594,67 +529,3 @@ pub fn compute_permutation_21( op_sorted_op_rw ) } - -pub fn compute_permutation_7( - r: Field, - op_sorted_step: [Field; 7], - op_sorted_addr: [Field; 7], - op_sorted_val: [Field; 7], - op_sorted_op_rw: [Field; 7] -) -> Field { - permutation::compute_7( - r, - op_sorted_step, - op_sorted_addr, - op_sorted_val, - op_sorted_op_rw - ) -} - -pub fn compute_permutation_17( - r: Field, - op_sorted_step: [Field; 17], - op_sorted_addr: [Field; 17], - op_sorted_val: [Field; 17], - op_sorted_op_rw: [Field; 17] -) -> Field { - permutation::compute_17( - r, - op_sorted_step, - op_sorted_addr, - op_sorted_val, - op_sorted_op_rw - ) -} - -pub fn compute_permutation_15( - r: Field, - op_sorted_step: [Field; 15], - op_sorted_addr: [Field; 15], - op_sorted_val: [Field; 15], - op_sorted_op_rw: [Field; 15] -) -> Field { - permutation::compute_15( - r, - op_sorted_step, - op_sorted_addr, - op_sorted_val, - op_sorted_op_rw - ) -} - -pub fn compute_permutation_18( - r: Field, - op_sorted_step: [Field; 18], - op_sorted_addr: [Field; 18], - op_sorted_val: [Field; 18], - op_sorted_op_rw: [Field; 18] -) -> Field { - permutation::compute_18( - r, - op_sorted_step, - op_sorted_addr, - op_sorted_val, - op_sorted_op_rw - ) -} diff --git a/circuits/helpers/src/permutation.nr b/circuits/helpers/src/permutation.nr index 3f58e3b..118973f 100644 --- a/circuits/helpers/src/permutation.nr +++ b/circuits/helpers/src/permutation.nr @@ -9,57 +9,3 @@ pub fn compute_21( 0 } -pub fn compute_9( - _r: Field, - _op_sorted_step: [Field; 9], - _op_sorted_addr: [Field; 9], - _op_sorted_val: [Field; 9], - _op_sorted_op_rw: [Field; 9] -) -> Field { - // TODO: implement - 0 -} - -pub fn compute_7( - _r: Field, - _op_sorted_step: [Field; 7], - _op_sorted_addr: [Field; 7], - _op_sorted_val: [Field; 7], - _op_sorted_op_rw: [Field; 7] -) -> Field { - // TODO: implement - 0 -} - -pub fn compute_17( - _r: Field, - _op_sorted_step: [Field; 17], - _op_sorted_addr: [Field; 17], - _op_sorted_val: [Field; 17], - _op_sorted_op_rw: [Field; 17] -) -> Field { - // TODO: implement - 0 -} - -pub fn compute_18( - _r: Field, - _op_sorted_step: [Field; 18], - _op_sorted_addr: [Field; 18], - _op_sorted_val: [Field; 18], - _op_sorted_op_rw: [Field; 18] -) -> Field { - // TODO: implement - 0 -} - -pub fn compute_15( - _r: Field, - _op_sorted_step: [Field; 15], - _op_sorted_addr: [Field; 15], - _op_sorted_val: [Field; 15], - _op_sorted_op_rw: [Field; 15] -) -> Field { - // TODO: implement - 0 -} diff --git a/circuits/instr/and/src/main.nr b/circuits/instr/and/src/main.nr index bb482dd..2ba8e6c 100644 --- a/circuits/instr/and/src/main.nr +++ b/circuits/instr/and/src/main.nr @@ -10,10 +10,10 @@ use dep::std; fn main( r: Field, - op_sorted_step: [Field; 18], - op_sorted_addr: [Field; 18], - op_sorted_val: [Field; 18], - op_sorted_op_rw: [Field; 18] + op_sorted_step: [Field; 21], + op_sorted_addr: [Field; 21], + op_sorted_val: [Field; 21], + op_sorted_op_rw: [Field; 21] ) -> pub Field { //check the program counter assert(op_sorted_addr[0] == 8203); @@ -93,7 +93,13 @@ fn main( assert(op_sorted_op_rw[17] == 1); assert(op_sorted_val[17] == comp_status); - helpers::compute_permutation_18( + for i in 18..21 { + assert(op_sorted_addr[i] == 0); + assert(op_sorted_val[i] == 0); + assert(op_sorted_op_rw[i] == 0); + } + + helpers::compute_permutation_21( r, op_sorted_step, op_sorted_addr, @@ -110,11 +116,11 @@ fn test_0() -> Field { main( 1, [ - 343432, 343433, 343434, 343435, 343436, 343437, 343438, 343439, 343440, 343441, 343442, 343443, 343444, 343445, 343446,343447, 343448 , 343449 + 343432, 343433, 343434, 343435, 343436, 343437, 343438, 343439, 343440, 343441, 343442, 343443, 343444, 343445, 343446,343447, 343448 , 343449 , 343450 , 343451 , 343452 ], - [8203, 79, 8203,8203,8203, 0, 0, 0, 0, 0,0,8203,8203,8204,8200,8200,8205, 8205], - [49231, 41, 49232, 1, 49233, 0, 0, 0, 0, 0,0,49233,49234,67,34,2,36,36], - [0, 0, 1, 0, 1, 0, 0, 0, 0, 0,0,0,1,0,0,1,0, 1] + [8203, 79, 8203,8203,8203, 0, 0, 0, 0, 0,0,8203,8203,8204,8200,8200,8205,8205,0,0,0], + [49231, 41, 49232, 1, 49233, 0, 0, 0, 0, 0,0,49233,49234,67,34,2,36,36,0,0,0], + [0, 0, 1, 0, 1, 0, 0, 0, 0, 0,0,0,1,0,0,1,0, 1,0,0,0] ) } @@ -123,11 +129,11 @@ fn test_1() -> Field { main( 1, [ - 343492, 343493, 343494, 343495, 343496, 343497, 343498, 343499, 343500, 343501, 343502, 343503, 343504, 343505, 343506, 343507, 343508 , 343509 + 343492, 343493, 343494, 343495, 343496, 343497, 343498, 343499, 343500, 343501, 343502, 343503, 343504, 343505, 343506, 343507, 343508 , 343509 , 343510 , 343511 , 343512 ], - [8203, 79, 8203,8203,8203, 0, 0, 0,0,0,8203,49233,8203 ,8204,8200,8200,8205, 8205], - [49231, 37 , 49232, 1, 49233, 0, 0, 0,0,0, 49233,69,49234,67,34,2,36,36], - [0, 0, 1, 0, 1, 0, 0, 0,0,0,0,0,1,0,0,1,0, 1] + [8203, 79, 8203,8203,8203, 0, 0, 0,0,0,8203,49233,8203 ,8204,8200,8200,8205, 8205,0,0,0], + [49231, 37 , 49232, 1, 49233, 0, 0, 0,0,0, 49233,69,49234,67,34,2,36,36,0,0,0], + [0, 0, 1, 0, 1, 0, 0, 0,0,0,0,0,1,0,0,1,0, 1,0,0,0] ) } @@ -136,11 +142,11 @@ fn test_2() -> Field { main( 1, [ - 343552, 343553, 343554, 343555, 343556, 343557, 343558, 343559, 343560, 343561, 343562, 343563, 343564, 343565, 343566, 343567, 343568 , 343569 + 343552, 343553, 343554, 343555, 343556, 343557, 343558, 343559, 343560, 343561, 343562, 343563, 343564, 343565, 343566, 343567, 343568 , 343569 , 343570 , 343571 , 343572 ], - [8203, 79, 8203,8203,8203,0,0,0,8203,49233,8203,13,8202,8204,8200,8200,8205, 8205 ], - [49231, 53, 49232, 1, 49233,0,0,0,49233,13,49234,0,69,67,34,2,36,36 ], - [0, 0, 1, 0, 1,0,0,0,0,0,1,0,0,0,0,1,0, 1 ] + [8203, 79, 8203,8203,8203,0,0,0,8203,49233,8203,13,8202,8204,8200,8200,8205, 8205,0,0,0], + [49231, 53, 49232, 1, 49233,0,0,0,49233,13,49234,0,69,67,34,2,36,36,0,0,0], + [0, 0, 1, 0, 1,0,0,0,0,0,1,0,0,0,0,1,0, 1,0,0,0] ) } @@ -149,11 +155,11 @@ fn test_3() -> Field { main( 1, [ - 343612, 343613, 343614, 343615, 343616, 343617, 343618, 343619, 343620, 343621, 343622, 343623, 343624, 343625, 343626, 343627, 343628 , 343629 + 343612, 343613, 343614, 343615, 343616, 343617, 343618, 343619, 343620, 343621, 343622, 343623, 343624, 343625, 343626, 343627, 343628 , 343629 , 343630 , 343631 , 343632 ], - [8203, 79, 8203,8203,8203,0,0,8203,49233,8203,8203,49234, 8203,8204,8200,8200,8205, 8205 ], - [49231, 45, 49232, 1, 49233,0,0,49233,1,49234,49234,2,49235,67,34,2,36,36], - [0, 0, 1, 0, 1,0,0,0,0,1,0,0,1,0,0,1,0, 1 ] + [8203, 79, 8203,8203,8203,0,0,8203,49233,8203,8203,49234, 8203,8204,8200,8200,8205, 8205 ,0,0,0], + [49231, 45, 49232, 1, 49233,0,0,49233,1,49234,49234,2,49235,67,34,2,36,36,0,0,0], + [0, 0, 1, 0, 1,0,0,0,0,1,0,0,1,0,0,1,0,1,0,0,0] ) } @@ -162,11 +168,11 @@ fn test_4() -> Field { main( 1, [ - 343712, 343713, 343714, 343715, 343716, 343717, 343718, 343719, 343720, 343721, 343722, 343723, 343724, 343725, 343726, 343727, 343728 , 343729 + 343712, 343713, 343714, 343715, 343716, 343717, 343718, 343719, 343720, 343721, 343722, 343723, 343724, 343725, 343726, 343727, 343728 , 343729 , 343730 , 343731 , 343732 ], - [8203,79,8203,8203,8203,8203, 49233, 8203, 8203, 49234, 8203, 8201, 582,8204,8200,8200,8205, 8205 ], - [49231,61, 49232,0,49233,49233, 1, 49234, 49234, 2, 49235, 69, 80,67,34,2,36,36], - [0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0,0,0,1,0, 1 ] + [8203,79,8203,8203,8203,8203, 49233, 8203, 8203, 49234, 8203, 8201, 582,8204,8200,8200,8205, 8205,0,0,0], + [49231,61, 49232,0,49233,49233, 1, 49234, 49234, 2, 49235, 69, 80,67,34,2,36,36,0,0,0], + [0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0,0,0,1,0, 1,0,0,0] ) } @@ -175,11 +181,11 @@ fn test_5() -> Field { main( 1, [ - 343812, 343813, 343814, 343815, 343816, 343817, 343818, 343819, 343820, 343821, 343822, 343823, 343824, 343825, 343826, 343827, 343828 , 343829 + 343812, 343813, 343814, 343815, 343816, 343817, 343818, 343819, 343820, 343821, 343822, 343823, 343824, 343825, 343826, 343827, 343828 , 343829 , 343830 , 343831 , 343832 ], - [8203,79,8203,8203,8203,8203, 49233, 8203, 8203, 49234, 8203, 8202, 582,8204,8200,8200,8205, 8205 ], - [49231,57, 49232,1,49233,49233, 1, 49234, 49234, 2, 49235, 69, 80,67,34,2,36,36], - [0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0,0,0,1,0, 1 ] + [8203,79,8203,8203,8203,8203, 49233, 8203, 8203, 49234, 8203, 8202, 582,8204,8200,8200,8205, 8205,0,0,0], + [49231,57, 49232,1,49233,49233, 1, 49234, 49234, 2, 49235, 69, 80,67,34,2,36,36,0,0,0], + [0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0,0,0,1,0,1,0,0,0] ) } @@ -188,11 +194,11 @@ fn test_6() -> Field { main( 1, [ - 343912, 343913, 343914, 343915, 343916, 343917, 343918, 343919, 343920, 343921, 343922, 343923, 343924, 343925, 343926, 343927, 343928 , 343929 + 343912, 343913, 343914, 343915, 343916, 343917, 343918, 343919, 343920, 343921, 343922, 343923, 343924, 343925, 343926, 343927, 343928 , 343929 , 343930 , 343931 , 343932 ], - [8203,79,8203,8203,8203,0,8203,49233,8203,5675,8201,5688,5689,8204,8200,8200,8205, 8205 ], - [49231,33, 49232,0,49233,0,49233,5675,5676,69,13,1,2,67,34,2,36,36], - [0, 0, 1, 0, 1,0,0,0,1,0,0,0,0 ,0,0,1,0,1] + [8203,79,8203,8203,8203,0,8203,49233,8203,5675,8201,5688,5689,8204,8200,8200,8205, 8205,0,0,0], + [49231,33, 49232,0,49233,0,49233,5675,5676,69,13,1,2,67,34,2,36,36,0,0,0], + [0, 0, 1, 0, 1,0,0,0,1,0,0,0,0 ,0,0,1,0,1,0,0,0] ) } @@ -201,10 +207,10 @@ fn test_7() -> Field { main( 1, [ - 343912, 343913, 343914, 343915, 343916, 343917, 343918, 343919, 343920, 343921, 343922, 343923, 343924, 343925, 343926, 343927, 343928 , 343929 + 343912, 343913, 343914, 343915, 343916, 343917, 343918, 343919, 343920, 343921, 343922, 343923, 343924, 343925, 343926, 343927, 343928 , 343929 , 343930 , 343931 , 343932 ], - [8203,79,8203,8203,8203,0,8203,49233,8203,5675,5676,8202,582,8204,8200,8200,8205, 8205], - [49231,49, 49232,0,49233,0,49233,5675,5676,1,2,69,112,67,34,2,36,36], - [0, 0, 1, 0, 1,0,0,0,1,0,0,0,0,0,0,1,0,1] + [8203,79,8203,8203,8203,0,8203,49233,8203,5675,5676,8202,582,8204,8200,8200,8205, 8205,0,0,0], + [49231,49, 49232,0,49233,0,49233,5675,5676,1,2,69,112,67,34,2,36,36,0,0,0], + [0, 0, 1, 0, 1,0,0,0,1,0,0,0,0,0,0,1,0,1,0,0,0] ) } \ No newline at end of file diff --git a/circuits/instr/asl/src/main.nr b/circuits/instr/asl/src/main.nr index 7d341a4..8840f85 100644 --- a/circuits/instr/asl/src/main.nr +++ b/circuits/instr/asl/src/main.nr @@ -1,46 +1,150 @@ use dep::helpers; +use dep::std; -fn check_op( +//PC = 8203 +//X = 8201 +//Y = 8202 +//A = 8200 +//SR = 8205 +//M = 8204 + +fn main( r: Field, - op_sorted_step: [Field; 21], - op_sorted_addr: [Field; 21], - op_sorted_val: [Field; 21], - op_sorted_op_rw: [Field; 21] -) -> Field { - // TODO: implemented mode retrieval here for the opcode read - // we don't generalize this because each opcode will only have a few modes - // and we want to keep the total constraints down rather than needlessly - // checking for other opcodes every time - - let mode: Field = 0; //stubbed for now, we assume the mode is retreived in logic above - let mut sub_arr_step: [Field; 7] = [0,0,0,0,0,0,0]; - let mut sub_arr_addr: [Field; 7] = [0,0,0,0,0,0,0]; - let mut sub_arr_val: [Field; 7] = [0,0,0,0,0,0,0]; - let mut sub_arr_op_rw: [Field; 7] = [0,0,0,0,0,0,0]; - for i in 0..7 { - sub_arr_step[i] = op_sorted_step[i]; - sub_arr_addr[i] = op_sorted_addr[i]; - sub_arr_val[i] = op_sorted_val[i]; - sub_arr_op_rw[i] = op_sorted_op_rw[i]; - } - let address_and_value: [Field; 2] = helpers::get_addressing( - mode, - sub_arr_step, - sub_arr_addr, - sub_arr_val, - sub_arr_op_rw + op_sorted_step: [Field; 17], + op_sorted_addr: [Field; 17], + op_sorted_val: [Field; 17], + op_sorted_op_rw: [Field; 17] +) -> pub Field { + //check the program counter + assert(op_sorted_addr[0] == 8203); + assert(op_sorted_op_rw[0] == 0); + let pc = op_sorted_val[0]; + + //check the opcode + assert( + (op_sorted_val[1] == 230) + | (op_sorted_val[1] == 238) + | (op_sorted_val[1] == 246) + | (op_sorted_val[1] == 254) ); + assert(op_sorted_op_rw[1] == 0); + let opcode = op_sorted_val[1]; + + //update the PC + assert(op_sorted_addr[2] == 8203); + assert(op_sorted_op_rw[2] == 1); + assert(op_sorted_val[2] == pc + 1); + + //check the mode + assert(op_sorted_addr[3] == 8203); + assert(op_sorted_op_rw[3] == 0); + let mode = op_sorted_val[3]; + + //update the PC + assert(op_sorted_addr[4] == 8203); + assert(op_sorted_op_rw[4] == 1); + assert(op_sorted_val[4] == pc + 2); + + let mut sub_arr_addr: [Field; 8] = [0, 0, 0, 0, 0, 0, 0, 0]; + let mut sub_arr_val: [Field; 8] = [0, 0, 0, 0, 0, 0, 0, 0]; + let mut sub_arr_op_rw: [Field; 8] = [0, 0, 0, 0, 0, 0, 0, 0]; + let offset = 5; + + for i in 0..8 { + sub_arr_addr[i] = op_sorted_addr[offset + i]; + sub_arr_val[i] = op_sorted_val[offset + i]; + sub_arr_op_rw[i] = op_sorted_op_rw[offset + i]; + } + + helpers::addressing_helpers(opcode, mode, sub_arr_addr, sub_arr_val, sub_arr_op_rw); + + // read from memory + assert(op_sorted_addr[13] == 8204); + assert(op_sorted_op_rw[13] == 0); + let mem_val = op_sorted_val[13]; - // TODO: implement the rest of the op code checks here + // write to memory + assert(op_sorted_addr[14] == 8204); + assert(op_sorted_op_rw[14] == 1); + let new_mem = helpers::wrapping_add_u8(mem_val, 1); + assert(op_sorted_val[14] == new_mem.value); - // TODO: handle case of padding + //read status register + assert(op_sorted_addr[15] == 8205); + assert(op_sorted_op_rw[15] == 0); + let sr = op_sorted_val[15]; - // Compute permutation and return it - helpers::compute_permutation( + let mut status = helpers::convert_to_status(sr); + + //compute zero and negative flags + status = helpers::compute_zn_status(new_mem.value, status); + let comp_status = helpers::status_to_num(status); + + //write status register + assert(op_sorted_addr[16] == 8205); + assert(op_sorted_op_rw[16] == 1); + assert(op_sorted_val[16] == comp_status); + + helpers::compute_permutation_17( r, op_sorted_step, op_sorted_addr, op_sorted_val, op_sorted_op_rw ) -} \ No newline at end of file +} + +#[test] +fn test_0() -> Field { + main( + 1, + [ + 343432, 343433, 343434, 343435, 343436, 343437, 343438, 343439, 343440, 343441, 343442, 343443, 343444, 343445, 343446,343447, 343448 + ], + [8203, 79, 8203,8203,8203, 0, 0, 0, 0, 0, 8203, 49233, 8203, 8204, 8204, 8205, 8205], + // [49231, 230, 49232, 0, 0, 0, 0, 0, 49232, 13, 49233, 0, 1, 38, 36], + [49231, 230, 49232, 1, 49233, 0, 0, 0, 0, 0, 49233, 13, 49234, 0, 1, 38, 36], + [0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1] + ) +} +#[test] +fn test_1() -> Field { + main( + 1, + [ + 343492, 343493, 343494, 343495, 343496, 343497, 343498, 343499, 343500, 343501, 343502, 343503, 343504, 343505, 343506, 343507, 343508 + ], + [8203, 79, 8203,8203,8203, 0, 0, 0, 8203, 49233, 8203, 13, 8202, 8204, 8204, 8205, 8205], + // [49231, 246, 49232, 0, 0, 0, 49232, 13, 49233, 0, 100, 1, 2, 36, 36], + [49231, 246, 49232, 1, 49233, 0, 0, 0, 49233, 13, 49234, 0, 100, 1, 2, 36, 36], + [0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1] + ) +} + +#[test] +fn test_2() -> Field { + main( + 1, + [ + 343552, 343553, 343554, 343555, 343556, 343557, 343558, 343559, 343560, 343561, 343562, 343563, 343564, 343565, 343566, 343567, 343568 + ], + [8203, 79, 8203,8203,8203, 0, 0, 8203, 49233, 8203, 8203, 49234, 8203, 8204, 8204, 8205, 8205], + // [49231, 238, 49232, 0, 0, 49232, 1, 49233, 49233, 2, 49234, 2, 3, 36, 36], + [49231, 238, 49232, 1, 49233, 0, 0, 49233, 1, 49234, 49234, 2, 49235, 3, 4, 36, 36], + [0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1, 0, 1] + ) +} + +#[test] +fn test_3() -> Field { + main( + 1, + [ + 343612, 343613, 343614, 343615, 343616, 343617, 343618, 343619, 343620, 343621, 343622, 343623, 343624, 343625, 343626, 343627, 343628 + ], + [8203, 79, 8203,8203,8203, 8203, 49233, 8203, 8203, 49234, 8203, 8202, 582, 8204, 8204, 8205, 8205], + [49231, 254, 49232, 1, 49233, 49233, 1, 49234, 49234, 2, 49235, 69, 80, 4, 5, 36, 36], + [0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 1] + ) +} + diff --git a/circuits/instr/bit/src/main.nr b/circuits/instr/bit/src/main.nr index 6ad7cd7..68f1e6d 100644 --- a/circuits/instr/bit/src/main.nr +++ b/circuits/instr/bit/src/main.nr @@ -10,10 +10,10 @@ use dep::std; fn main( r: Field, - op_sorted_step: [Field; 15], - op_sorted_addr: [Field; 15], - op_sorted_val: [Field; 15], - op_sorted_op_rw: [Field; 15] + op_sorted_step: [Field; 21], + op_sorted_addr: [Field; 21], + op_sorted_val: [Field; 21], + op_sorted_op_rw: [Field; 21] ) -> pub Field { //check the program counter assert(op_sorted_addr[0] == 8203); @@ -73,7 +73,13 @@ fn main( assert(op_sorted_op_rw[14] == 1); assert(op_sorted_val[14] == comp_status); - helpers::compute_permutation_15( + for i in 15..21 { + assert(op_sorted_addr[i] == 0); + assert(op_sorted_val[i] == 0); + assert(op_sorted_op_rw[i] == 0); + } + + helpers::compute_permutation_21( r, op_sorted_step, op_sorted_addr, @@ -87,11 +93,11 @@ fn test_0() -> Field { main( 1, [ - 343432, 343433, 343434, 343435, 343436, 343437, 343438, 343439, 343440, 343441, 343442, 343443, 343444, 343445, 343446 + 343432, 343433, 343434, 343435, 343436, 343437, 343438, 343439, 343440, 343441, 343442, 343443, 343444, 343445, 343446 , 343447, 343448, 343449, 343450, 343451, 343452 ], - [8203, 79, 8203,0,0,0,0,0,8203,49232,8203 ,8204,8204,8205,8205], - [49231, 36, 49232,0,0,0,0,0,49232,13,49233,14,14,36,36], - [0, 0, 1,0,0,0,0,0,0,0,1,0,0,0,1 ] + [8203, 79, 8203,0,0,0,0,0,8203,49232,8203 ,8204,8204,8205,8205,0,0,0,0,0,0], + [49231, 36, 49232,0,0,0,0,0,49232,13,49233,14,14,36,36,0,0,0,0,0,0], + [0, 0, 1,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0] ) } @@ -100,11 +106,11 @@ fn test_1() -> Field { main( 1, [ - 343492, 343493, 343494, 343495, 343496, 343497, 343498, 343499, 343500, 343501, 343502, 343503, 343504, 343505, 343506 + 343492, 343493, 343494, 343495, 343496, 343497, 343498, 343499, 343500, 343501, 343502, 343503, 343504, 343505, 343506, 343507, 343508, 343509, 343510, 343511, 343512 ], - [8203, 79, 8203,0,0,0,0,0,8203,49232,8203 ,8204,8204,8205,8205], - [49231, 36, 49232,0,0,0,0,0,49232,13,49233,0,14,36,38], - [0, 0, 1,0,0,0,0,0,0,0,1,0,0,0,1 ] + [8203, 79, 8203,0,0,0,0,0,8203,49232,8203 ,8204,8204,8205,8205,0,0,0,0,0,0], + [49231, 36, 49232,0,0,0,0,0,49232,13,49233,0,14,36,38,0,0,0,0,0,0], + [0, 0, 1,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0] ) } @@ -113,11 +119,11 @@ fn test_2() -> Field { main( 1, [ - 343552, 343553, 343554, 343555, 343556, 343557, 343558, 343559, 343560, 343561, 343562, 343563, 343564, 343565, 343566 + 343552, 343553, 343554, 343555, 343556, 343557, 343558, 343559, 343560, 343561, 343562, 343563, 343564, 343565, 343566 , 343567, 343568, 343569, 343570, 343571, 343572 ], - [8203, 79, 8203,0,0,8203,49232,8203,8203,49233,8203,8204,8204,8205,8205], - [49231, 44, 49232,0,0,49232,1,49233,49233,2,49234,14,14,36,36], - [0, 0, 1,0,0,0,0,1,0,0,1,0,0,0,1] + [8203, 79, 8203,0,0,8203,49232,8203,8203,49233,8203,8204,8204,8205,8205,0,0,0,0,0,0], + [49231, 44, 49232,0,0,49232,1,49233,49233,2,49234,14,14,36,36,0,0,0,0,0,0], + [0, 0, 1,0,0,0,0,1,0,0,1,0,0,0,1,0,0,0,0,0,0] ) } @@ -126,11 +132,11 @@ fn test_3() -> Field { main( 1, [ - 343552, 343553, 343554, 343555, 343556, 343557, 343558, 343559, 343560, 343561, 343562, 343563, 343564, 343565, 343566 + 343552, 343553, 343554, 343555, 343556, 343557, 343558, 343559, 343560, 343561, 343562, 343563, 343564, 343565, 343566 , 343567, 343568, 343569, 343570, 343571, 343572 ], - [8203, 79, 8203,0,0,8203,49232,8203,8203,49233,8203,8204,8204,8205,8205], - [49231, 44, 49232,0,0,49232,1,49233,49233,2,49234,0,14,36,38], - [0, 0, 1,0,0,0,0,1,0,0,1,0,0,0,1] + [8203, 79, 8203,0,0,8203,49232,8203,8203,49233,8203,8204,8204,8205,8205,0,0,0,0,0,0], + [49231, 44, 49232,0,0,49232,1,49233,49233,2,49234,0,14,36,38,0,0,0,0,0,0], + [0, 0, 1,0,0,0,0,1,0,0,1,0,0,0,1,0,0,0,0,0,0] ) } diff --git a/circuits/instr/clc/src/main.nr b/circuits/instr/clc/src/main.nr index 64bc701..ec2611b 100644 --- a/circuits/instr/clc/src/main.nr +++ b/circuits/instr/clc/src/main.nr @@ -10,59 +10,73 @@ use dep::std; fn main( r: Field, - op_sorted_step: [Field; 7], - op_sorted_addr: [Field; 7], - op_sorted_val: [Field; 7], - op_sorted_op_rw: [Field; 7] + op_sorted_step: [Field; 21], + op_sorted_addr: [Field; 21], + op_sorted_val: [Field; 21], + op_sorted_op_rw: [Field; 21] ) -> pub Field { - - //check the program counter + //check the program counter assert(op_sorted_addr[0] == 8203); assert(op_sorted_op_rw[0] == 0); let pc = op_sorted_val[0]; //check the opcode - assert(op_sorted_val[1] == 24); //0x18 - assert(op_sorted_op_rw[1] == 0); - + assert(op_sorted_val[1] == 24); //0x18 + assert(op_sorted_op_rw[1] == 0); + let opcode = op_sorted_val[1]; + //update the PC assert(op_sorted_addr[2] == 8203); assert(op_sorted_op_rw[2] == 1); assert(op_sorted_val[2] == pc + 1); - let mut sub_arr_addr: [Field; 2] = [0,0]; - let mut sub_arr_val: [Field; 2] = [0,0]; - let mut sub_arr_op_rw: [Field; 2] = [0,0]; - let offset = 3; - for i in 0..2 { + //check the mode + assert(op_sorted_addr[3] == 8203); + assert(op_sorted_op_rw[3] == 0); + let _ = op_sorted_val[3]; + + //update the PC + assert(op_sorted_addr[4] == 8203); + assert(op_sorted_op_rw[4] == 1); + assert(op_sorted_val[4] == pc + 2); + + // addressing + let mut sub_arr_addr: [Field; 8] = [0, 0, 0, 0, 0, 0, 0, 0]; + let mut sub_arr_val: [Field; 8] = [0, 0, 0, 0, 0, 0, 0, 0]; + let mut sub_arr_op_rw: [Field; 8] = [0, 0, 0, 0, 0, 0, 0, 0]; + let offset = 5; + + for i in 0..8 { sub_arr_addr[i] = op_sorted_addr[offset + i]; sub_arr_val[i] = op_sorted_val[offset + i]; sub_arr_op_rw[i] = op_sorted_op_rw[offset + i]; } - helpers::imp( - sub_arr_addr, - sub_arr_val, - sub_arr_op_rw - ); + helpers::addressing_helpers(opcode, 0, sub_arr_addr, sub_arr_val, sub_arr_op_rw); //read status register - assert(op_sorted_addr[5] == 8205); - assert(op_sorted_op_rw[5] == 0); - let sr = op_sorted_val[5]; + assert(op_sorted_addr[13] == 8205); + assert(op_sorted_op_rw[13] == 0); + let sr = op_sorted_val[13]; let mut status = helpers::convert_to_status(sr); - + //clear the interrupt flag. status = helpers::clear_carry_bit(status); let comp_status = helpers::status_to_num(status); //write on status register - assert(op_sorted_addr[6] == 8205); - assert(op_sorted_op_rw[6] == 1); - assert(op_sorted_val[6] == comp_status); + assert(op_sorted_addr[14] == 8205); + assert(op_sorted_op_rw[14] == 1); + assert(op_sorted_val[14] == comp_status); - helpers::compute_permutation_7( + for i in 15..21 { + assert(op_sorted_addr[i] == 0); + assert(op_sorted_val[i] == 0); + assert(op_sorted_op_rw[i] == 0); + } + + helpers::compute_permutation_21( r, op_sorted_step, op_sorted_addr, @@ -75,61 +89,72 @@ fn main( fn test_0() -> Field { main( 1, - [343432, 343433, 343434, 343435, 343436, 343437, 343438], - [8203, 79, 8203, 8203, 80, 8205, 8205], - [49231, 24, 49232, 49232, 224, 38, 38], - [0, 0, 1, 0, 0, 0, 1] + [ + 343432, 343433, 343434, 343435, 343436, 343437, 343438, 343439, 343440, 343441, 343442, 343443, 343444, 343445, 343446, 343447, 343448, 343449, 343450, 343451, 343452 + ], + [8203, 79, 8203, 8203, 8203, 0, 0, 0, 0, 0, 0, 8203, 80, 8205, 8205, 0, 0, 0, 0, 0, 0], + [49231, 24, 49232, 1, 49233, 0, 0, 0, 0, 0, 0, 49233, 224, 38, 38, 0, 0, 0, 0, 0, 0], + [0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0] ) } #[test] fn test_1() -> Field { main( 1, - [343492, 343493, 343494, 343495, 343496, 343497, 343498], - [8203, 79, 8203, 8203, 80, 8205, 8205], - [49231, 24, 49232, 49232, 224, 1, 0], - [0, 0, 1, 0, 0, 0, 1] + [ + 343492, 343493, 343494, 343495, 343496, 343497, 343498, 343499, 343500, 343501, 343502, 343503, 343504, 343505, 343506, 343507, 343508, 343509, 343510, 343511, 343512 + ], + [8203, 79, 8203, 8203, 8203,0, 0, 0, 0, 0, 0, 8203, 80, 8205, 8205, 0, 0, 0, 0, 0, 0], + [49231, 24, 49232, 1, 49233,0, 0, 0, 0, 0, 0, 49233, 224, 1, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0] ) } #[test] fn test_2() -> Field { main( 1, - [343552, 343553, 343554, 343555, 343556, 343557, 343558], - [8203, 79, 8203, 8203, 80, 8205, 8205], - [49231, 24, 49232, 49232, 224, 255, 254], - [0, 0, 1, 0, 0, 0, 1] + [ + 343552, 343553, 343554, 343555, 343556, 343557, 343558, 343559, 343560, 343561, 343562, 343563, 343564, 343565, 343566, 343567, 343568, 343569, 343570, 343571, 343572 + ], + [8203, 79, 8203, 8203, 8203, 0, 0, 0, 0, 0, 0,8203, 80, 8205, 8205, 0, 0, 0, 0, 0, 0], + [49231, 24, 49232, 1, 49233, 0, 0, 0, 0, 0, 0,49233, 224, 255, 254, 0, 0, 0, 0, 0, 0], + [0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0] ) } #[test] fn test_3() -> Field { main( 1, - [343612, 343613, 343614, 343615, 343616, 343617, 343618], - [8203, 79, 8203, 8203, 80, 8205, 8205], - [49231, 24, 49232, 49232, 224, 123, 122], - [0, 0, 1, 0, 0, 0, 1] + [ + 343612, 343613, 343614, 343615, 343616, 343617, 343618, 343619, 343620, 343621, 343622, 343623, 343624, 343625, 343626, 343627, 343628, 343629, 343630, 343631, 343632 + ], + [8203, 79, 8203, 8203, 8203,0, 0, 0, 0, 0, 0, 8203, 80, 8205, 8205, 0, 0, 0, 0, 0, 0], + [49231, 24, 49232, 1, 49233, 0, 0, 0, 0, 0, 0,49233, 224, 123, 122, 0, 0, 0, 0, 0, 0], + [0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0] ) } #[test] fn test_4() -> Field { main( 1, - [343672, 343673, 343674, 343675, 343676, 343677, 343678], - [8203, 79, 8203, 8203, 80, 8205, 8205], - [49231, 24, 49232, 49232, 224, 0, 0], - [0, 0, 1, 0, 0, 0, 1] + [ + 343672, 343673, 343674, 343675, 343676, 343677, 343678, 343679, 343680, 343681, 343682, 343683, 343684, 343685, 343686, 343687, 343688, 343689, 343690, 343691, 343692 + ], + [8203, 79, 8203, 8203, 8203,0, 0, 0, 0, 0, 0, 8203, 80, 8205, 8205, 0, 0, 0, 0, 0, 0], + [49231, 24, 49232, 1, 49233,0, 0, 0, 0, 0, 0, 49233, 224, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0] ) } #[test] fn test_5() -> Field { main( 1, - [343732, 343733, 343734, 343735, 343736, 343737, 343738], - [8203, 79, 8203, 8203, 80, 8205, 8205], - [49231, 24, 49232, 49232, 224, 36, 36], - [0, 0, 1, 0, 0, 0, 1] + [ + 343732, 343733, 343734, 343735, 343736, 343737, 343738, 343739, 343740, 343741, 343742, 343743, 343744, 343745, 343746, 343747, 343748, 343749, 343750, 343751, 343752 + ], + [8203, 79, 8203, 8203, 8203,0, 0, 0, 0, 0, 0, 8203, 80, 8205, 8205, 0, 0, 0, 0, 0, 0], + [49231, 24, 49232, 1, 49233,0, 0, 0, 0, 0, 0, 49233, 224, 36, 36, 0, 0, 0, 0, 0, 0], + [0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0] ) } - diff --git a/circuits/instr/cld/src/main.nr b/circuits/instr/cld/src/main.nr index f7d02f0..97bedeb 100644 --- a/circuits/instr/cld/src/main.nr +++ b/circuits/instr/cld/src/main.nr @@ -10,59 +10,73 @@ use dep::std; fn main( r: Field, - op_sorted_step: [Field; 7], - op_sorted_addr: [Field; 7], - op_sorted_val: [Field; 7], - op_sorted_op_rw: [Field; 7] + op_sorted_step: [Field; 21], + op_sorted_addr: [Field; 21], + op_sorted_val: [Field; 21], + op_sorted_op_rw: [Field; 21] ) -> pub Field { - - //check the program counter + //check the program counter assert(op_sorted_addr[0] == 8203); assert(op_sorted_op_rw[0] == 0); let pc = op_sorted_val[0]; //check the opcode - assert(op_sorted_val[1] == 216); //0xD8 - assert(op_sorted_op_rw[1] == 0); - + assert(op_sorted_val[1] == 216); //0xD8 + assert(op_sorted_op_rw[1] == 0); + let opcode = op_sorted_val[1]; + //update the PC assert(op_sorted_addr[2] == 8203); assert(op_sorted_op_rw[2] == 1); assert(op_sorted_val[2] == pc + 1); - let mut sub_arr_addr: [Field; 2] = [0,0]; - let mut sub_arr_val: [Field; 2] = [0,0]; - let mut sub_arr_op_rw: [Field; 2] = [0,0]; - let offset = 3; - for i in 0..2 { + //check the mode + assert(op_sorted_addr[3] == 8203); + assert(op_sorted_op_rw[3] == 0); + let _ = op_sorted_val[3]; + + //update the PC + assert(op_sorted_addr[4] == 8203); + assert(op_sorted_op_rw[4] == 1); + assert(op_sorted_val[4] == pc + 2); + + // addressing + let mut sub_arr_addr: [Field; 8] = [0, 0, 0, 0, 0, 0, 0, 0]; + let mut sub_arr_val: [Field; 8] = [0, 0, 0, 0, 0, 0, 0, 0]; + let mut sub_arr_op_rw: [Field; 8] = [0, 0, 0, 0, 0, 0, 0, 0]; + let offset = 5; + + for i in 0..8 { sub_arr_addr[i] = op_sorted_addr[offset + i]; sub_arr_val[i] = op_sorted_val[offset + i]; sub_arr_op_rw[i] = op_sorted_op_rw[offset + i]; } - helpers::imp( - sub_arr_addr, - sub_arr_val, - sub_arr_op_rw - ); + helpers::addressing_helpers(opcode, 0, sub_arr_addr, sub_arr_val, sub_arr_op_rw); //read status register - assert(op_sorted_addr[5] == 8205); - assert(op_sorted_op_rw[5] == 0); - let sr = op_sorted_val[5]; + assert(op_sorted_addr[13] == 8205); + assert(op_sorted_op_rw[13] == 0); + let sr = op_sorted_val[13]; let mut status = helpers::convert_to_status(sr); - + //clear the decimal flag. status = helpers::clear_decimal_bit(status); let comp_status = helpers::status_to_num(status); //write on status register - assert(op_sorted_addr[6] == 8205); - assert(op_sorted_op_rw[6] == 1); - assert(op_sorted_val[6] == comp_status); + assert(op_sorted_addr[14] == 8205); + assert(op_sorted_op_rw[14] == 1); + assert(op_sorted_val[14] == comp_status); + + for i in 15..21 { + assert(op_sorted_addr[i] == 0); + assert(op_sorted_val[i] == 0); + assert(op_sorted_op_rw[i] == 0); + } - helpers::compute_permutation_7( + helpers::compute_permutation_21( r, op_sorted_step, op_sorted_addr, @@ -71,65 +85,81 @@ fn main( ) } - #[test] fn test_0() -> Field { main( 1, - [343432, 343433, 343434, 343435, 343436, 343437, 343438], - [8203, 79, 8203, 8203, 80, 8205, 8205], - [49231, 216, 49232, 49232, 224, 38, 38], - [0, 0, 1, 0, 0, 0, 1] + [ + 343432, 343433, 343434, 343435, 343436, 343437, 343438, 343439, 343440, 343441, 343442, 343443, 343444, 343445, 343446, 343447, 343448, 343449, 343450, 343451, 343452 + ], + [8203, 79, 8203, 8203, 8203, 0, 0, 0, 0, 0, 0, 8203, 80, 8205, 8205, 0, 0, 0, 0, 0, 0], + [49231, 216, 49232, 1, 49233, 0, 0, 0, 0, 0, 0, 49233, 224, 38, 38, 0, 0, 0, 0, 0, 0], + [0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0] ) } + #[test] fn test_1() -> Field { main( 1, - [343492, 343493, 343494, 343495, 343496, 343497, 343498], - [8203, 79, 8203, 8203, 80, 8205, 8205], - [49231, 216, 49232, 49232, 224, 8, 0], - [0, 0, 1, 0, 0, 0, 1] + [ + 343432, 343433, 343434, 343435, 343436, 343437, 343438, 343439, 343440, 343441, 343442, 343443, 343444, 343445, 343446, 343447, 343448, 343449, 343450, 343451, 343452 + ], + [8203, 79, 8203, 8203, 8203, 0, 0, 0, 0, 0, 0, 8203, 80, 8205, 8205, 0, 0, 0, 0, 0, 0], + [49231, 216, 49232, 1, 49233, 0, 0, 0, 0, 0, 0, 49233, 224, 8, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0] ) } + #[test] fn test_2() -> Field { main( 1, - [343552, 343553, 343554, 343555, 343556, 343557, 343558], - [8203, 79, 8203, 8203, 80, 8205, 8205], - [49231, 216, 49232, 49232, 224, 0, 0], - [0, 0, 1, 0, 0, 0, 1] + [ + 343432, 343433, 343434, 343435, 343436, 343437, 343438, 343439, 343440, 343441, 343442, 343443, 343444, 343445, 343446, 343447, 343448, 343449, 343450, 343451, 343452 + ], + [8203, 79, 8203, 8203, 8203, 0, 0, 0, 0, 0, 0, 8203, 80, 8205, 8205, 0, 0, 0, 0, 0, 0], + [49231, 216, 49232, 1, 49233, 0, 0, 0, 0, 0, 0, 49233, 224, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0] ) } + #[test] fn test_3() -> Field { main( 1, - [343612, 343613, 343614, 343615, 343616, 343617, 343618], - [8203, 79, 8203, 8203, 80, 8205, 8205], - [49231, 216, 49232, 49232, 224, 255, 247], - [0, 0, 1, 0, 0, 0, 1] + [ + 343432, 343433, 343434, 343435, 343436, 343437, 343438, 343439, 343440, 343441, 343442, 343443, 343444, 343445, 343446, 343447, 343448, 343449, 343450, 343451, 343452 + ], + [8203, 79, 8203, 8203, 8203, 0, 0, 0, 0, 0, 0, 8203, 80, 8205, 8205, 0, 0, 0, 0, 0, 0], + [49231, 216, 49232, 1, 49233, 0, 0, 0, 0, 0, 0, 49233, 224, 255, 247, 0, 0, 0, 0, 0, 0], + [0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0] ) } + + #[test] fn test_4() -> Field { main( 1, - [343672, 343673, 343674, 343675, 343676, 343677, 343678], - [8203, 79, 8203, 8203, 80, 8205, 8205], - [49231, 216, 49232, 49232, 224, 36, 36], - [0, 0, 1, 0, 0, 0, 1] + [ + 343432, 343433, 343434, 343435, 343436, 343437, 343438, 343439, 343440, 343441, 343442, 343443, 343444, 343445, 343446, 343447, 343448, 343449, 343450, 343451, 343452 + ], + [8203, 79, 8203, 8203, 8203, 0, 0, 0, 0, 0, 0, 8203, 80, 8205, 8205, 0, 0, 0, 0, 0, 0], + [49231, 216, 49232, 1, 49233, 0, 0, 0, 0, 0, 0, 49233, 224, 36, 36, 0, 0, 0, 0, 0, 0], + [0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0] ) } + #[test] fn test_5() -> Field { main( 1, - [343732, 343733, 343734, 343735, 343736, 343737, 343738], - [8203, 79, 8203, 8203, 80, 8205, 8205], - [49231, 216, 49232, 49232, 224, 40, 32], - [0, 0, 1, 0, 0, 0, 1] + [ + 343432, 343433, 343434, 343435, 343436, 343437, 343438, 343439, 343440, 343441, 343442, 343443, 343444, 343445, 343446, 343447, 343448, 343449, 343450, 343451, 343452 + ], + [8203, 79, 8203, 8203, 8203, 0, 0, 0, 0, 0, 0, 8203, 80, 8205, 8205, 0, 0, 0, 0, 0, 0], + [49231, 216, 49232, 1, 49233, 0, 0, 0, 0, 0, 0, 49233, 224, 40, 32, 0, 0, 0, 0, 0, 0], + [0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0] ) } - diff --git a/circuits/instr/cli/src/main.nr b/circuits/instr/cli/src/main.nr index 3bdd7bd..7f55513 100644 --- a/circuits/instr/cli/src/main.nr +++ b/circuits/instr/cli/src/main.nr @@ -10,60 +10,73 @@ use dep::std; fn main( r: Field, - op_sorted_step: [Field; 7], - op_sorted_addr: [Field; 7], - op_sorted_val: [Field; 7], - op_sorted_op_rw: [Field; 7] + op_sorted_step: [Field; 21], + op_sorted_addr: [Field; 21], + op_sorted_val: [Field; 21], + op_sorted_op_rw: [Field; 21] ) -> pub Field { - - //check the program counter + //check the program counter assert(op_sorted_addr[0] == 8203); assert(op_sorted_op_rw[0] == 0); let pc = op_sorted_val[0]; //check the opcode - assert(op_sorted_val[1] == 88); //0x58 - assert(op_sorted_op_rw[1] == 0); - + assert(op_sorted_val[1] == 88); //0x58 + assert(op_sorted_op_rw[1] == 0); + let opcode = op_sorted_val[1]; + //update the PC assert(op_sorted_addr[2] == 8203); assert(op_sorted_op_rw[2] == 1); assert(op_sorted_val[2] == pc + 1); + + //check the mode + assert(op_sorted_addr[3] == 8203); + assert(op_sorted_op_rw[3] == 0); + let _ = op_sorted_val[3]; + + //update the PC + assert(op_sorted_addr[4] == 8203); + assert(op_sorted_op_rw[4] == 1); + assert(op_sorted_val[4] == pc + 2); - let mut sub_arr_addr: [Field; 2] = [0,0]; - let mut sub_arr_val: [Field; 2] = [0,0]; - let mut sub_arr_op_rw: [Field; 2] = [0,0]; - let offset = 3; + // addressing + let mut sub_arr_addr: [Field; 8] = [0, 0, 0, 0, 0, 0, 0, 0]; + let mut sub_arr_val: [Field; 8] = [0, 0, 0, 0, 0, 0, 0, 0]; + let mut sub_arr_op_rw: [Field; 8] = [0, 0, 0, 0, 0, 0, 0, 0]; + let offset = 5; - for i in 0..2 { + for i in 0..8 { sub_arr_addr[i] = op_sorted_addr[offset + i]; sub_arr_val[i] = op_sorted_val[offset + i]; sub_arr_op_rw[i] = op_sorted_op_rw[offset + i]; } - helpers::imp( - sub_arr_addr, - sub_arr_val, - sub_arr_op_rw - ); + helpers::addressing_helpers(opcode, 0, sub_arr_addr, sub_arr_val, sub_arr_op_rw); //read status register - assert(op_sorted_addr[5] == 8205); - assert(op_sorted_op_rw[5] == 0); - let sr = op_sorted_val[5]; + assert(op_sorted_addr[13] == 8205); + assert(op_sorted_op_rw[13] == 0); + let sr = op_sorted_val[13]; let mut status = helpers::convert_to_status(sr); - + //clear the interrupt flag. status = helpers::clear_interrupt_bit(status); let comp_status = helpers::status_to_num(status); //write on status register - assert(op_sorted_addr[6] == 8205); - assert(op_sorted_op_rw[6] == 1); - assert(op_sorted_val[6] == comp_status); + assert(op_sorted_addr[14] == 8205); + assert(op_sorted_op_rw[14] == 1); + assert(op_sorted_val[14] == comp_status); + + for i in 15..21 { + assert(op_sorted_addr[i] == 0); + assert(op_sorted_op_rw[i] == 0); + assert(op_sorted_val[i] == 0); + } - helpers::compute_permutation_7( + helpers::compute_permutation_21( r, op_sorted_step, op_sorted_addr, @@ -72,66 +85,80 @@ fn main( ) } - #[test] fn test_0() -> Field { main( 1, - [343432, 343433, 343434, 343435, 343436, 343437, 343438], - [8203, 79, 8203, 8203, 80, 8205, 8205], - [49231, 88, 49232, 49232, 224, 36, 32], - [0, 0, 1, 0, 0, 0, 1] + [ + 343432, 343433, 343434, 343435, 343436, 343437, 343438, 343439, 343440, 343441, 343442, 343443, 343444, 343445, 343446, 343447, 343448, 343449, 343450, 343451, 343452 + ], + [8203, 79, 8203, 8203, 8203, 0, 0, 0, 0, 0, 0, 8203, 80, 8205, 8205, 0, 0, 0, 0, 0, 0], + [49231, 88, 49232, 1, 49233, 0, 0, 0, 0, 0, 0, 49233, 224, 36, 32, 0, 0, 0, 0, 0, 0], + [0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0] ) } + #[test] fn test_1() -> Field { main( 1, - [343492, 343493, 343494, 343495, 343496, 343497, 343498], - [8203, 79, 8203, 8203, 80, 8205, 8205], - [49231, 88, 49232, 49232, 224, 32, 32], - [0, 0, 1, 0, 0, 0, 1] + [ + 343432, 343433, 343434, 343435, 343436, 343437, 343438, 343439, 343440, 343441, 343442, 343443, 343444, 343445, 343446, 343447, 343448, 343449, 343450, 343451, 343452 + ], + [8203, 79, 8203, 8203, 8203, 0, 0, 0, 0, 0, 0, 8203, 80, 8205, 8205, 0, 0, 0, 0, 0, 0], + [49231, 88, 49232, 1, 49233, 0, 0, 0, 0, 0, 0, 49233, 224, 32, 32, 0, 0, 0, 0, 0, 0], + [0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0] ) } + #[test] fn test_2() -> Field { main( 1, - [343552, 343553, 343554, 343555, 343556, 343557, 343558], - [8203, 79, 8203, 8203, 80, 8205, 8205], - [49231, 88, 49232, 49232, 224, 132, 128], - [0, 0, 1, 0, 0, 0, 1] + [ + 343432, 343433, 343434, 343435, 343436, 343437, 343438, 343439, 343440, 343441, 343442, 343443, 343444, 343445, 343446, 343447, 343448, 343449, 343450, 343451, 343452 + ], + [8203, 79, 8203, 8203, 8203, 0, 0, 0, 0, 0, 0, 8203, 80, 8205, 8205, 0, 0, 0, 0, 0, 0], + [49231, 88, 49232, 1, 49233, 0, 0, 0, 0, 0, 0, 49233, 224, 132, 128, 0, 0, 0, 0, 0, 0], + [0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0] ) } + #[test] fn test_3() -> Field { main( 1, - [343612, 343613, 343614, 343615, 343616, 343617, 343618], - [8203, 79, 8203, 8203, 80, 8205, 8205], - [49231, 88, 49232, 49232, 224, 0, 0], - [0, 0, 1, 0, 0, 0, 1] + [ + 343432, 343433, 343434, 343435, 343436, 343437, 343438, 343439, 343440, 343441, 343442, 343443, 343444, 343445, 343446, 343447, 343448, 343449, 343450, 343451, 343452 + ], + [8203, 79, 8203, 8203, 8203, 0, 0, 0, 0, 0, 0, 8203, 80, 8205, 8205, 0, 0, 0, 0, 0, 0], + [49231, 88, 49232, 1, 49233, 0, 0, 0, 0, 0, 0, 49233, 224, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0] ) } + #[test] fn test_4() -> Field { main( 1, - [343672, 343673, 343674, 343675, 343676, 343677, 343678], - [8203, 79, 8203, 8203, 80, 8205, 8205], - [49231, 88, 49232, 49232, 224, 4, 0], - [0, 0, 1, 0, 0, 0, 1] + [ + 343432, 343433, 343434, 343435, 343436, 343437, 343438, 343439, 343440, 343441, 343442, 343443, 343444, 343445, 343446, 343447, 343448, 343449, 343450, 343451, 343452 + ], + [8203, 79, 8203, 8203, 8203, 0, 0, 0, 0, 0, 0, 8203, 80, 8205, 8205, 0, 0, 0, 0, 0, 0], + [49231, 88, 49232, 1, 49233, 0, 0, 0, 0, 0, 0, 49233, 224, 4, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0] ) } + #[test] fn test_5() -> Field { main( 1, - [343732, 343733, 343734, 343735, 343736, 343737, 343738], - [8203, 79, 8203, 8203, 80, 8205, 8205], - [49231, 88, 49232, 49232, 224, 2, 2], - [0, 0, 1, 0, 0, 0, 1] + [ + 343432, 343433, 343434, 343435, 343436, 343437, 343438, 343439, 343440, 343441, 343442, 343443, 343444, 343445, 343446, 343447, 343448, 343449, 343450, 343451, 343452 + ], + [8203, 79, 8203, 8203, 8203, 0, 0, 0, 0, 0, 0, 8203, 80, 8205, 8205, 0, 0, 0, 0, 0, 0], + [49231, 88, 49232, 1, 49233, 0, 0, 0, 0, 0, 0, 49233, 224, 2, 2, 0, 0, 0, 0, 0, 0], + [0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0] ) } - - diff --git a/circuits/instr/clv/src/main.nr b/circuits/instr/clv/src/main.nr index ffa12fe..a56b388 100644 --- a/circuits/instr/clv/src/main.nr +++ b/circuits/instr/clv/src/main.nr @@ -10,59 +10,73 @@ use dep::std; fn main( r: Field, - op_sorted_step: [Field; 7], - op_sorted_addr: [Field; 7], - op_sorted_val: [Field; 7], - op_sorted_op_rw: [Field; 7] + op_sorted_step: [Field; 21], + op_sorted_addr: [Field; 21], + op_sorted_val: [Field; 21], + op_sorted_op_rw: [Field; 21] ) -> pub Field { - - //check the program counter + //check the program counter assert(op_sorted_addr[0] == 8203); assert(op_sorted_op_rw[0] == 0); let pc = op_sorted_val[0]; //check the opcode - assert(op_sorted_val[1] == 184); //0xB8 - assert(op_sorted_op_rw[1] == 0); - + assert(op_sorted_val[1] == 184); //0xB8 + assert(op_sorted_op_rw[1] == 0); + let opcode = op_sorted_val[1]; + //update the PC assert(op_sorted_addr[2] == 8203); assert(op_sorted_op_rw[2] == 1); assert(op_sorted_val[2] == pc + 1); - let mut sub_arr_addr: [Field; 2] = [0,0]; - let mut sub_arr_val: [Field; 2] = [0,0]; - let mut sub_arr_op_rw: [Field; 2] = [0,0]; - let offset = 3; - for i in 0..2 { + //check the mode + assert(op_sorted_addr[3] == 8203); + assert(op_sorted_op_rw[3] == 0); + let _ = op_sorted_val[3]; + + //update the PC + assert(op_sorted_addr[4] == 8203); + assert(op_sorted_op_rw[4] == 1); + assert(op_sorted_val[4] == pc + 2); + + // addressing + let mut sub_arr_addr: [Field; 8] = [0, 0, 0, 0, 0, 0, 0, 0]; + let mut sub_arr_val: [Field; 8] = [0, 0, 0, 0, 0, 0, 0, 0]; + let mut sub_arr_op_rw: [Field; 8] = [0, 0, 0, 0, 0, 0, 0, 0]; + let offset = 5; + + for i in 0..8 { sub_arr_addr[i] = op_sorted_addr[offset + i]; sub_arr_val[i] = op_sorted_val[offset + i]; sub_arr_op_rw[i] = op_sorted_op_rw[offset + i]; } - helpers::imp( - sub_arr_addr, - sub_arr_val, - sub_arr_op_rw - ); + helpers::addressing_helpers(opcode, 0, sub_arr_addr, sub_arr_val, sub_arr_op_rw); //read status register - assert(op_sorted_addr[5] == 8205); - assert(op_sorted_op_rw[5] == 0); - let sr = op_sorted_val[5]; + assert(op_sorted_addr[13] == 8205); + assert(op_sorted_op_rw[13] == 0); + let sr = op_sorted_val[13]; let mut status = helpers::convert_to_status(sr); - + //clear the overflow flag. status = helpers::clear_overflow_bit(status); let comp_status = helpers::status_to_num(status); //write on status register - assert(op_sorted_addr[6] == 8205); - assert(op_sorted_op_rw[6] == 1); - assert(op_sorted_val[6] == comp_status); + assert(op_sorted_addr[14] == 8205); + assert(op_sorted_op_rw[14] == 1); + assert(op_sorted_val[14] == comp_status); + + for i in 15..21 { + assert(op_sorted_addr[i] == 0); + assert(op_sorted_op_rw[i] == 0); + assert(op_sorted_val[i] == 0); + } - helpers::compute_permutation_7( + helpers::compute_permutation_21( r, op_sorted_step, op_sorted_addr, @@ -75,61 +89,76 @@ fn main( fn test_0() -> Field { main( 1, - [343432, 343433, 343434, 343435, 343436, 343437, 343438], - [8203, 79, 8203, 8203, 80, 8205, 8205], - [49231, 184, 49232, 49232, 224, 38, 38], - [0, 0, 1, 0, 0, 0, 1] + [ + 343432, 343433, 343434, 343435, 343436, 343437, 343438, 343439, 343440, 343441, 343442, 343443, 343444, 343445, 343446, 343447, 343448, 343449, 343450, 343451, 343452 + ], + [8203, 79, 8203, 8203, 8203, 0, 0, 0, 0, 0, 0, 8203, 80, 8205, 8205, 0, 0, 0, 0, 0, 0], + [49231, 184, 49232, 1, 49233, 0, 0, 0, 0, 0, 0, 49233, 224, 38, 38, 0, 0, 0, 0, 0, 0], + [0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0] ) } + #[test] fn test_1() -> Field { main( 1, - [343492, 343493, 343494, 343495, 343496, 343497, 343498], - [8203, 79, 8203, 8203, 80, 8205, 8205], - [49231, 184, 49232, 49232, 224, 64, 0], - [0, 0, 1, 0, 0, 0, 1] + [ + 343432, 343433, 343434, 343435, 343436, 343437, 343438, 343439, 343440, 343441, 343442, 343443, 343444, 343445, 343446, 343447, 343448, 343449, 343450, 343451, 343452 + ], + [8203, 79, 8203, 8203, 8203, 0, 0, 0, 0, 0, 0, 8203, 80, 8205, 8205, 0, 0, 0, 0, 0, 0], + [49231, 184, 49232, 1, 49233, 0, 0, 0, 0, 0, 0, 49233, 224, 64, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0] ) } + #[test] fn test_2() -> Field { main( 1, - [343552, 343553, 343554, 343555, 343556, 343557, 343558], - [8203, 79, 8203, 8203, 80, 8205, 8205], - [49231, 184, 49232, 49232, 224, 128, 128], - [0, 0, 1, 0, 0, 0, 1] + [ + 343432, 343433, 343434, 343435, 343436, 343437, 343438, 343439, 343440, 343441, 343442, 343443, 343444, 343445, 343446, 343447, 343448, 343449, 343450, 343451, 343452 + ], + [8203, 79, 8203, 8203, 8203, 0, 0, 0, 0, 0, 0, 8203, 80, 8205, 8205, 0, 0, 0, 0, 0, 0], + [49231, 184, 49232, 1, 49233, 0, 0, 0, 0, 0, 0, 49233, 224, 128, 128, 0, 0, 0, 0, 0, 0], + [0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0] ) } + #[test] fn test_3() -> Field { main( 1, - [343612, 343613, 343614, 343615, 343616, 343617, 343618], - [8203, 79, 8203, 8203, 80, 8205, 8205], - [49231, 184, 49232, 49232, 224, 192, 128], - [0, 0, 1, 0, 0, 0, 1] + [ + 343432, 343433, 343434, 343435, 343436, 343437, 343438, 343439, 343440, 343441, 343442, 343443, 343444, 343445, 343446, 343447, 343448, 343449, 343450, 343451, 343452 + ], + [8203, 79, 8203, 8203, 8203, 0, 0, 0, 0, 0, 0, 8203, 80, 8205, 8205, 0, 0, 0, 0, 0, 0], + [49231, 184, 49232, 1, 49233, 0, 0, 0, 0, 0, 0, 49233, 224, 192, 128, 0, 0, 0, 0, 0, 0], + [0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0] ) } + #[test] fn test_4() -> Field { main( 1, - [343672, 343673, 343674, 343675, 343676, 343677, 343678], - [8203, 79, 8203, 8203, 80, 8205, 8205], - [49231, 184, 49232, 49232, 224, 36, 36], - [0, 0, 1, 0, 0, 0, 1] + [ + 343432, 343433, 343434, 343435, 343436, 343437, 343438, 343439, 343440, 343441, 343442, 343443, 343444, 343445, 343446, 343447, 343448, 343449, 343450, 343451, 343452 + ], + [8203, 79, 8203, 8203, 8203, 0, 0, 0, 0, 0, 0, 8203, 80, 8205, 8205, 0, 0, 0, 0, 0, 0], + [49231, 184, 49232, 1, 49233, 0, 0, 0, 0, 0, 0, 49233, 224, 36, 36, 0, 0, 0, 0, 0, 0], + [0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0] ) } + #[test] fn test_5() -> Field { main( 1, - [343732, 343733, 343734, 343735, 343736, 343737, 343738], - [8203, 79, 8203, 8203, 80, 8205, 8205], - [49231, 184, 49232, 49232, 224, 0, 0], - [0, 0, 1, 0, 0, 0, 1] + [ + 343432, 343433, 343434, 343435, 343436, 343437, 343438, 343439, 343440, 343441, 343442, 343443, 343444, 343445, 343446, 343447, 343448, 343449, 343450, 343451, 343452 + ], + [8203, 79, 8203, 8203, 8203, 0, 0, 0, 0, 0, 0, 8203, 80, 8205, 8205, 0, 0, 0, 0, 0, 0], + [49231, 184, 49232, 1, 49233, 0, 0, 0, 0, 0, 0, 49233, 224, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0] ) } - - diff --git a/circuits/instr/dec/src/main.nr b/circuits/instr/dec/src/main.nr index d3a22b9..fe969b7 100644 --- a/circuits/instr/dec/src/main.nr +++ b/circuits/instr/dec/src/main.nr @@ -10,10 +10,10 @@ use dep::std; fn main( r: Field, - op_sorted_step: [Field; 17], - op_sorted_addr: [Field; 17], - op_sorted_val: [Field; 17], - op_sorted_op_rw: [Field; 17] + op_sorted_step: [Field; 21], + op_sorted_addr: [Field; 21], + op_sorted_val: [Field; 21], + op_sorted_op_rw: [Field; 21] ) -> pub Field { //check the program counter assert(op_sorted_addr[0] == 8203); @@ -85,8 +85,14 @@ fn main( assert(op_sorted_addr[16] == 8205); assert(op_sorted_op_rw[16] == 1); assert(op_sorted_val[16] == comp_status); + + for i in 17..21 { + assert(op_sorted_addr[i] == 0); + assert(op_sorted_val[i] == 0); + assert(op_sorted_op_rw[i] == 0); + } - helpers::compute_permutation_17( + helpers::compute_permutation_21( r, op_sorted_step, op_sorted_addr, @@ -100,11 +106,11 @@ fn test_0() -> Field { main( 1, [ - 343432, 343433, 343434, 343435, 343436, 343437, 343438, 343439, 343440, 343441, 343442, 343443, 343444, 343445, 343446, 343447, 343448 + 343432, 343433, 343434, 343435, 343436, 343437, 343438, 343439, 343440, 343441, 343442, 343443, 343444, 343445, 343446, 343447, 343448 , 343449, 343450, 343451, 343452 ], - [8203, 79, 8203, 8203, 8203, 0, 0, 0, 0, 0, 8203, 49233, 8203, 8204, 8204, 8205, 8205], - [49231, 198, 49232, 1, 49233, 0, 0, 0, 0, 0, 49233, 13, 49234, 1, 0, 36, 38], - [0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1] + [8203, 79, 8203, 8203, 8203, 0, 0, 0, 0, 0, 8203, 49233, 8203, 8204, 8204, 8205, 8205 ,0,0,0,0], + [49231, 198, 49232, 1, 49233, 0, 0, 0, 0, 0, 49233, 13, 49234, 1, 0, 36, 38 ,0,0,0,0], + [0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1 ,0,0,0,0] ) } #[test] @@ -112,11 +118,11 @@ fn test_1() -> Field { main( 1, [ - 343492, 343493, 343494, 343495, 343496, 343497, 343498, 343499, 343500, 343501, 343502, 343503, 343504, 343505, 343506, 343507, 343508 + 343492, 343493, 343494, 343495, 343496, 343497, 343498, 343499, 343500, 343501, 343502, 343503, 343504, 343505, 343506, 343507, 343508 , 343509, 343510, 343511, 343512 ], - [8203, 79, 8203, 8203, 8203, 0, 0, 0, 8203, 49233, 8203, 13, 8202, 8204, 8204, 8205, 8205], - [49231, 214, 49232, 1, 49233, 0, 0, 0, 49233, 13, 49234, 0, 100, 2, 1, 36, 36], - [0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1] + [8203, 79, 8203, 8203, 8203, 0, 0, 0, 8203, 49233, 8203, 13, 8202, 8204, 8204, 8205, 8205 ,0,0,0,0], + [49231, 214, 49232, 1, 49233, 0, 0, 0, 49233, 13, 49234, 0, 100, 2, 1, 36, 36 ,0,0,0,0], + [0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1 ,0,0,0,0] ) } @@ -125,11 +131,11 @@ fn test_2() -> Field { main( 1, [ - 343552, 343553, 343554, 343555, 343556, 343557, 343558, 343559, 343560, 343561, 343562, 343563, 343564, 343565, 343566, 343567, 343568 + 343552, 343553, 343554, 343555, 343556, 343557, 343558, 343559, 343560, 343561, 343562, 343563, 343564, 343565, 343566, 343567, 343568 , 343569, 343570, 343571, 343572 ], - [8203, 79, 8203, 8203, 8203, 0, 0, 8203, 49233, 8203, 8203, 49234, 8203, 8204, 8204, 8205, 8205], - [49231, 206, 49232, 1, 49233, 0, 0, 49233, 1, 49234, 49234, 2, 49235, 4, 3, 36, 36], - [0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1, 0, 1] + [8203, 79, 8203, 8203, 8203, 0, 0, 8203, 49233, 8203, 8203, 49234, 8203, 8204, 8204, 8205, 8205 ,0,0,0,0], + [49231, 206, 49232, 1, 49233, 0, 0, 49233, 1, 49234, 49234, 2, 49235, 4, 3, 36, 36 ,0,0,0,0], + [0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1, 0, 1 ,0,0,0,0] ) } @@ -138,13 +144,13 @@ fn test_3() -> Field { main( 1, [ - 343612, 343613, 343614, 343615, 343616, 343617, 343618, 343619, 343620, 343621, 343622, 343623, 343624, 343625, 343626, 343627, 343628 + 343612, 343613, 343614, 343615, 343616, 343617, 343618, 343619, 343620, 343621, 343622, 343623, 343624, 343625, 343626, 343627, 343628 , 343629, 343630, 343631, 343632 ], [ - 8203, 79, 8203, 8203, 8203, 8203, 49233, 8203, 8203, 49234, 8203, 8202, 582, 8204, 8204, 8205, 8205 + 8203, 79, 8203, 8203, 8203, 8203, 49233, 8203, 8203, 49234, 8203, 8202, 582, 8204, 8204, 8205, 8205 ,0,0,0,0 ], - [49231, 222, 49232, 1, 49233, 49233, 1, 49234, 49234, 2, 49235, 69, 80, 5, 4, 36, 36], - [0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 1] + [49231, 222, 49232, 1, 49233, 49233, 1, 49234, 49234, 2, 49235, 69, 80, 5, 4, 36, 36 ,0,0,0,0], + [0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 1 ,0,0,0,0] ) } diff --git a/circuits/instr/dex/src/main.nr b/circuits/instr/dex/src/main.nr index 4009bb5..4eaa2bc 100644 --- a/circuits/instr/dex/src/main.nr +++ b/circuits/instr/dex/src/main.nr @@ -7,10 +7,10 @@ pub fn OPCODE_VALUE() -> Field { fn main( r: Field, - op_sorted_step: [Field; 9], - op_sorted_addr: [Field; 9], - op_sorted_val: [Field; 9], - op_sorted_op_rw: [Field; 9] + op_sorted_step: [Field; 21], + op_sorted_addr: [Field; 21], + op_sorted_val: [Field; 21], + op_sorted_op_rw: [Field; 21] ) -> pub Field { assert(op_sorted_addr[0] == PC_ADDR()); assert(op_sorted_op_rw[0] == 0); @@ -19,42 +19,55 @@ fn main( // this the address read value should be the opcode assert(op_sorted_val[1] == OPCODE_VALUE()); assert(op_sorted_op_rw[1] == 0); + let opcode = op_sorted_val[1]; //next update the PC assert(op_sorted_addr[2] == PC_ADDR()); assert(op_sorted_op_rw[2] == 1); assert(op_sorted_val[2] == pc + 1); - let mut sub_arr_addr: [Field; 2] = [0, 0]; - let mut sub_arr_val: [Field; 2] = [0, 0]; - let mut sub_arr_op_rw: [Field; 2] = [0, 0]; - let offset = 3; - for i in 0..2 { + //check the mode + assert(op_sorted_addr[3] == 8203); + assert(op_sorted_op_rw[3] == 0); + let _ = op_sorted_val[3]; + + //update the PC + assert(op_sorted_addr[4] == 8203); + assert(op_sorted_op_rw[4] == 1); + assert(op_sorted_val[4] == pc + 2); + + // addressing + let mut sub_arr_addr: [Field; 8] = [0, 0, 0, 0, 0, 0, 0, 0]; + let mut sub_arr_val: [Field; 8] = [0, 0, 0, 0, 0, 0, 0, 0]; + let mut sub_arr_op_rw: [Field; 8] = [0, 0, 0, 0, 0, 0, 0, 0]; + let offset = 5; + + for i in 0..8 { sub_arr_addr[i] = op_sorted_addr[offset + i]; sub_arr_val[i] = op_sorted_val[offset + i]; sub_arr_op_rw[i] = op_sorted_op_rw[offset + i]; } - helpers::imp(sub_arr_addr, sub_arr_val, sub_arr_op_rw); + helpers::addressing_helpers(opcode, 0, sub_arr_addr, sub_arr_val, sub_arr_op_rw); // we perform a read of x - assert(op_sorted_addr[5] == X_ADDR()); - assert(op_sorted_op_rw[5] == 0); - let value = op_sorted_val[5]; + assert(op_sorted_addr[13] == X_ADDR()); + assert(op_sorted_op_rw[13] == 0); + let value = op_sorted_val[13]; // we then perform a write of x - 1 - assert(op_sorted_addr[6] == X_ADDR()); - assert(op_sorted_op_rw[6] == 1); + assert(op_sorted_addr[14] == X_ADDR()); + assert(op_sorted_op_rw[14] == 1); let wdec = helpers::wrapping_dec_u8(value, 1); - assert(op_sorted_val[6] == wdec.value); + assert(op_sorted_val[14] == wdec.value); // we then set a new status into the status register // first there is a read from the status register - assert(op_sorted_addr[7] == SR_ADDR()); - assert(op_sorted_op_rw[7] == 0); - let sr = op_sorted_val[7]; + assert(op_sorted_addr[15] == SR_ADDR()); + assert(op_sorted_op_rw[15] == 0); + let sr = op_sorted_val[15]; let mut status = helpers::convert_to_status(sr); @@ -63,12 +76,18 @@ fn main( status = helpers::compute_zn_status(wdec.value, status); let comp_status = helpers::status_to_num(status); // 0x26 - assert(op_sorted_addr[8] == SR_ADDR()); - assert(op_sorted_op_rw[8] == 1); - assert(op_sorted_val[8] == comp_status); - + assert(op_sorted_addr[16] == SR_ADDR()); + assert(op_sorted_op_rw[16] == 1); + assert(op_sorted_val[16] == comp_status); + + for i in 17..21 { + assert(op_sorted_addr[i] == 0); + assert(op_sorted_val[i] == 0); + assert(op_sorted_op_rw[i] == 0); + } + // Compute permutation and return it - helpers::compute_permutation_9( + helpers::compute_permutation_21( r, op_sorted_step, op_sorted_addr, @@ -81,49 +100,63 @@ fn main( fn test_0() -> Field { main( 1, - [212536, 212537, 212538, 212539, 212540, 212541, 212542, 212543, 212544], - [PC_ADDR(), 55, PC_ADDR(), PC_ADDR(), 56, X_ADDR(), X_ADDR(), SR_ADDR(), SR_ADDR()], - [49207, OPCODE_VALUE(), 49208, 49208, 208, 0, 255, 38, 164], - [0, 0, 1, 0, 0, 0, 1, 0, 1] + [ + 343432, 343433, 343434, 343435, 343436, 343437, 343438, 343439, 343440, 343441, 343442, 343443, 343444, 343445, 343446, 343447, 343448, 343449, 343450, 343451, 343452 + ], + [8203, 79, 8203, 8203, 8203, 0, 0, 0, 0, 0, 0, 8203, 80,8201,8201, 8205, 8205, 0, 0, 0, 0], + [49231, 202, 49232, 1, 49233, 0, 0, 0, 0, 0, 0, 49233, 224,0, 255, 38, 164, 0, 0, 0, 0], + [0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0,0,1, 0, 1, 0, 0, 0, 0] ) } + #[test] fn test_1() -> Field { main( 1, - [212570, 212571, 212572, 212573, 212574, 212575, 212576, 212577, 212578], - [PC_ADDR(), 55, PC_ADDR(), PC_ADDR(), 56, X_ADDR(), X_ADDR(), SR_ADDR(), SR_ADDR()], - [49207, 202, 49208, 49208, 208, 255, 254, 164, 164], - [0, 0, 1, 0, 0, 0, 1, 0, 1] + [ + 343432, 343433, 343434, 343435, 343436, 343437, 343438, 343439, 343440, 343441, 343442, 343443, 343444, 343445, 343446, 343447, 343448, 343449, 343450, 343451, 343452 + ], + [8203, 79, 8203, 8203, 8203, 0, 0, 0, 0, 0, 0, 8203, 80,8201,8201, 8205, 8205, 0, 0, 0, 0], + [49231, 202, 49232, 1, 49233, 0, 0, 0, 0, 0, 0, 49233, 224,255,254, 164, 164, 0, 0, 0, 0], + [0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0,0,1, 0, 1, 0, 0, 0, 0] ) } + #[test] fn test_2() -> Field { main( 1, - [212604, 212605, 212606, 212607, 212608, 212609, 212610, 212611, 212612], - [PC_ADDR(), 55, PC_ADDR(), PC_ADDR(), 56, X_ADDR(), X_ADDR(), SR_ADDR(), SR_ADDR()], - [49207, 202, 49208, 49208, 208, 254, 253, 164, 164], - [0, 0, 1, 0, 0, 0, 1, 0, 1] + [ + 343432, 343433, 343434, 343435, 343436, 343437, 343438, 343439, 343440, 343441, 343442, 343443, 343444, 343445, 343446, 343447, 343448, 343449, 343450, 343451, 343452 + ], + [8203, 79, 8203, 8203, 8203, 0, 0, 0, 0, 0, 0, 8203, 80,8201,8201, 8205, 8205, 0, 0, 0, 0], + [49231, 202, 49232, 1, 49233, 0, 0, 0, 0, 0, 0, 49233, 224,254,253, 164, 164, 0, 0, 0, 0], + [0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0,0,1, 0, 1, 0, 0, 0, 0] ) } + #[test] fn test_3() -> Field { main( 1, - [212638, 212639, 212640, 212641, 212642, 212643, 212644, 212645, 212646], - [PC_ADDR(), 55, PC_ADDR(), PC_ADDR(), 56, X_ADDR(), X_ADDR(), SR_ADDR(), SR_ADDR()], - [49207, 202, 49208, 49208, 208, 253, 252, 164, 164], - [0, 0, 1, 0, 0, 0, 1, 0, 1] + [ + 343432, 343433, 343434, 343435, 343436, 343437, 343438, 343439, 343440, 343441, 343442, 343443, 343444, 343445, 343446, 343447, 343448, 343449, 343450, 343451, 343452 + ], + [8203, 79, 8203, 8203, 8203, 0, 0, 0, 0, 0, 0, 8203, 80,8201,8201, 8205, 8205, 0, 0, 0, 0], + [49231, 202, 49232, 1, 49233, 0, 0, 0, 0, 0, 0, 49233, 224,253,252, 164, 164, 0, 0, 0, 0], + [0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0,0,1, 0, 1, 0, 0, 0, 0] ) } + #[test] fn test_4() -> Field { main( 1, - [212672, 212673, 212674, 212675, 212676, 212677, 212678, 212679, 212680], - [PC_ADDR(), 55, PC_ADDR(), PC_ADDR(), 56, X_ADDR(), X_ADDR(), SR_ADDR(), SR_ADDR()], - [49207, 202, 49208, 49208, 208, 252, 251, 164, 164], - [0, 0, 1, 0, 0, 0, 1, 0, 1] + [ + 343432, 343433, 343434, 343435, 343436, 343437, 343438, 343439, 343440, 343441, 343442, 343443, 343444, 343445, 343446, 343447, 343448, 343449, 343450, 343451, 343452 + ], + [8203, 79, 8203, 8203, 8203, 0, 0, 0, 0, 0, 0, 8203, 80,8201,8201, 8205, 8205, 0, 0, 0, 0], + [49231, 202, 49232, 1, 49233, 0, 0, 0, 0, 0, 0, 49233, 224,252,251, 164, 164, 0, 0, 0, 0], + [0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0,0,1, 0, 1, 0, 0, 0, 0] ) } diff --git a/circuits/instr/dey/src/main.nr b/circuits/instr/dey/src/main.nr index 7dfeda7..8755d33 100644 --- a/circuits/instr/dey/src/main.nr +++ b/circuits/instr/dey/src/main.nr @@ -10,10 +10,10 @@ use dep::std; fn main( r: Field, - op_sorted_step: [Field; 9], - op_sorted_addr: [Field; 9], - op_sorted_val: [Field; 9], - op_sorted_op_rw: [Field; 9] + op_sorted_step: [Field; 21], + op_sorted_addr: [Field; 21], + op_sorted_val: [Field; 21], + op_sorted_op_rw: [Field; 21] ) -> pub Field { //check the program counter @@ -24,43 +24,52 @@ fn main( //check the opcode assert(op_sorted_val[1] == 136); //0x88 assert(op_sorted_op_rw[1] == 0); + let opcode = op_sorted_val[1]; //update the PC assert(op_sorted_addr[2] == 8203); assert(op_sorted_op_rw[2] == 1); assert(op_sorted_val[2] == pc + 1); + + //check the mode + assert(op_sorted_addr[3] == 8203); + assert(op_sorted_op_rw[3] == 0); + let _ = op_sorted_val[3]; + + //update the PC + assert(op_sorted_addr[4] == 8203); + assert(op_sorted_op_rw[4] == 1); + assert(op_sorted_val[4] == pc + 2); - let mut sub_arr_addr: [Field; 2] = [0,0]; - let mut sub_arr_val: [Field; 2] = [0,0]; - let mut sub_arr_op_rw: [Field; 2] = [0,0]; - let offset = 3; - for i in 0..2 { + // addressing + let mut sub_arr_addr: [Field; 8] = [0, 0, 0, 0, 0, 0, 0, 0]; + let mut sub_arr_val: [Field; 8] = [0, 0, 0, 0, 0, 0, 0, 0]; + let mut sub_arr_op_rw: [Field; 8] = [0, 0, 0, 0, 0, 0, 0, 0]; + let offset = 5; + + for i in 0..8 { sub_arr_addr[i] = op_sorted_addr[offset + i]; sub_arr_val[i] = op_sorted_val[offset + i]; sub_arr_op_rw[i] = op_sorted_op_rw[offset + i]; } - helpers::imp( - sub_arr_addr, - sub_arr_val, - sub_arr_op_rw - ); + helpers::addressing_helpers(opcode, 0, sub_arr_addr, sub_arr_val, sub_arr_op_rw); // read y - assert(op_sorted_addr[5] == 8202); - assert(op_sorted_op_rw[5] == 0); - let value = op_sorted_val[5]; + assert(op_sorted_addr[13] == 8202); + assert(op_sorted_op_rw[13] == 0); + let value = op_sorted_val[13]; // write y - assert(op_sorted_addr[6] == 8202); - assert(op_sorted_op_rw[6] == 1); + assert(op_sorted_addr[14] == 8202); + assert(op_sorted_op_rw[14] == 1); let wadd = helpers::wrapping_dec_u8(value, 1); - assert(op_sorted_val[6] == wadd.value); + assert(op_sorted_val[14] == wadd.value); //read status register - assert(op_sorted_addr[7] == 8205); - assert(op_sorted_op_rw[7] == 0); - let sr = op_sorted_val[7]; + assert(op_sorted_addr[15] == 8205); + assert(op_sorted_op_rw[15] == 0); + let sr = op_sorted_val[15]; let mut status = helpers::convert_to_status(sr); @@ -69,11 +78,17 @@ fn main( let comp_status = helpers::status_to_num(status); //write on status register - assert(op_sorted_addr[8] == 8205); - assert(op_sorted_op_rw[8] == 1); - assert(op_sorted_val[8] == comp_status); + assert(op_sorted_addr[16] == 8205); + assert(op_sorted_op_rw[16] == 1); + assert(op_sorted_val[16] == comp_status); + + for i in 17..21 { + assert(op_sorted_addr[i] == 0); + assert(op_sorted_val[i] == 0); + assert(op_sorted_op_rw[i] == 0); + } - helpers::compute_permutation_9( + helpers::compute_permutation_21( r, op_sorted_step, op_sorted_addr, @@ -87,60 +102,77 @@ fn main( fn test_0() -> Field { main( 1, - [343432, 343433, 343434, 343435, 343436, 343437, 343438, 343439, 343440], - [8203, 79, 8203, 8203, 80, 8202, 8202, 8205, 8205], - [49231, 136, 49232, 49232, 224, 127, 126, 36, 36], - [0, 0, 1, 0, 0, 0, 1, 0, 1] + [ + 343432, 343433, 343434, 343435, 343436, 343437, 343438, 343439, 343440, 343441, 343442, 343443, 343444, 343445, 343446, 343447, 343448, 343449, 343450, 343451, 343452 + ], + [8203, 79, 8203, 8203, 8203, 0, 0, 0, 0, 0, 0, 8203, 80,8202,8202, 8205, 8205, 0, 0, 0, 0], + [49231, 136, 49232, 1, 49233, 0, 0, 0, 0, 0, 0, 49233, 224,127,126, 36, 36, 0, 0, 0, 0], + [0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0,0,1, 0, 1, 0, 0, 0, 0] ) } + #[test] fn test_1() -> Field { main( 1, - [343492, 343493, 343494, 343495, 343496, 343497, 343498, 343499, 343500], - [8203, 79, 8203, 8203, 80, 8202, 8202, 8205, 8205], - [49231, 136, 49232, 49232, 224, 126, 125, 36, 36], - [0, 0, 1, 0, 0, 0, 1, 0, 1] + [ + 343432, 343433, 343434, 343435, 343436, 343437, 343438, 343439, 343440, 343441, 343442, 343443, 343444, 343445, 343446, 343447, 343448, 343449, 343450, 343451, 343452 + ], + [8203, 79, 8203, 8203, 8203, 0, 0, 0, 0, 0, 0, 8203, 80,8202,8202, 8205, 8205, 0, 0, 0, 0], + [49231, 136, 49232, 1, 49233, 0, 0, 0, 0, 0, 0, 49233, 224,126,125, 36, 36, 0, 0, 0, 0], + [0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0,0,1, 0, 1, 0, 0, 0, 0] ) } + #[test] fn test_2() -> Field { main( 1, - [343552, 343553, 343554, 343555, 343556, 343557, 343558, 343559, 343560], - [8203, 79, 8203, 8203, 80, 8202, 8202, 8205, 8205], - [49231, 136, 49232, 49232, 224, 125, 124, 36, 36], - [0, 0, 1, 0, 0, 0, 1, 0, 1] + [ + 343432, 343433, 343434, 343435, 343436, 343437, 343438, 343439, 343440, 343441, 343442, 343443, 343444, 343445, 343446, 343447, 343448, 343449, 343450, 343451, 343452 + ], + [8203, 79, 8203, 8203, 8203, 0, 0, 0, 0, 0, 0, 8203, 80,8202,8202, 8205, 8205, 0, 0, 0, 0], + [49231, 136, 49232, 1, 49233, 0, 0, 0, 0, 0, 0, 49233, 224,125,124, 36, 36, 0, 0, 0, 0], + [0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0,0,1, 0, 1, 0, 0, 0, 0] ) } + #[test] fn test_3() -> Field { main( 1, - [343612, 343613, 343614, 343615, 343616, 343617, 343618, 343619, 343620], - [8203, 79, 8203, 8203, 80, 8202, 8202, 8205, 8205], - [49231, 136, 49232, 49232, 224, 124, 123, 36, 36], - [0, 0, 1, 0, 0, 0, 1, 0, 1] + [ + 343432, 343433, 343434, 343435, 343436, 343437, 343438, 343439, 343440, 343441, 343442, 343443, 343444, 343445, 343446, 343447, 343448, 343449, 343450, 343451, 343452 + ], + [8203, 79, 8203, 8203, 8203, 0, 0, 0, 0, 0, 0, 8203, 80,8202,8202, 8205, 8205, 0, 0, 0, 0], + [49231, 136, 49232, 1, 49233, 0, 0, 0, 0, 0, 0, 49233, 224,124,123, 36, 36, 0, 0, 0, 0], + [0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0,0,1, 0, 1, 0, 0, 0, 0] ) } + #[test] fn test_4() -> Field { main( 1, - [343672, 343673, 343674, 343675, 343676, 343677, 343678, 343679, 343680], - [8203, 79, 8203, 8203, 80, 8202, 8202, 8205, 8205], - [49231, 136, 49232, 49232, 224, 123, 122, 36, 36], - [0, 0, 1, 0, 0, 0, 1, 0, 1] + [ + 343432, 343433, 343434, 343435, 343436, 343437, 343438, 343439, 343440, 343441, 343442, 343443, 343444, 343445, 343446, 343447, 343448, 343449, 343450, 343451, 343452 + ], + [8203, 79, 8203, 8203, 8203, 0, 0, 0, 0, 0, 0, 8203, 80,8202,8202, 8205, 8205, 0, 0, 0, 0], + [49231, 136, 49232, 1, 49233, 0, 0, 0, 0, 0, 0, 49233, 224,123,122, 36, 36, 0, 0, 0, 0], + [0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0,0,1, 0, 1, 0, 0, 0, 0] ) } + #[test] fn test_5() -> Field { main( 1, - [343732, 343733, 343734, 343735, 343736, 343737, 343738, 343739, 343740], - [8203, 79, 8203, 8203, 80, 8202, 8202, 8205, 8205], - [49231, 136, 49232, 49232, 224, 122, 121, 36, 36], - [0, 0, 1, 0, 0, 0, 1, 0, 1] + [ + 343432, 343433, 343434, 343435, 343436, 343437, 343438, 343439, 343440, 343441, 343442, 343443, 343444, 343445, 343446, 343447, 343448, 343449, 343450, 343451, 343452 + ], + [8203, 79, 8203, 8203, 8203, 0, 0, 0, 0, 0, 0, 8203, 80,8202,8202, 8205, 8205, 0, 0, 0, 0], + [49231, 136, 49232, 1, 49233, 0, 0, 0, 0, 0, 0, 49233, 224,122,121, 36, 36, 0, 0, 0, 0], + [0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0,0,1, 0, 1, 0, 0, 0, 0] ) } diff --git a/circuits/instr/inc/src/main.nr b/circuits/instr/inc/src/main.nr index 8840f85..32b67c2 100644 --- a/circuits/instr/inc/src/main.nr +++ b/circuits/instr/inc/src/main.nr @@ -10,10 +10,10 @@ use dep::std; fn main( r: Field, - op_sorted_step: [Field; 17], - op_sorted_addr: [Field; 17], - op_sorted_val: [Field; 17], - op_sorted_op_rw: [Field; 17] + op_sorted_step: [Field; 21], + op_sorted_addr: [Field; 21], + op_sorted_val: [Field; 21], + op_sorted_op_rw: [Field; 21] ) -> pub Field { //check the program counter assert(op_sorted_addr[0] == 8203); @@ -84,8 +84,14 @@ fn main( assert(op_sorted_addr[16] == 8205); assert(op_sorted_op_rw[16] == 1); assert(op_sorted_val[16] == comp_status); + + for i in 17..21{ + assert(op_sorted_addr[i] == 0); + assert(op_sorted_val[i] == 0); + assert(op_sorted_op_rw[i] == 0); + } - helpers::compute_permutation_17( + helpers::compute_permutation_21( r, op_sorted_step, op_sorted_addr, @@ -99,12 +105,11 @@ fn test_0() -> Field { main( 1, [ - 343432, 343433, 343434, 343435, 343436, 343437, 343438, 343439, 343440, 343441, 343442, 343443, 343444, 343445, 343446,343447, 343448 + 343432, 343433, 343434, 343435, 343436, 343437, 343438, 343439, 343440, 343441, 343442, 343443, 343444, 343445, 343446,343447, 343448 , 343449, 343450, 343451, 343452 ], - [8203, 79, 8203,8203,8203, 0, 0, 0, 0, 0, 8203, 49233, 8203, 8204, 8204, 8205, 8205], - // [49231, 230, 49232, 0, 0, 0, 0, 0, 49232, 13, 49233, 0, 1, 38, 36], - [49231, 230, 49232, 1, 49233, 0, 0, 0, 0, 0, 49233, 13, 49234, 0, 1, 38, 36], - [0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1] + [8203, 79, 8203,8203,8203, 0, 0, 0, 0, 0, 8203, 49233, 8203, 8204, 8204, 8205, 8205,0,0,0,0], + [49231, 230, 49232, 1, 49233, 0, 0, 0, 0, 0, 49233, 13, 49234, 0, 1, 38, 36,0,0,0,0], + [0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1,0,0,0,0] ) } #[test] @@ -112,12 +117,11 @@ fn test_1() -> Field { main( 1, [ - 343492, 343493, 343494, 343495, 343496, 343497, 343498, 343499, 343500, 343501, 343502, 343503, 343504, 343505, 343506, 343507, 343508 + 343492, 343493, 343494, 343495, 343496, 343497, 343498, 343499, 343500, 343501, 343502, 343503, 343504, 343505, 343506, 343507, 343508 , 343509, 343510, 343511, 343512 ], - [8203, 79, 8203,8203,8203, 0, 0, 0, 8203, 49233, 8203, 13, 8202, 8204, 8204, 8205, 8205], - // [49231, 246, 49232, 0, 0, 0, 49232, 13, 49233, 0, 100, 1, 2, 36, 36], - [49231, 246, 49232, 1, 49233, 0, 0, 0, 49233, 13, 49234, 0, 100, 1, 2, 36, 36], - [0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1] + [8203, 79, 8203,8203,8203, 0, 0, 0, 8203, 49233, 8203, 13, 8202, 8204, 8204, 8205, 8205,0,0,0,0], + [49231, 246, 49232, 1, 49233, 0, 0, 0, 49233, 13, 49234, 0, 100, 1, 2, 36, 36,0,0,0,0], + [0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1,0,0,0,0] ) } @@ -126,12 +130,11 @@ fn test_2() -> Field { main( 1, [ - 343552, 343553, 343554, 343555, 343556, 343557, 343558, 343559, 343560, 343561, 343562, 343563, 343564, 343565, 343566, 343567, 343568 + 343552, 343553, 343554, 343555, 343556, 343557, 343558, 343559, 343560, 343561, 343562, 343563, 343564, 343565, 343566, 343567, 343568 , 343569, 343570, 343571, 343572 ], - [8203, 79, 8203,8203,8203, 0, 0, 8203, 49233, 8203, 8203, 49234, 8203, 8204, 8204, 8205, 8205], - // [49231, 238, 49232, 0, 0, 49232, 1, 49233, 49233, 2, 49234, 2, 3, 36, 36], - [49231, 238, 49232, 1, 49233, 0, 0, 49233, 1, 49234, 49234, 2, 49235, 3, 4, 36, 36], - [0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1, 0, 1] + [8203, 79, 8203,8203,8203, 0, 0, 8203, 49233, 8203, 8203, 49234, 8203, 8204, 8204, 8205, 8205,0,0,0,0], + [49231, 238, 49232, 1, 49233, 0, 0, 49233, 1, 49234, 49234, 2, 49235, 3, 4, 36, 36,0,0,0,0], + [0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1, 0, 1,0,0,0,0] ) } @@ -140,11 +143,11 @@ fn test_3() -> Field { main( 1, [ - 343612, 343613, 343614, 343615, 343616, 343617, 343618, 343619, 343620, 343621, 343622, 343623, 343624, 343625, 343626, 343627, 343628 + 343612, 343613, 343614, 343615, 343616, 343617, 343618, 343619, 343620, 343621, 343622, 343623, 343624, 343625, 343626, 343627, 343628 , 343629, 343630, 343631, 343632 ], - [8203, 79, 8203,8203,8203, 8203, 49233, 8203, 8203, 49234, 8203, 8202, 582, 8204, 8204, 8205, 8205], - [49231, 254, 49232, 1, 49233, 49233, 1, 49234, 49234, 2, 49235, 69, 80, 4, 5, 36, 36], - [0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 1] + [8203, 79, 8203,8203,8203, 8203, 49233, 8203, 8203, 49234, 8203, 8202, 582, 8204, 8204, 8205, 8205,0,0,0,0], + [49231, 254, 49232, 1, 49233, 49233, 1, 49234, 49234, 2, 49235, 69, 80, 4, 5, 36, 36,0,0,0,0], + [0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 1,0,0,0,0] ) } diff --git a/circuits/instr/inx/src/main.nr b/circuits/instr/inx/src/main.nr index ca3b605..46bba89 100644 --- a/circuits/instr/inx/src/main.nr +++ b/circuits/instr/inx/src/main.nr @@ -8,10 +8,10 @@ pub fn OPCODE_VALUE() -> Field { fn main( r: Field, - op_sorted_step: [Field; 9], - op_sorted_addr: [Field; 9], - op_sorted_val: [Field; 9], - op_sorted_op_rw: [Field; 9] + op_sorted_step: [Field; 21], + op_sorted_addr: [Field; 21], + op_sorted_val: [Field; 21], + op_sorted_op_rw: [Field; 21] ) -> pub Field { assert(op_sorted_addr[0] == PC_ADDR()); assert(op_sorted_op_rw[0] == 0); @@ -26,46 +26,55 @@ fn main( // this the address read value should be the opcode assert(op_sorted_val[1] == OPCODE_VALUE()); - assert(op_sorted_op_rw[1] == 0); + assert(op_sorted_op_rw[1] == 0); + let opcode = op_sorted_val[1]; //next update the PC assert(op_sorted_addr[2] == PC_ADDR()); assert(op_sorted_op_rw[2] == 1); assert(op_sorted_val[2] == pc + 1); - let mut sub_arr_addr: [Field; 2] = [0,0]; - let mut sub_arr_val: [Field; 2] = [0,0]; - let mut sub_arr_op_rw: [Field; 2] = [0,0]; - let offset = 3; - for i in 0..2 { + //check the mode + assert(op_sorted_addr[3] == 8203); + assert(op_sorted_op_rw[3] == 0); + let _ = op_sorted_val[3]; + + //update the PC + assert(op_sorted_addr[4] == 8203); + assert(op_sorted_op_rw[4] == 1); + assert(op_sorted_val[4] == pc + 2); + + // addressing + let mut sub_arr_addr: [Field; 8] = [0, 0, 0, 0, 0, 0, 0, 0]; + let mut sub_arr_val: [Field; 8] = [0, 0, 0, 0, 0, 0, 0, 0]; + let mut sub_arr_op_rw: [Field; 8] = [0, 0, 0, 0, 0, 0, 0, 0]; + let offset = 5; + + for i in 0..8 { sub_arr_addr[i] = op_sorted_addr[offset + i]; sub_arr_val[i] = op_sorted_val[offset + i]; sub_arr_op_rw[i] = op_sorted_op_rw[offset + i]; } - helpers::imp( - sub_arr_addr, - sub_arr_val, - sub_arr_op_rw - ); + helpers::addressing_helpers(opcode, 0, sub_arr_addr, sub_arr_val, sub_arr_op_rw); // we perform a read of x - assert(op_sorted_addr[5] == X_ADDR()); - assert(op_sorted_op_rw[5] == 0); - let value = op_sorted_val[5]; + assert(op_sorted_addr[13] == X_ADDR()); + assert(op_sorted_op_rw[13] == 0); + let value = op_sorted_val[13]; // we then perform a write of x + 1 - assert(op_sorted_addr[6] == X_ADDR()); - assert(op_sorted_op_rw[6] == 1); + assert(op_sorted_addr[14] == X_ADDR()); + assert(op_sorted_op_rw[14] == 1); let wadd = helpers::wrapping_add_u8(value, 1); - assert(op_sorted_val[6] == wadd.value); + assert(op_sorted_val[14] == wadd.value); // we then set a new status into the status register // first there is a read from the status register - assert(op_sorted_addr[7] == SR_ADDR()); - assert(op_sorted_op_rw[7] == 0); - let sr = op_sorted_val[7]; + assert(op_sorted_addr[15] == SR_ADDR()); + assert(op_sorted_op_rw[15] == 0); + let sr = op_sorted_val[15]; // std::println(wadd); let mut status = helpers::convert_to_status(sr); @@ -75,12 +84,18 @@ fn main( status = helpers::compute_zn_status(wadd.value, status); let comp_status = helpers::status_to_num(status); // std::println(status); - assert(op_sorted_addr[8] == SR_ADDR()); - assert(op_sorted_op_rw[8] == 1); - assert(op_sorted_val[8] == comp_status); + assert(op_sorted_addr[16] == SR_ADDR()); + assert(op_sorted_op_rw[16] == 1); + assert(op_sorted_val[16] == comp_status); + + for i in 17..21 { + assert(op_sorted_addr[i] == 0); + assert(op_sorted_op_rw[i] == 0); + assert(op_sorted_val[i] == 0); + } // Compute permutation and return it - helpers::compute_permutation_9( + helpers::compute_permutation_21( r, op_sorted_step, op_sorted_addr, @@ -93,59 +108,76 @@ fn main( fn test_0() -> Field { main( 1, - [343432, 343433, 343434, 343435, 343436, 343437, 343438, 343439, 343440], - [PC_ADDR(), 79, PC_ADDR(), PC_ADDR(), 80, X_ADDR(), X_ADDR(), SR_ADDR(), SR_ADDR()], - [49231, OPCODE_VALUE(), 49232, OPCODE_VALUE(), 224, 0, 1, 36, 36], - [0, 0, 1, 0, 0, 0, 1, 0, 1] + [ + 343432, 343433, 343434, 343435, 343436, 343437, 343438, 343439, 343440, 343441, 343442, 343443, 343444, 343445, 343446, 343447, 343448, 343449, 343450, 343451, 343452 + ], + [8203, 79, 8203, 8203, 8203, 0, 0, 0, 0, 0, 0, 8203, 80,8201,8201, 8205, 8205, 0, 0, 0, 0], + [49231, 232, 49232, 1, 49233, 0, 0, 0, 0, 0, 0, 49233, 224,0,1, 36, 36, 0, 0, 0, 0], + [0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0,0,1, 0, 1, 0, 0, 0, 0] ) } + #[test] fn test_1() -> Field { main( 1, - [343492, 343493, 343494, 343495, 343496, 343497, 343498, 343499, 343500], - [PC_ADDR(), 79, PC_ADDR(), PC_ADDR(), 80, X_ADDR(), X_ADDR(), SR_ADDR(), SR_ADDR()], - [49231, OPCODE_VALUE(), 49232, 49232, 224, 1, 2, 36, 36], - [0, 0, 1, 0, 0, 0, 1, 0, 1] + [ + 343432, 343433, 343434, 343435, 343436, 343437, 343438, 343439, 343440, 343441, 343442, 343443, 343444, 343445, 343446, 343447, 343448, 343449, 343450, 343451, 343452 + ], + [8203, 79, 8203, 8203, 8203, 0, 0, 0, 0, 0, 0, 8203, 80,8201,8201, 8205, 8205, 0, 0, 0, 0], + [49231, 232, 49232, 1, 49233, 0, 0, 0, 0, 0, 0, 49233, 224,1,2, 36, 36, 0, 0, 0, 0], + [0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0,0,1, 0, 1, 0, 0, 0, 0] ) } + #[test] fn test_2() -> Field { main( 1, - [343552, 343553, 343554, 343555, 343556, 343557, 343558, 343559, 343560], - [PC_ADDR(), 79, PC_ADDR(), PC_ADDR(), 80, X_ADDR(), X_ADDR(), SR_ADDR(), SR_ADDR()], - [49231, OPCODE_VALUE(), 49232, 49232, 224, 2, 3, 36, 36], - [0, 0, 1, 0, 0, 0, 1, 0, 1] + [ + 343432, 343433, 343434, 343435, 343436, 343437, 343438, 343439, 343440, 343441, 343442, 343443, 343444, 343445, 343446, 343447, 343448, 343449, 343450, 343451, 343452 + ], + [8203, 79, 8203, 8203, 8203, 0, 0, 0, 0, 0, 0, 8203, 80,8201,8201, 8205, 8205, 0, 0, 0, 0], + [49231, 232, 49232, 1, 49233, 0, 0, 0, 0, 0, 0, 49233, 224,2,3, 36, 36, 0, 0, 0, 0], + [0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0,0,1, 0, 1, 0, 0, 0, 0] ) } + #[test] fn test_3() -> Field { main( 1, - [343612, 343613, 343614, 343615, 343616, 343617, 343618, 343619, 343620], - [PC_ADDR(), 79, PC_ADDR(), PC_ADDR(), 80, X_ADDR(), X_ADDR(), SR_ADDR(), SR_ADDR()], - [49231, OPCODE_VALUE(), 49232, 49232, 224, 3, 4, 36, 36], - [0, 0, 1, 0, 0, 0, 1, 0, 1] + [ + 343432, 343433, 343434, 343435, 343436, 343437, 343438, 343439, 343440, 343441, 343442, 343443, 343444, 343445, 343446, 343447, 343448, 343449, 343450, 343451, 343452 + ], + [8203, 79, 8203, 8203, 8203, 0, 0, 0, 0, 0, 0, 8203, 80,8201,8201, 8205, 8205, 0, 0, 0, 0], + [49231, 232, 49232, 1, 49233, 0, 0, 0, 0, 0, 0, 49233, 224,3,4, 36, 36, 0, 0, 0, 0], + [0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0,0,1, 0, 1, 0, 0, 0, 0] ) } + #[test] fn test_4() -> Field { main( 1, - [343672, 343673, 343674, 343675, 343676, 343677, 343678, 343679, 343680], - [PC_ADDR(), 79, PC_ADDR(), PC_ADDR(), 80, X_ADDR(), X_ADDR(), SR_ADDR(), SR_ADDR()], - [49231, OPCODE_VALUE(), 49232, 49232, 224, 4, 5, 36, 36], - [0, 0, 1, 0, 0, 0, 1, 0, 1] + [ + 343432, 343433, 343434, 343435, 343436, 343437, 343438, 343439, 343440, 343441, 343442, 343443, 343444, 343445, 343446, 343447, 343448, 343449, 343450, 343451, 343452 + ], + [8203, 79, 8203, 8203, 8203, 0, 0, 0, 0, 0, 0, 8203, 80,8201,8201, 8205, 8205, 0, 0, 0, 0], + [49231, 232, 49232, 1, 49233, 0, 0, 0, 0, 0, 0, 49233, 224,4,5, 36, 36, 0, 0, 0, 0], + [0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0,0,1, 0, 1, 0, 0, 0, 0] ) } + #[test] fn test_5() -> Field { main( 1, - [343732, 343733, 343734, 343735, 343736, 343737, 343738, 343739, 343740], - [PC_ADDR(), 79, PC_ADDR(), PC_ADDR(), 80, X_ADDR(), X_ADDR(), SR_ADDR(), SR_ADDR()], - [49231, OPCODE_VALUE(), 49232, 49232, 224, 5, 6, 36, 36], - [0, 0, 1, 0, 0, 0, 1, 0, 1] + [ + 343432, 343433, 343434, 343435, 343436, 343437, 343438, 343439, 343440, 343441, 343442, 343443, 343444, 343445, 343446, 343447, 343448, 343449, 343450, 343451, 343452 + ], + [8203, 79, 8203, 8203, 8203, 0, 0, 0, 0, 0, 0, 8203, 80,8201,8201, 8205, 8205, 0, 0, 0, 0], + [49231, 232, 49232, 1, 49233, 0, 0, 0, 0, 0, 0, 49233, 224,5,6, 36, 36, 0, 0, 0, 0], + [0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0,0,1, 0, 1, 0, 0, 0, 0] ) } \ No newline at end of file diff --git a/circuits/instr/iny/src/main.nr b/circuits/instr/iny/src/main.nr index 01bb223..64e06da 100644 --- a/circuits/instr/iny/src/main.nr +++ b/circuits/instr/iny/src/main.nr @@ -9,10 +9,10 @@ use dep::std; fn main( r: Field, - op_sorted_step: [Field; 9], - op_sorted_addr: [Field; 9], - op_sorted_val: [Field; 9], - op_sorted_op_rw: [Field; 9] + op_sorted_step: [Field; 21], + op_sorted_addr: [Field; 21], + op_sorted_val: [Field; 21], + op_sorted_op_rw: [Field; 21] ) -> pub Field { //check the program counter @@ -23,43 +23,52 @@ fn main( //check the opcode assert(op_sorted_val[1] == 200); //0xc8 assert(op_sorted_op_rw[1] == 0); + let opcode = op_sorted_val[1]; //update the PC assert(op_sorted_addr[2] == 8203); assert(op_sorted_op_rw[2] == 1); assert(op_sorted_val[2] == pc + 1); - let mut sub_arr_addr: [Field; 2] = [0,0]; - let mut sub_arr_val: [Field; 2] = [0,0]; - let mut sub_arr_op_rw: [Field; 2] = [0,0]; - let offset = 3; - for i in 0..2 { + //check the mode + assert(op_sorted_addr[3] == 8203); + assert(op_sorted_op_rw[3] == 0); + let _ = op_sorted_val[3]; + + //update the PC + assert(op_sorted_addr[4] == 8203); + assert(op_sorted_op_rw[4] == 1); + assert(op_sorted_val[4] == pc + 2); + + // addressing + let mut sub_arr_addr: [Field; 8] = [0, 0, 0, 0, 0, 0, 0, 0]; + let mut sub_arr_val: [Field; 8] = [0, 0, 0, 0, 0, 0, 0, 0]; + let mut sub_arr_op_rw: [Field; 8] = [0, 0, 0, 0, 0, 0, 0, 0]; + let offset = 5; + + for i in 0..8 { sub_arr_addr[i] = op_sorted_addr[offset + i]; sub_arr_val[i] = op_sorted_val[offset + i]; sub_arr_op_rw[i] = op_sorted_op_rw[offset + i]; } - helpers::imp( - sub_arr_addr, - sub_arr_val, - sub_arr_op_rw - ); + helpers::addressing_helpers(opcode, 0, sub_arr_addr, sub_arr_val, sub_arr_op_rw); // read y - assert(op_sorted_addr[5] == 8202); - assert(op_sorted_op_rw[5] == 0); - let value = op_sorted_val[5]; + assert(op_sorted_addr[13] == 8202); + assert(op_sorted_op_rw[13] == 0); + let value = op_sorted_val[13]; // write y - assert(op_sorted_addr[6] == 8202); - assert(op_sorted_op_rw[6] == 1); + assert(op_sorted_addr[14] == 8202); + assert(op_sorted_op_rw[14] == 1); let wadd = helpers::wrapping_add_u8(value, 1); - assert(op_sorted_val[6] == wadd.value); + assert(op_sorted_val[14] == wadd.value); //read staus register - assert(op_sorted_addr[7] == 8205); - assert(op_sorted_op_rw[7] == 0); - let sr = op_sorted_val[7]; + assert(op_sorted_addr[15] == 8205); + assert(op_sorted_op_rw[15] == 0); + let sr = op_sorted_val[15]; let mut status = helpers::convert_to_status(sr); @@ -68,11 +77,17 @@ fn main( let comp_status = helpers::status_to_num(status); //write on status register - assert(op_sorted_addr[8] == 8205); - assert(op_sorted_op_rw[8] == 1); - assert(op_sorted_val[8] == comp_status); + assert(op_sorted_addr[16] == 8205); + assert(op_sorted_op_rw[16] == 1); + assert(op_sorted_val[16] == comp_status); + + for i in 17..21 { + assert(op_sorted_addr[i] == 0); + assert(op_sorted_val[i] == 0); + assert(op_sorted_op_rw[i] == 0); + } - helpers::compute_permutation_9( + helpers::compute_permutation_21( r, op_sorted_step, op_sorted_addr, @@ -85,60 +100,77 @@ fn main( fn test_0() -> Field { main( 1, - [343432, 343433, 343434, 343435, 343436, 343437, 343438, 343439, 343440], - [8203, 79, 8203, 8203, 80, 8202, 8202, 8205, 8205], - [49231, 200, 49232, 49232, 224, 0, 1, 38, 36], - [0, 0, 1, 0, 0, 0, 1, 0, 1] + [ + 343432, 343433, 343434, 343435, 343436, 343437, 343438, 343439, 343440, 343441, 343442, 343443, 343444, 343445, 343446, 343447, 343448, 343449, 343450, 343451, 343452 + ], + [8203, 79, 8203, 8203, 8203, 0, 0, 0, 0, 0, 0, 8203, 80,8202,8202, 8205, 8205, 0, 0, 0, 0], + [49231, 200, 49232, 1, 49233, 0, 0, 0, 0, 0, 0, 49233, 224,0,1, 36, 36, 0, 0, 0, 0], + [0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0,0,1, 0, 1, 0, 0, 0, 0] ) } + #[test] fn test_1() -> Field { main( 1, - [343492, 343493, 343494, 343495, 343496, 343497, 343498, 343499, 343500], - [8203, 79, 8203, 8203, 80, 8202, 8202, 8205, 8205], - [49231, 200, 49232, 49232, 224, 1, 2, 36, 36], - [0, 0, 1, 0, 0, 0, 1, 0, 1] + [ + 343432, 343433, 343434, 343435, 343436, 343437, 343438, 343439, 343440, 343441, 343442, 343443, 343444, 343445, 343446, 343447, 343448, 343449, 343450, 343451, 343452 + ], + [8203, 79, 8203, 8203, 8203, 0, 0, 0, 0, 0, 0, 8203, 80,8202,8202, 8205, 8205, 0, 0, 0, 0], + [49231, 200, 49232, 1, 49233, 0, 0, 0, 0, 0, 0, 49233, 224,1,2, 36, 36, 0, 0, 0, 0], + [0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0,0,1, 0, 1, 0, 0, 0, 0] ) } + #[test] fn test_2() -> Field { main( 1, - [343552, 343553, 343554, 343555, 343556, 343557, 343558, 343559, 343560], - [8203, 79, 8203, 8203, 80, 8202, 8202, 8205, 8205], - [49231, 200, 49232, 49232, 224, 2, 3, 36, 36], - [0, 0, 1, 0, 0, 0, 1, 0, 1] + [ + 343432, 343433, 343434, 343435, 343436, 343437, 343438, 343439, 343440, 343441, 343442, 343443, 343444, 343445, 343446, 343447, 343448, 343449, 343450, 343451, 343452 + ], + [8203, 79, 8203, 8203, 8203, 0, 0, 0, 0, 0, 0, 8203, 80,8202,8202, 8205, 8205, 0, 0, 0, 0], + [49231, 200, 49232, 1, 49233, 0, 0, 0, 0, 0, 0, 49233, 224,2,3, 36, 36, 0, 0, 0, 0], + [0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0,0,1, 0, 1, 0, 0, 0, 0] ) } + #[test] fn test_3() -> Field { main( 1, - [343612, 343613, 343614, 343615, 343616, 343617, 343618, 343619, 343620], - [8203, 79, 8203, 8203, 80, 8202, 8202, 8205, 8205], - [49231, 200, 49232, 49232, 224, 3, 4, 36, 36], - [0, 0, 1, 0, 0, 0, 1, 0, 1] + [ + 343432, 343433, 343434, 343435, 343436, 343437, 343438, 343439, 343440, 343441, 343442, 343443, 343444, 343445, 343446, 343447, 343448, 343449, 343450, 343451, 343452 + ], + [8203, 79, 8203, 8203, 8203, 0, 0, 0, 0, 0, 0, 8203, 80,8202,8202, 8205, 8205, 0, 0, 0, 0], + [49231, 200, 49232, 1, 49233, 0, 0, 0, 0, 0, 0, 49233, 224,3,4, 36, 36, 0, 0, 0, 0], + [0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0,0,1, 0, 1, 0, 0, 0, 0] ) } + #[test] fn test_4() -> Field { main( 1, - [343672, 343673, 343674, 343675, 343676, 343677, 343678, 343679, 343680], - [8203, 79, 8203, 8203, 80, 8202, 8202, 8205, 8205], - [49231, 200, 49232, 49232, 224, 4, 5, 36, 36], - [0, 0, 1, 0, 0, 0, 1, 0, 1] + [ + 343432, 343433, 343434, 343435, 343436, 343437, 343438, 343439, 343440, 343441, 343442, 343443, 343444, 343445, 343446, 343447, 343448, 343449, 343450, 343451, 343452 + ], + [8203, 79, 8203, 8203, 8203, 0, 0, 0, 0, 0, 0, 8203, 80,8202,8202, 8205, 8205, 0, 0, 0, 0], + [49231, 200, 49232, 1, 49233, 0, 0, 0, 0, 0, 0, 49233, 224,4,5, 36, 36, 0, 0, 0, 0], + [0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0,0,1, 0, 1, 0, 0, 0, 0] ) } + #[test] fn test_5() -> Field { main( 1, - [343732, 343733, 343734, 343735, 343736, 343737, 343738, 343739, 343740], - [8203, 79, 8203, 8203, 80, 8202, 8202, 8205, 8205], - [49231, 200, 49232, 49232, 224, 5, 6, 36, 36], - [0, 0, 1, 0, 0, 0, 1, 0, 1] + [ + 343432, 343433, 343434, 343435, 343436, 343437, 343438, 343439, 343440, 343441, 343442, 343443, 343444, 343445, 343446, 343447, 343448, 343449, 343450, 343451, 343452 + ], + [8203, 79, 8203, 8203, 8203, 0, 0, 0, 0, 0, 0, 8203, 80,8202,8202, 8205, 8205, 0, 0, 0, 0], + [49231, 200, 49232, 1, 49233, 0, 0, 0, 0, 0, 0, 49233, 224,5,6, 36, 36, 0, 0, 0, 0], + [0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0,0,1, 0, 1, 0, 0, 0, 0] ) } diff --git a/circuits/instr/lda/src/main.nr b/circuits/instr/lda/src/main.nr index b416c85..aef5d23 100644 --- a/circuits/instr/lda/src/main.nr +++ b/circuits/instr/lda/src/main.nr @@ -10,10 +10,10 @@ use dep::std; fn main( r: Field, - op_sorted_step: [Field; 17], - op_sorted_addr: [Field; 17], - op_sorted_val: [Field; 17], - op_sorted_op_rw: [Field; 17] + op_sorted_step: [Field; 21], + op_sorted_addr: [Field; 21], + op_sorted_val: [Field; 21], + op_sorted_op_rw: [Field; 21] ) -> pub Field { //check the program counter assert(op_sorted_addr[0] == 8203); @@ -85,8 +85,14 @@ fn main( assert(op_sorted_addr[16] == 8205); assert(op_sorted_op_rw[16] == 1); assert(op_sorted_val[16] == comp_status); + + for i in 17..21 { + assert(op_sorted_addr[i] == 0); + assert(op_sorted_val[i] == 0); + assert(op_sorted_op_rw[i] == 0); + } - helpers::compute_permutation_17( + helpers::compute_permutation_21( r, op_sorted_step, op_sorted_addr, @@ -100,11 +106,11 @@ fn test_0() -> Field { main( 1, [ - 343432, 343433, 343434, 343435, 343436, 343437, 343438, 343439, 343440, 343441, 343442, 343443, 343444, 343445, 343446,343447, 343448 + 343432, 343433, 343434, 343435, 343436, 343437, 343438, 343439, 343440, 343441, 343442, 343443, 343444, 343445, 343446,343447, 343448, 343449, 343450, 343451, 343452 ], - [8203, 79, 8203,8203,8203, 0, 0, 0, 0, 0,0,8203,8203,8204,8200,8205,8205], - [49231, 169, 49232, 1, 49233, 0, 0, 0, 0, 0,0,49233,49234,34,34,36,36], - [0, 0, 1, 0, 1, 0, 0, 0, 0, 0,0,0,1,0,1,0,1] + [8203, 79, 8203,8203,8203, 0, 0, 0, 0, 0,0,8203,8203,8204,8200,8205,8205,0,0,0,0], + [49231, 169, 49232, 1, 49233, 0, 0, 0, 0, 0,0,49233,49234,34,34,36,36,0,0,0,0], + [0, 0, 1, 0, 1, 0, 0, 0, 0, 0,0,0,1,0,1,0,1,0,0,0,0] ) } @@ -113,11 +119,11 @@ fn test_1() -> Field { main( 1, [ - 343492, 343493, 343494, 343495, 343496, 343497, 343498, 343499, 343500, 343501, 343502, 343503, 343504, 343505, 343506, 343507, 343508 + 343492, 343493, 343494, 343495, 343496, 343497, 343498, 343499, 343500, 343501, 343502, 343503, 343504, 343505, 343506, 343507, 343508 ,343509, 343510, 343511, 343512 ], - [8203, 79, 8203,8203,8203, 0, 0, 0,0,0,8203,49233,8203 ,8204,8200,8205,8205], - [49231, 165 , 49232, 1, 49233, 0, 0, 0,0,0, 49233,69,49234,34,34,36,36], - [0, 0, 1, 0, 1, 0, 0, 0,0,0,0,0,1,0,1,0,1] + [8203, 79, 8203,8203,8203, 0, 0, 0,0,0,8203,49233,8203 ,8204,8200,8205,8205,0,0,0,0], + [49231, 165 , 49232, 1, 49233, 0, 0, 0,0,0, 49233,69,49234,34,34,36,36,0,0,0,0], + [0, 0, 1, 0, 1, 0, 0, 0,0,0,0,0,1,0,1,0,1,0,0,0,0] ) } @@ -126,11 +132,11 @@ fn test_2() -> Field { main( 1, [ - 343552, 343553, 343554, 343555, 343556, 343557, 343558, 343559, 343560, 343561, 343562, 343563, 343564, 343565, 343566, 343567, 343568 + 343552, 343553, 343554, 343555, 343556, 343557, 343558, 343559, 343560, 343561, 343562, 343563, 343564, 343565, 343566, 343567, 343568 ,343569, 343570, 343571, 343572 ], - [8203, 79, 8203,8203,8203,0,0,0,8203,49233,8203,13,8202,8204,8200,8205,8205], - [49231, 181, 49232, 1, 49233,0,0,0,49233,13,49234,0,69,34,34,36,36 ], - [0, 0, 1, 0, 1,0,0,0,0,0,1,0,0,0,1,0,1] + [8203, 79, 8203,8203,8203,0,0,0,8203,49233,8203,13,8202,8204,8200,8205,8205,0,0,0,0], + [49231, 181, 49232, 1, 49233,0,0,0,49233,13,49234,0,69,34,34,36,36,0,0,0,0], + [0, 0, 1, 0, 1,0,0,0,0,0,1,0,0,0,1,0,1,0,0,0,0] ) } @@ -139,11 +145,11 @@ fn test_3() -> Field { main( 1, [ - 343612, 343613, 343614, 343615, 343616, 343617, 343618, 343619, 343620, 343621, 343622, 343623, 343624, 343625, 343626, 343627, 343628 + 343612, 343613, 343614, 343615, 343616, 343617, 343618, 343619, 343620, 343621, 343622, 343623, 343624, 343625, 343626, 343627, 343628 , 343629, 343630, 343631, 343632 ], - [8203, 79, 8203,8203,8203,0,0,8203,49233,8203,8203,49234, 8203,8204,8200,8205,8205 ], - [49231, 173, 49232, 1, 49233,0,0,49233,1,49234,49234,2,49235,34,34,36,36], - [0, 0, 1, 0, 1,0,0,0,0,1,0,0,1, 0,1,0,1] + [8203, 79, 8203,8203,8203,0,0,8203,49233,8203,8203,49234, 8203,8204,8200,8205,8205,0,0,0,0], + [49231, 173, 49232, 1, 49233,0,0,49233,1,49234,49234,2,49235,34,34,36,36,0,0,0,0], + [0, 0, 1, 0, 1,0,0,0,0,1,0,0,1, 0,1,0,1,0,0,0,0] ) } @@ -152,11 +158,11 @@ fn test_4() -> Field { main( 1, [ - 343712, 343713, 343714, 343715, 343716, 343717, 343718, 343719, 343720, 343721, 343722, 343723, 343724, 343725, 343726, 343727, 343728 + 343712, 343713, 343714, 343715, 343716, 343717, 343718, 343719, 343720, 343721, 343722, 343723, 343724, 343725, 343726, 343727, 343728 , 343729, 343730, 343731, 343732 ], - [8203,79,8203,8203,8203,8203, 49233, 8203, 8203, 49234, 8203, 8201, 582,8204,8200,8205,8205], - [49231,189, 49232,0,49233,49233, 1, 49234, 49234, 2, 49235, 69, 80,34,34,36,36], - [0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0,1,0,1] + [8203,79,8203,8203,8203,8203, 49233, 8203, 8203, 49234, 8203, 8201, 582,8204,8200,8205,8205,0,0,0,0], + [49231,189, 49232,0,49233,49233, 1, 49234, 49234, 2, 49235, 69, 80,34,34,36,36,0,0,0,0], + [0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0,1,0,1,0,0,0,0] ) } @@ -165,11 +171,11 @@ fn test_5() -> Field { main( 1, [ - 343812, 343813, 343814, 343815, 343816, 343817, 343818, 343819, 343820, 343821, 343822, 343823, 343824, 343825, 343826, 343827, 343828 + 343812, 343813, 343814, 343815, 343816, 343817, 343818, 343819, 343820, 343821, 343822, 343823, 343824, 343825, 343826, 343827, 343828 , 343829, 343830, 343831, 343832 ], - [8203,79,8203,8203,8203,8203, 49233, 8203, 8203, 49234, 8203, 8202, 582,8204,8200,8205,8205], - [49231,185, 49232,1,49233,49233, 1, 49234, 49234, 2, 49235, 69, 80,34,34,36,36], - [0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0,1,0,1] + [8203,79,8203,8203,8203,8203, 49233, 8203, 8203, 49234, 8203, 8202, 582,8204,8200,8205,8205,0,0,0,0], + [49231,185, 49232,1,49233,49233, 1, 49234, 49234, 2, 49235, 69, 80,34,34,36,36,0,0,0,0], + [0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0,1,0,1,0,0,0,0] ) } @@ -178,11 +184,11 @@ fn test_6() -> Field { main( 1, [ - 343912, 343913, 343914, 343915, 343916, 343917, 343918, 343919, 343920, 343921, 343922, 343923, 343924, 343925, 343926, 343927, 343928 + 343912, 343913, 343914, 343915, 343916, 343917, 343918, 343919, 343920, 343921, 343922, 343923, 343924, 343925, 343926, 343927, 343928 , 343929, 343930, 343931, 343932 ], - [8203,79,8203,8203,8203,0,8203,49233,8203,5675,8201,5688,5689,8204,8200,8205,8205], - [49231,161, 49232,0,49233,0,49233,5675,5676,69,13,1,2,34,34,36,36], - [0, 0, 1, 0, 1,0,0,0,1,0,0,0,0 ,0,1,0,1] + [8203,79,8203,8203,8203,0,8203,49233,8203,5675,8201,5688,5689,8204,8200,8205,8205,0,0,0,0], + [49231,161, 49232,0,49233,0,49233,5675,5676,69,13,1,2,34,34,36,36,0,0,0,0], + [0, 0, 1, 0, 1,0,0,0,1,0,0,0,0 ,0,1,0,1,0,0,0,0] ) } @@ -191,10 +197,10 @@ fn test_7() -> Field { main( 1, [ - 343912, 343913, 343914, 343915, 343916, 343917, 343918, 343919, 343920, 343921, 343922, 343923, 343924, 343925, 343926, 343927, 343928 + 343912, 343913, 343914, 343915, 343916, 343917, 343918, 343919, 343920, 343921, 343922, 343923, 343924, 343925, 343926, 343927, 343928 , 343929, 343930, 343931, 343932 ], - [8203,79,8203,8203,8203,0,8203,49233,8203,5675,5676,8202,582,8204,8200,8205,8205], - [49231,177, 49232,0,49233,0,49233,5675,5676,1,2,69,112,34,34,36,36], - [0, 0, 1, 0, 1,0,0,0,1,0,0,0,0,0,1,0,1] + [8203,79,8203,8203,8203,0,8203,49233,8203,5675,5676,8202,582,8204,8200,8205,8205,0,0,0,0], + [49231,177, 49232,0,49233,0,49233,5675,5676,1,2,69,112,34,34,36,36,0,0,0,0], + [0, 0, 1, 0, 1,0,0,0,1,0,0,0,0,0,1,0,1,0,0,0,0] ) } \ No newline at end of file diff --git a/circuits/instr/ldx/src/main.nr b/circuits/instr/ldx/src/main.nr index 26637fc..ab38e10 100644 --- a/circuits/instr/ldx/src/main.nr +++ b/circuits/instr/ldx/src/main.nr @@ -10,10 +10,10 @@ use dep::std; fn main( r: Field, - op_sorted_step: [Field; 17], - op_sorted_addr: [Field; 17], - op_sorted_val: [Field; 17], - op_sorted_op_rw: [Field; 17] + op_sorted_step: [Field; 21], + op_sorted_addr: [Field; 21], + op_sorted_val: [Field; 21], + op_sorted_op_rw: [Field; 21] ) -> pub Field { //check the program counter assert(op_sorted_addr[0] == 8203); @@ -83,8 +83,14 @@ fn main( assert(op_sorted_addr[16] == 8205); assert(op_sorted_op_rw[16] == 1); assert(op_sorted_val[16] == comp_status); + + for i in 17..21 { + assert(op_sorted_addr[i] == 0); + assert(op_sorted_val[i] == 0); + assert(op_sorted_op_rw[i] == 0); + } - helpers::compute_permutation_17( + helpers::compute_permutation_21( r, op_sorted_step, op_sorted_addr, @@ -98,11 +104,11 @@ fn test_0() -> Field { main( 1, [ - 343432, 343433, 343434, 343435, 343436, 343437, 343438, 343439, 343440, 343441, 343442, 343443, 343444, 343445, 343446,343447, 343448 + 343432, 343433, 343434, 343435, 343436, 343437, 343438, 343439, 343440, 343441, 343442, 343443, 343444, 343445, 343446,343447, 343448 , 343449, 343450, 343451, 343452 ], - [8203, 79, 8203,8203,8203, 0, 0, 0, 0, 0,0,8203,8203,8204,8201,8205,8205], - [49231, 162, 49232, 1, 49233, 0, 0, 0, 0, 0,0,49233,49234,34,34,36,36], - [0, 0, 1, 0, 1, 0, 0, 0, 0, 0,0,0,1,0,1,0,1] + [8203, 79, 8203,8203,8203, 0, 0, 0, 0, 0,0,8203,8203,8204,8201,8205,8205,0,0,0,0], + [49231, 162, 49232, 1, 49233, 0, 0, 0, 0, 0,0,49233,49234,34,34,36,36,0,0,0,0], + [0, 0, 1, 0, 1, 0, 0, 0, 0, 0,0,0,1,0,1,0,1,0,0,0,0] ) } @@ -111,11 +117,11 @@ fn test_1() -> Field { main( 1, [ - 343492, 343493, 343494, 343495, 343496, 343497, 343498, 343499, 343500, 343501, 343502, 343503, 343504, 343505, 343506, 343507, 343508 + 343492, 343493, 343494, 343495, 343496, 343497, 343498, 343499, 343500, 343501, 343502, 343503, 343504, 343505, 343506, 343507, 343508 , 343509, 343510, 343511, 343512 ], - [8203, 79, 8203,8203,8203, 0, 0, 0,0,0,8203,49233,8203 ,8204,8201,8205,8205], - [49231, 166 , 49232, 1, 49233, 0, 0, 0,0,0, 49233,69,49234,34,34,36,36], - [0, 0, 1, 0, 1, 0, 0, 0,0,0,0,0,1,0,1,0,1] + [8203, 79, 8203,8203,8203, 0, 0, 0,0,0,8203,49233,8203 ,8204,8201,8205,8205,0,0,0,0], + [49231, 166 , 49232, 1, 49233, 0, 0, 0,0,0, 49233,69,49234,34,34,36,36,0,0,0,0], + [0, 0, 1, 0, 1, 0, 0, 0,0,0,0,0,1,0,1,0,1,0,0,0,0] ) } @@ -124,11 +130,11 @@ fn test_2() -> Field { main( 1, [ - 343552, 343553, 343554, 343555, 343556, 343557, 343558, 343559, 343560, 343561, 343562, 343563, 343564, 343565, 343566, 343567, 343568 + 343552, 343553, 343554, 343555, 343556, 343557, 343558, 343559, 343560, 343561, 343562, 343563, 343564, 343565, 343566, 343567, 343568 , 343569, 343570, 343571, 343572 ], - [8203, 79, 8203,8203,8203,0,0,0,8203,49233,8203,13,8202,8204,8201,8205,8205], - [49231, 182, 49232, 1, 49233,0,0,0,49233,13,49234,0,69,34,34,36,36], - [0, 0, 1, 0, 1,0,0,0,0,0,1,0,0,0,1,0,1] + [8203, 79, 8203,8203,8203,0,0,0,8203,49233,8203,13,8202,8204,8201,8205,8205,0,0,0,0], + [49231, 182, 49232, 1, 49233,0,0,0,49233,13,49234,0,69,34,34,36,36,0,0,0,0], + [0, 0, 1, 0, 1,0,0,0,0,0,1,0,0,0,1,0,1,0,0,0,0] ) } @@ -137,11 +143,11 @@ fn test_3() -> Field { main( 1, [ - 343612, 343613, 343614, 343615, 343616, 343617, 343618, 343619, 343620, 343621, 343622, 343623, 343624, 343625, 343626, 343627, 343628 + 343612, 343613, 343614, 343615, 343616, 343617, 343618, 343619, 343620, 343621, 343622, 343623, 343624, 343625, 343626, 343627, 343628 , 343629, 343630, 343631, 343632 ], - [8203, 79, 8203,8203,8203,0,0,8203,49233,8203,8203,49234, 8203,8204,8201,8205,8205], - [49231, 174, 49232, 1, 49233,0,0,49233,1,49234,49234,2,49235,34,34,36,36], - [0, 0, 1, 0, 1,0,0,0,0,1,0,0,1,0,1,0,1] + [8203, 79, 8203,8203,8203,0,0,8203,49233,8203,8203,49234, 8203,8204,8201,8205,8205,0,0,0,0], + [49231, 174, 49232, 1, 49233,0,0,49233,1,49234,49234,2,49235,34,34,36,36,0,0,0,0], + [0, 0, 1, 0, 1,0,0,0,0,1,0,0,1,0,1,0,1,0,0,0,0] ) } @@ -150,11 +156,11 @@ fn test_5() -> Field { main( 1, [ - 343812, 343813, 343814, 343815, 343816, 343817, 343818, 343819, 343820, 343821, 343822, 343823, 343824, 343825, 343826, 343827, 343828 + 343812, 343813, 343814, 343815, 343816, 343817, 343818, 343819, 343820, 343821, 343822, 343823, 343824, 343825, 343826, 343827, 343828 , 343829, 343830, 343831, 343832 ], - [8203,79,8203,8203,8203,8203, 49233, 8203, 8203, 49234, 8203, 8202, 582,8204,8201,8205,8205], - [49231,190, 49232,1,49233,49233, 1, 49234, 49234, 2, 49235, 69, 80,34,34,36,36], - [0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0,0,1,0,1] + [8203,79,8203,8203,8203,8203, 49233, 8203, 8203, 49234, 8203, 8202, 582,8204,8201,8205,8205,0,0,0,0], + [49231,190, 49232,1,49233,49233, 1, 49234, 49234, 2, 49235, 69, 80,34,34,36,36,0,0,0,0], + [0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0,0,1,0,1,0,0,0,0] ) } diff --git a/circuits/instr/ldy/src/main.nr b/circuits/instr/ldy/src/main.nr index 6ec466a..f8fef9c 100644 --- a/circuits/instr/ldy/src/main.nr +++ b/circuits/instr/ldy/src/main.nr @@ -10,10 +10,10 @@ use dep::std; fn main( r: Field, - op_sorted_step: [Field; 17], - op_sorted_addr: [Field; 17], - op_sorted_val: [Field; 17], - op_sorted_op_rw: [Field; 17] + op_sorted_step: [Field; 21], + op_sorted_addr: [Field; 21], + op_sorted_val: [Field; 21], + op_sorted_op_rw: [Field; 21] ) -> pub Field { //check the program counter assert(op_sorted_addr[0] == 8203); @@ -82,8 +82,14 @@ fn main( assert(op_sorted_addr[16] == 8205); assert(op_sorted_op_rw[16] == 1); assert(op_sorted_val[16] == comp_status); + + for i in 17..21 { + assert(op_sorted_addr[i] == 0); + assert(op_sorted_val[i] == 0); + assert(op_sorted_op_rw[i] == 0); + } - helpers::compute_permutation_17( + helpers::compute_permutation_21( r, op_sorted_step, op_sorted_addr, @@ -97,11 +103,11 @@ fn test_0() -> Field { main( 1, [ - 343432, 343433, 343434, 343435, 343436, 343437, 343438, 343439, 343440, 343441, 343442, 343443, 343444, 343445, 343446,343447, 343448 + 343432, 343433, 343434, 343435, 343436, 343437, 343438, 343439, 343440, 343441, 343442, 343443, 343444, 343445, 343446,343447, 343448 , 343449, 343450, 343451, 343452 ], - [8203, 79, 8203,8203,8203, 0, 0, 0, 0, 0,0,8203,8203,8204,8202,8205,8205], - [49231, 160, 49232, 1, 49233, 0, 0, 0, 0, 0,0,49233,49234,34,34,36,36], - [0, 0, 1, 0, 1, 0, 0, 0, 0, 0,0,0,1,0,1,0,1] + [8203, 79, 8203,8203,8203, 0, 0, 0, 0, 0,0,8203,8203,8204,8202,8205,8205,0,0,0,0], + [49231, 160, 49232, 1, 49233, 0, 0, 0, 0, 0,0,49233,49234,34,34,36,36,0,0,0,0], + [0, 0, 1, 0, 1, 0, 0, 0, 0, 0,0,0,1,0,1,0,1,0,0,0,0] ) } @@ -110,11 +116,11 @@ fn test_1() -> Field { main( 1, [ - 343492, 343493, 343494, 343495, 343496, 343497, 343498, 343499, 343500, 343501, 343502, 343503, 343504, 343505, 343506, 343507, 343508 + 343492, 343493, 343494, 343495, 343496, 343497, 343498, 343499, 343500, 343501, 343502, 343503, 343504, 343505, 343506, 343507, 343508 , 343509, 343510, 343511, 343512 ], - [8203, 79, 8203,8203,8203, 0, 0, 0,0,0,8203,49233,8203 ,8204,8202,8205,8205], - [49231, 164 , 49232, 1, 49233, 0, 0, 0,0,0, 49233,69,49234,34,34,36,36], - [0, 0, 1, 0, 1, 0, 0, 0,0,0,0,0,1,0,1,0,1] + [8203, 79, 8203,8203,8203, 0, 0, 0,0,0,8203,49233,8203 ,8204,8202,8205,8205,0,0,0,0], + [49231, 164 , 49232, 1, 49233, 0, 0, 0,0,0, 49233,69,49234,34,34,36,36,0,0,0,0], + [0, 0, 1, 0, 1, 0, 0, 0,0,0,0,0,1,0,1,0,1,0,0,0,0] ) } @@ -123,11 +129,11 @@ fn test_2() -> Field { main( 1, [ - 343552, 343553, 343554, 343555, 343556, 343557, 343558, 343559, 343560, 343561, 343562, 343563, 343564, 343565, 343566, 343567, 343568 + 343552, 343553, 343554, 343555, 343556, 343557, 343558, 343559, 343560, 343561, 343562, 343563, 343564, 343565, 343566, 343567, 343568 , 343569, 343570, 343571, 343572 ], - [8203, 79, 8203,8203,8203,0,0,0,8203,49233,8203,13,8202,8204,8202,8205,8205], - [49231, 180, 49232, 1, 49233,0,0,0,49233,13,49234,0,69,34,34,36,36], - [0, 0, 1, 0, 1,0,0,0,0,0,1,0,0,0,1,0,1] + [8203, 79, 8203,8203,8203,0,0,0,8203,49233,8203,13,8202,8204,8202,8205,8205,0,0,0,0], + [49231, 180, 49232, 1, 49233,0,0,0,49233,13,49234,0,69,34,34,36,36,0,0,0,0], + [0, 0, 1, 0, 1,0,0,0,0,0,1,0,0,0,1,0,1,0,0,0,0] ) } @@ -136,11 +142,11 @@ fn test_3() -> Field { main( 1, [ - 343612, 343613, 343614, 343615, 343616, 343617, 343618, 343619, 343620, 343621, 343622, 343623, 343624, 343625, 343626, 343627, 343628 + 343612, 343613, 343614, 343615, 343616, 343617, 343618, 343619, 343620, 343621, 343622, 343623, 343624, 343625, 343626, 343627, 343628 , 343629, 343630, 343631, 343632 ], - [8203, 79, 8203,8203,8203,0,0,8203,49233,8203,8203,49234, 8203,8204,8202,8205,8205], - [49231, 172, 49232, 1, 49233,0,0,49233,1,49234,49234,2,49235,34,34,36,36], - [0, 0, 1, 0, 1,0,0,0,0,1,0,0,1,0,1,0,1] + [8203, 79, 8203,8203,8203,0,0,8203,49233,8203,8203,49234, 8203,8204,8202,8205,8205,0,0,0,0], + [49231, 172, 49232, 1, 49233,0,0,49233,1,49234,49234,2,49235,34,34,36,36,0,0,0,0], + [0, 0, 1, 0, 1,0,0,0,0,1,0,0,1,0,1,0,1,0,0,0,0] ) } @@ -149,11 +155,11 @@ fn test_4() -> Field { main( 1, [ - 343712, 343713, 343714, 343715, 343716, 343717, 343718, 343719, 343720, 343721, 343722, 343723, 343724, 343725, 343726, 343727, 343728 + 343712, 343713, 343714, 343715, 343716, 343717, 343718, 343719, 343720, 343721, 343722, 343723, 343724, 343725, 343726, 343727, 343728 , 343729, 343730, 343731, 343732 ], - [8203,79,8203,8203,8203,8203, 49233, 8203, 8203, 49234, 8203, 8201, 582,8204,8202,8205,8205], - [49231,188, 49232,0,49233,49233, 1, 49234, 49234, 2, 49235, 69, 80,34,34,36,36], - [0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0,0,1,0,1] + [8203,79,8203,8203,8203,8203, 49233, 8203, 8203, 49234, 8203, 8201, 582,8204,8202,8205,8205,0,0,0,0], + [49231,188, 49232,0,49233,49233, 1, 49234, 49234, 2, 49235, 69, 80,34,34,36,36,0,0,0,0], + [0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0,0,1,0,1,0,0,0,0] ) } diff --git a/circuits/instr/lsr/src/main.nr b/circuits/instr/lsr/src/main.nr index 7d341a4..8840f85 100644 --- a/circuits/instr/lsr/src/main.nr +++ b/circuits/instr/lsr/src/main.nr @@ -1,46 +1,150 @@ use dep::helpers; +use dep::std; -fn check_op( +//PC = 8203 +//X = 8201 +//Y = 8202 +//A = 8200 +//SR = 8205 +//M = 8204 + +fn main( r: Field, - op_sorted_step: [Field; 21], - op_sorted_addr: [Field; 21], - op_sorted_val: [Field; 21], - op_sorted_op_rw: [Field; 21] -) -> Field { - // TODO: implemented mode retrieval here for the opcode read - // we don't generalize this because each opcode will only have a few modes - // and we want to keep the total constraints down rather than needlessly - // checking for other opcodes every time - - let mode: Field = 0; //stubbed for now, we assume the mode is retreived in logic above - let mut sub_arr_step: [Field; 7] = [0,0,0,0,0,0,0]; - let mut sub_arr_addr: [Field; 7] = [0,0,0,0,0,0,0]; - let mut sub_arr_val: [Field; 7] = [0,0,0,0,0,0,0]; - let mut sub_arr_op_rw: [Field; 7] = [0,0,0,0,0,0,0]; - for i in 0..7 { - sub_arr_step[i] = op_sorted_step[i]; - sub_arr_addr[i] = op_sorted_addr[i]; - sub_arr_val[i] = op_sorted_val[i]; - sub_arr_op_rw[i] = op_sorted_op_rw[i]; - } - let address_and_value: [Field; 2] = helpers::get_addressing( - mode, - sub_arr_step, - sub_arr_addr, - sub_arr_val, - sub_arr_op_rw + op_sorted_step: [Field; 17], + op_sorted_addr: [Field; 17], + op_sorted_val: [Field; 17], + op_sorted_op_rw: [Field; 17] +) -> pub Field { + //check the program counter + assert(op_sorted_addr[0] == 8203); + assert(op_sorted_op_rw[0] == 0); + let pc = op_sorted_val[0]; + + //check the opcode + assert( + (op_sorted_val[1] == 230) + | (op_sorted_val[1] == 238) + | (op_sorted_val[1] == 246) + | (op_sorted_val[1] == 254) ); + assert(op_sorted_op_rw[1] == 0); + let opcode = op_sorted_val[1]; + + //update the PC + assert(op_sorted_addr[2] == 8203); + assert(op_sorted_op_rw[2] == 1); + assert(op_sorted_val[2] == pc + 1); + + //check the mode + assert(op_sorted_addr[3] == 8203); + assert(op_sorted_op_rw[3] == 0); + let mode = op_sorted_val[3]; + + //update the PC + assert(op_sorted_addr[4] == 8203); + assert(op_sorted_op_rw[4] == 1); + assert(op_sorted_val[4] == pc + 2); + + let mut sub_arr_addr: [Field; 8] = [0, 0, 0, 0, 0, 0, 0, 0]; + let mut sub_arr_val: [Field; 8] = [0, 0, 0, 0, 0, 0, 0, 0]; + let mut sub_arr_op_rw: [Field; 8] = [0, 0, 0, 0, 0, 0, 0, 0]; + let offset = 5; + + for i in 0..8 { + sub_arr_addr[i] = op_sorted_addr[offset + i]; + sub_arr_val[i] = op_sorted_val[offset + i]; + sub_arr_op_rw[i] = op_sorted_op_rw[offset + i]; + } + + helpers::addressing_helpers(opcode, mode, sub_arr_addr, sub_arr_val, sub_arr_op_rw); + + // read from memory + assert(op_sorted_addr[13] == 8204); + assert(op_sorted_op_rw[13] == 0); + let mem_val = op_sorted_val[13]; - // TODO: implement the rest of the op code checks here + // write to memory + assert(op_sorted_addr[14] == 8204); + assert(op_sorted_op_rw[14] == 1); + let new_mem = helpers::wrapping_add_u8(mem_val, 1); + assert(op_sorted_val[14] == new_mem.value); - // TODO: handle case of padding + //read status register + assert(op_sorted_addr[15] == 8205); + assert(op_sorted_op_rw[15] == 0); + let sr = op_sorted_val[15]; - // Compute permutation and return it - helpers::compute_permutation( + let mut status = helpers::convert_to_status(sr); + + //compute zero and negative flags + status = helpers::compute_zn_status(new_mem.value, status); + let comp_status = helpers::status_to_num(status); + + //write status register + assert(op_sorted_addr[16] == 8205); + assert(op_sorted_op_rw[16] == 1); + assert(op_sorted_val[16] == comp_status); + + helpers::compute_permutation_17( r, op_sorted_step, op_sorted_addr, op_sorted_val, op_sorted_op_rw ) -} \ No newline at end of file +} + +#[test] +fn test_0() -> Field { + main( + 1, + [ + 343432, 343433, 343434, 343435, 343436, 343437, 343438, 343439, 343440, 343441, 343442, 343443, 343444, 343445, 343446,343447, 343448 + ], + [8203, 79, 8203,8203,8203, 0, 0, 0, 0, 0, 8203, 49233, 8203, 8204, 8204, 8205, 8205], + // [49231, 230, 49232, 0, 0, 0, 0, 0, 49232, 13, 49233, 0, 1, 38, 36], + [49231, 230, 49232, 1, 49233, 0, 0, 0, 0, 0, 49233, 13, 49234, 0, 1, 38, 36], + [0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1] + ) +} +#[test] +fn test_1() -> Field { + main( + 1, + [ + 343492, 343493, 343494, 343495, 343496, 343497, 343498, 343499, 343500, 343501, 343502, 343503, 343504, 343505, 343506, 343507, 343508 + ], + [8203, 79, 8203,8203,8203, 0, 0, 0, 8203, 49233, 8203, 13, 8202, 8204, 8204, 8205, 8205], + // [49231, 246, 49232, 0, 0, 0, 49232, 13, 49233, 0, 100, 1, 2, 36, 36], + [49231, 246, 49232, 1, 49233, 0, 0, 0, 49233, 13, 49234, 0, 100, 1, 2, 36, 36], + [0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1] + ) +} + +#[test] +fn test_2() -> Field { + main( + 1, + [ + 343552, 343553, 343554, 343555, 343556, 343557, 343558, 343559, 343560, 343561, 343562, 343563, 343564, 343565, 343566, 343567, 343568 + ], + [8203, 79, 8203,8203,8203, 0, 0, 8203, 49233, 8203, 8203, 49234, 8203, 8204, 8204, 8205, 8205], + // [49231, 238, 49232, 0, 0, 49232, 1, 49233, 49233, 2, 49234, 2, 3, 36, 36], + [49231, 238, 49232, 1, 49233, 0, 0, 49233, 1, 49234, 49234, 2, 49235, 3, 4, 36, 36], + [0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1, 0, 1] + ) +} + +#[test] +fn test_3() -> Field { + main( + 1, + [ + 343612, 343613, 343614, 343615, 343616, 343617, 343618, 343619, 343620, 343621, 343622, 343623, 343624, 343625, 343626, 343627, 343628 + ], + [8203, 79, 8203,8203,8203, 8203, 49233, 8203, 8203, 49234, 8203, 8202, 582, 8204, 8204, 8205, 8205], + [49231, 254, 49232, 1, 49233, 49233, 1, 49234, 49234, 2, 49235, 69, 80, 4, 5, 36, 36], + [0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 1] + ) +} + diff --git a/circuits/instr/rol/src/main.nr b/circuits/instr/rol/src/main.nr index 7d341a4..8840f85 100644 --- a/circuits/instr/rol/src/main.nr +++ b/circuits/instr/rol/src/main.nr @@ -1,46 +1,150 @@ use dep::helpers; +use dep::std; -fn check_op( +//PC = 8203 +//X = 8201 +//Y = 8202 +//A = 8200 +//SR = 8205 +//M = 8204 + +fn main( r: Field, - op_sorted_step: [Field; 21], - op_sorted_addr: [Field; 21], - op_sorted_val: [Field; 21], - op_sorted_op_rw: [Field; 21] -) -> Field { - // TODO: implemented mode retrieval here for the opcode read - // we don't generalize this because each opcode will only have a few modes - // and we want to keep the total constraints down rather than needlessly - // checking for other opcodes every time - - let mode: Field = 0; //stubbed for now, we assume the mode is retreived in logic above - let mut sub_arr_step: [Field; 7] = [0,0,0,0,0,0,0]; - let mut sub_arr_addr: [Field; 7] = [0,0,0,0,0,0,0]; - let mut sub_arr_val: [Field; 7] = [0,0,0,0,0,0,0]; - let mut sub_arr_op_rw: [Field; 7] = [0,0,0,0,0,0,0]; - for i in 0..7 { - sub_arr_step[i] = op_sorted_step[i]; - sub_arr_addr[i] = op_sorted_addr[i]; - sub_arr_val[i] = op_sorted_val[i]; - sub_arr_op_rw[i] = op_sorted_op_rw[i]; - } - let address_and_value: [Field; 2] = helpers::get_addressing( - mode, - sub_arr_step, - sub_arr_addr, - sub_arr_val, - sub_arr_op_rw + op_sorted_step: [Field; 17], + op_sorted_addr: [Field; 17], + op_sorted_val: [Field; 17], + op_sorted_op_rw: [Field; 17] +) -> pub Field { + //check the program counter + assert(op_sorted_addr[0] == 8203); + assert(op_sorted_op_rw[0] == 0); + let pc = op_sorted_val[0]; + + //check the opcode + assert( + (op_sorted_val[1] == 230) + | (op_sorted_val[1] == 238) + | (op_sorted_val[1] == 246) + | (op_sorted_val[1] == 254) ); + assert(op_sorted_op_rw[1] == 0); + let opcode = op_sorted_val[1]; + + //update the PC + assert(op_sorted_addr[2] == 8203); + assert(op_sorted_op_rw[2] == 1); + assert(op_sorted_val[2] == pc + 1); + + //check the mode + assert(op_sorted_addr[3] == 8203); + assert(op_sorted_op_rw[3] == 0); + let mode = op_sorted_val[3]; + + //update the PC + assert(op_sorted_addr[4] == 8203); + assert(op_sorted_op_rw[4] == 1); + assert(op_sorted_val[4] == pc + 2); + + let mut sub_arr_addr: [Field; 8] = [0, 0, 0, 0, 0, 0, 0, 0]; + let mut sub_arr_val: [Field; 8] = [0, 0, 0, 0, 0, 0, 0, 0]; + let mut sub_arr_op_rw: [Field; 8] = [0, 0, 0, 0, 0, 0, 0, 0]; + let offset = 5; + + for i in 0..8 { + sub_arr_addr[i] = op_sorted_addr[offset + i]; + sub_arr_val[i] = op_sorted_val[offset + i]; + sub_arr_op_rw[i] = op_sorted_op_rw[offset + i]; + } + + helpers::addressing_helpers(opcode, mode, sub_arr_addr, sub_arr_val, sub_arr_op_rw); + + // read from memory + assert(op_sorted_addr[13] == 8204); + assert(op_sorted_op_rw[13] == 0); + let mem_val = op_sorted_val[13]; - // TODO: implement the rest of the op code checks here + // write to memory + assert(op_sorted_addr[14] == 8204); + assert(op_sorted_op_rw[14] == 1); + let new_mem = helpers::wrapping_add_u8(mem_val, 1); + assert(op_sorted_val[14] == new_mem.value); - // TODO: handle case of padding + //read status register + assert(op_sorted_addr[15] == 8205); + assert(op_sorted_op_rw[15] == 0); + let sr = op_sorted_val[15]; - // Compute permutation and return it - helpers::compute_permutation( + let mut status = helpers::convert_to_status(sr); + + //compute zero and negative flags + status = helpers::compute_zn_status(new_mem.value, status); + let comp_status = helpers::status_to_num(status); + + //write status register + assert(op_sorted_addr[16] == 8205); + assert(op_sorted_op_rw[16] == 1); + assert(op_sorted_val[16] == comp_status); + + helpers::compute_permutation_17( r, op_sorted_step, op_sorted_addr, op_sorted_val, op_sorted_op_rw ) -} \ No newline at end of file +} + +#[test] +fn test_0() -> Field { + main( + 1, + [ + 343432, 343433, 343434, 343435, 343436, 343437, 343438, 343439, 343440, 343441, 343442, 343443, 343444, 343445, 343446,343447, 343448 + ], + [8203, 79, 8203,8203,8203, 0, 0, 0, 0, 0, 8203, 49233, 8203, 8204, 8204, 8205, 8205], + // [49231, 230, 49232, 0, 0, 0, 0, 0, 49232, 13, 49233, 0, 1, 38, 36], + [49231, 230, 49232, 1, 49233, 0, 0, 0, 0, 0, 49233, 13, 49234, 0, 1, 38, 36], + [0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1] + ) +} +#[test] +fn test_1() -> Field { + main( + 1, + [ + 343492, 343493, 343494, 343495, 343496, 343497, 343498, 343499, 343500, 343501, 343502, 343503, 343504, 343505, 343506, 343507, 343508 + ], + [8203, 79, 8203,8203,8203, 0, 0, 0, 8203, 49233, 8203, 13, 8202, 8204, 8204, 8205, 8205], + // [49231, 246, 49232, 0, 0, 0, 49232, 13, 49233, 0, 100, 1, 2, 36, 36], + [49231, 246, 49232, 1, 49233, 0, 0, 0, 49233, 13, 49234, 0, 100, 1, 2, 36, 36], + [0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1] + ) +} + +#[test] +fn test_2() -> Field { + main( + 1, + [ + 343552, 343553, 343554, 343555, 343556, 343557, 343558, 343559, 343560, 343561, 343562, 343563, 343564, 343565, 343566, 343567, 343568 + ], + [8203, 79, 8203,8203,8203, 0, 0, 8203, 49233, 8203, 8203, 49234, 8203, 8204, 8204, 8205, 8205], + // [49231, 238, 49232, 0, 0, 49232, 1, 49233, 49233, 2, 49234, 2, 3, 36, 36], + [49231, 238, 49232, 1, 49233, 0, 0, 49233, 1, 49234, 49234, 2, 49235, 3, 4, 36, 36], + [0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1, 0, 1] + ) +} + +#[test] +fn test_3() -> Field { + main( + 1, + [ + 343612, 343613, 343614, 343615, 343616, 343617, 343618, 343619, 343620, 343621, 343622, 343623, 343624, 343625, 343626, 343627, 343628 + ], + [8203, 79, 8203,8203,8203, 8203, 49233, 8203, 8203, 49234, 8203, 8202, 582, 8204, 8204, 8205, 8205], + [49231, 254, 49232, 1, 49233, 49233, 1, 49234, 49234, 2, 49235, 69, 80, 4, 5, 36, 36], + [0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 1] + ) +} + diff --git a/circuits/instr/ror/src/main.nr b/circuits/instr/ror/src/main.nr index 7d341a4..8840f85 100644 --- a/circuits/instr/ror/src/main.nr +++ b/circuits/instr/ror/src/main.nr @@ -1,46 +1,150 @@ use dep::helpers; +use dep::std; -fn check_op( +//PC = 8203 +//X = 8201 +//Y = 8202 +//A = 8200 +//SR = 8205 +//M = 8204 + +fn main( r: Field, - op_sorted_step: [Field; 21], - op_sorted_addr: [Field; 21], - op_sorted_val: [Field; 21], - op_sorted_op_rw: [Field; 21] -) -> Field { - // TODO: implemented mode retrieval here for the opcode read - // we don't generalize this because each opcode will only have a few modes - // and we want to keep the total constraints down rather than needlessly - // checking for other opcodes every time - - let mode: Field = 0; //stubbed for now, we assume the mode is retreived in logic above - let mut sub_arr_step: [Field; 7] = [0,0,0,0,0,0,0]; - let mut sub_arr_addr: [Field; 7] = [0,0,0,0,0,0,0]; - let mut sub_arr_val: [Field; 7] = [0,0,0,0,0,0,0]; - let mut sub_arr_op_rw: [Field; 7] = [0,0,0,0,0,0,0]; - for i in 0..7 { - sub_arr_step[i] = op_sorted_step[i]; - sub_arr_addr[i] = op_sorted_addr[i]; - sub_arr_val[i] = op_sorted_val[i]; - sub_arr_op_rw[i] = op_sorted_op_rw[i]; - } - let address_and_value: [Field; 2] = helpers::get_addressing( - mode, - sub_arr_step, - sub_arr_addr, - sub_arr_val, - sub_arr_op_rw + op_sorted_step: [Field; 17], + op_sorted_addr: [Field; 17], + op_sorted_val: [Field; 17], + op_sorted_op_rw: [Field; 17] +) -> pub Field { + //check the program counter + assert(op_sorted_addr[0] == 8203); + assert(op_sorted_op_rw[0] == 0); + let pc = op_sorted_val[0]; + + //check the opcode + assert( + (op_sorted_val[1] == 230) + | (op_sorted_val[1] == 238) + | (op_sorted_val[1] == 246) + | (op_sorted_val[1] == 254) ); + assert(op_sorted_op_rw[1] == 0); + let opcode = op_sorted_val[1]; + + //update the PC + assert(op_sorted_addr[2] == 8203); + assert(op_sorted_op_rw[2] == 1); + assert(op_sorted_val[2] == pc + 1); + + //check the mode + assert(op_sorted_addr[3] == 8203); + assert(op_sorted_op_rw[3] == 0); + let mode = op_sorted_val[3]; + + //update the PC + assert(op_sorted_addr[4] == 8203); + assert(op_sorted_op_rw[4] == 1); + assert(op_sorted_val[4] == pc + 2); + + let mut sub_arr_addr: [Field; 8] = [0, 0, 0, 0, 0, 0, 0, 0]; + let mut sub_arr_val: [Field; 8] = [0, 0, 0, 0, 0, 0, 0, 0]; + let mut sub_arr_op_rw: [Field; 8] = [0, 0, 0, 0, 0, 0, 0, 0]; + let offset = 5; + + for i in 0..8 { + sub_arr_addr[i] = op_sorted_addr[offset + i]; + sub_arr_val[i] = op_sorted_val[offset + i]; + sub_arr_op_rw[i] = op_sorted_op_rw[offset + i]; + } + + helpers::addressing_helpers(opcode, mode, sub_arr_addr, sub_arr_val, sub_arr_op_rw); + + // read from memory + assert(op_sorted_addr[13] == 8204); + assert(op_sorted_op_rw[13] == 0); + let mem_val = op_sorted_val[13]; - // TODO: implement the rest of the op code checks here + // write to memory + assert(op_sorted_addr[14] == 8204); + assert(op_sorted_op_rw[14] == 1); + let new_mem = helpers::wrapping_add_u8(mem_val, 1); + assert(op_sorted_val[14] == new_mem.value); - // TODO: handle case of padding + //read status register + assert(op_sorted_addr[15] == 8205); + assert(op_sorted_op_rw[15] == 0); + let sr = op_sorted_val[15]; - // Compute permutation and return it - helpers::compute_permutation( + let mut status = helpers::convert_to_status(sr); + + //compute zero and negative flags + status = helpers::compute_zn_status(new_mem.value, status); + let comp_status = helpers::status_to_num(status); + + //write status register + assert(op_sorted_addr[16] == 8205); + assert(op_sorted_op_rw[16] == 1); + assert(op_sorted_val[16] == comp_status); + + helpers::compute_permutation_17( r, op_sorted_step, op_sorted_addr, op_sorted_val, op_sorted_op_rw ) -} \ No newline at end of file +} + +#[test] +fn test_0() -> Field { + main( + 1, + [ + 343432, 343433, 343434, 343435, 343436, 343437, 343438, 343439, 343440, 343441, 343442, 343443, 343444, 343445, 343446,343447, 343448 + ], + [8203, 79, 8203,8203,8203, 0, 0, 0, 0, 0, 8203, 49233, 8203, 8204, 8204, 8205, 8205], + // [49231, 230, 49232, 0, 0, 0, 0, 0, 49232, 13, 49233, 0, 1, 38, 36], + [49231, 230, 49232, 1, 49233, 0, 0, 0, 0, 0, 49233, 13, 49234, 0, 1, 38, 36], + [0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1] + ) +} +#[test] +fn test_1() -> Field { + main( + 1, + [ + 343492, 343493, 343494, 343495, 343496, 343497, 343498, 343499, 343500, 343501, 343502, 343503, 343504, 343505, 343506, 343507, 343508 + ], + [8203, 79, 8203,8203,8203, 0, 0, 0, 8203, 49233, 8203, 13, 8202, 8204, 8204, 8205, 8205], + // [49231, 246, 49232, 0, 0, 0, 49232, 13, 49233, 0, 100, 1, 2, 36, 36], + [49231, 246, 49232, 1, 49233, 0, 0, 0, 49233, 13, 49234, 0, 100, 1, 2, 36, 36], + [0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1] + ) +} + +#[test] +fn test_2() -> Field { + main( + 1, + [ + 343552, 343553, 343554, 343555, 343556, 343557, 343558, 343559, 343560, 343561, 343562, 343563, 343564, 343565, 343566, 343567, 343568 + ], + [8203, 79, 8203,8203,8203, 0, 0, 8203, 49233, 8203, 8203, 49234, 8203, 8204, 8204, 8205, 8205], + // [49231, 238, 49232, 0, 0, 49232, 1, 49233, 49233, 2, 49234, 2, 3, 36, 36], + [49231, 238, 49232, 1, 49233, 0, 0, 49233, 1, 49234, 49234, 2, 49235, 3, 4, 36, 36], + [0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1, 0, 1] + ) +} + +#[test] +fn test_3() -> Field { + main( + 1, + [ + 343612, 343613, 343614, 343615, 343616, 343617, 343618, 343619, 343620, 343621, 343622, 343623, 343624, 343625, 343626, 343627, 343628 + ], + [8203, 79, 8203,8203,8203, 8203, 49233, 8203, 8203, 49234, 8203, 8202, 582, 8204, 8204, 8205, 8205], + [49231, 254, 49232, 1, 49233, 49233, 1, 49234, 49234, 2, 49235, 69, 80, 4, 5, 36, 36], + [0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 1] + ) +} + diff --git a/circuits/instr/sec/src/main.nr b/circuits/instr/sec/src/main.nr index 46d873e..7af343a 100644 --- a/circuits/instr/sec/src/main.nr +++ b/circuits/instr/sec/src/main.nr @@ -10,10 +10,10 @@ use dep::std; fn main( r: Field, - op_sorted_step: [Field; 7], - op_sorted_addr: [Field; 7], - op_sorted_val: [Field; 7], - op_sorted_op_rw: [Field; 7] + op_sorted_step: [Field; 21], + op_sorted_addr: [Field; 21], + op_sorted_val: [Field; 21], + op_sorted_op_rw: [Field; 21] ) -> pub Field { //check the program counter @@ -23,33 +23,42 @@ fn main( //check the opcode assert(op_sorted_val[1] == 56); //0x38 - assert(op_sorted_op_rw[1] == 0); + assert(op_sorted_op_rw[1] == 0); + let opcode = op_sorted_val[1]; //update the PC assert(op_sorted_addr[2] == 8203); assert(op_sorted_op_rw[2] == 1); assert(op_sorted_val[2] == pc + 1); - let mut sub_arr_addr: [Field; 2] = [0,0]; - let mut sub_arr_val: [Field; 2] = [0,0]; - let mut sub_arr_op_rw: [Field; 2] = [0,0]; - let offset = 3; - for i in 0..2 { + //check the mode + assert(op_sorted_addr[3] == 8203); + assert(op_sorted_op_rw[3] == 0); + let _ = op_sorted_val[3]; + + //update the PC + assert(op_sorted_addr[4] == 8203); + assert(op_sorted_op_rw[4] == 1); + assert(op_sorted_val[4] == pc + 2); + + // addressing + let mut sub_arr_addr: [Field; 8] = [0, 0, 0, 0, 0, 0, 0, 0]; + let mut sub_arr_val: [Field; 8] = [0, 0, 0, 0, 0, 0, 0, 0]; + let mut sub_arr_op_rw: [Field; 8] = [0, 0, 0, 0, 0, 0, 0, 0]; + let offset = 5; + + for i in 0..8 { sub_arr_addr[i] = op_sorted_addr[offset + i]; sub_arr_val[i] = op_sorted_val[offset + i]; sub_arr_op_rw[i] = op_sorted_op_rw[offset + i]; } - helpers::imp( - sub_arr_addr, - sub_arr_val, - sub_arr_op_rw - ); + helpers::addressing_helpers(opcode, 0, sub_arr_addr, sub_arr_val, sub_arr_op_rw); //read status register - assert(op_sorted_addr[5] == 8205); - assert(op_sorted_op_rw[5] == 0); - let sr = op_sorted_val[5]; + assert(op_sorted_addr[13] == 8205); + assert(op_sorted_op_rw[13] == 0); + let sr = op_sorted_val[13]; let mut status = helpers::convert_to_status(sr); @@ -58,11 +67,17 @@ fn main( let comp_status = helpers::status_to_num(status); //write on status register - assert(op_sorted_addr[6] == 8205); - assert(op_sorted_op_rw[6] == 1); - assert(op_sorted_val[6] == comp_status); + assert(op_sorted_addr[14] == 8205); + assert(op_sorted_op_rw[14] == 1); + assert(op_sorted_val[14] == comp_status); + + for i in 15..21 { + assert(op_sorted_addr[i] == 0); + assert(op_sorted_val[i] == 0); + assert(op_sorted_op_rw[i] == 0); + } - helpers::compute_permutation_7( + helpers::compute_permutation_21( r, op_sorted_step, op_sorted_addr, @@ -75,60 +90,77 @@ fn main( fn test_0() -> Field { main( 1, - [343432, 343433, 343434, 343435, 343436, 343437, 343438], - [8203, 79, 8203, 8203, 80, 8205, 8205], - [49231, 56, 49232, 49232, 224, 38, 39], - [0, 0, 1, 0, 0, 0, 1] + [ + 343432, 343433, 343434, 343435, 343436, 343437, 343438, 343439, 343440, 343441, 343442, 343443, 343444, 343445, 343446, 343447, 343448, 343449, 343450, 343451, 343452 + ], + [8203, 79, 8203, 8203, 8203, 0, 0, 0, 0, 0, 0, 8203, 80, 8205, 8205, 0, 0, 0, 0, 0, 0], + [49231, 56, 49232, 1, 49233, 0, 0, 0, 0, 0, 0, 49233, 224, 38, 39, 0, 0, 0, 0, 0, 0], + [0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0] ) } + #[test] fn test_1() -> Field { main( 1, - [343492, 343493, 343494, 343495, 343496, 343497, 343498], - [8203, 79, 8203, 8203, 80, 8205, 8205], - [49231, 56, 49232, 49232, 224, 1, 1], - [0, 0, 1, 0, 0, 0, 1] + [ + 343432, 343433, 343434, 343435, 343436, 343437, 343438, 343439, 343440, 343441, 343442, 343443, 343444, 343445, 343446, 343447, 343448, 343449, 343450, 343451, 343452 + ], + [8203, 79, 8203, 8203, 8203, 0, 0, 0, 0, 0, 0, 8203, 80, 8205, 8205, 0, 0, 0, 0, 0, 0], + [49231, 56, 49232, 1, 49233, 0, 0, 0, 0, 0, 0, 49233, 224, 1, 1, 0, 0, 0, 0, 0, 0], + [0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0] ) } + #[test] fn test_2() -> Field { main( 1, - [343552, 343553, 343554, 343555, 343556, 343557, 343558], - [8203, 79, 8203, 8203, 80, 8205, 8205], - [49231, 56, 49232, 49232, 224, 255, 255], - [0, 0, 1, 0, 0, 0, 1] + [ + 343432, 343433, 343434, 343435, 343436, 343437, 343438, 343439, 343440, 343441, 343442, 343443, 343444, 343445, 343446, 343447, 343448, 343449, 343450, 343451, 343452 + ], + [8203, 79, 8203, 8203, 8203, 0, 0, 0, 0, 0, 0, 8203, 80, 8205, 8205, 0, 0, 0, 0, 0, 0], + [49231, 56, 49232, 1, 49233, 0, 0, 0, 0, 0, 0, 49233, 224, 255, 255, 0, 0, 0, 0, 0, 0], + [0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0] ) } + #[test] fn test_3() -> Field { main( 1, - [343612, 343613, 343614, 343615, 343616, 343617, 343618], - [8203, 79, 8203, 8203, 80, 8205, 8205], - [49231, 56, 49232, 49232, 224, 123, 123], - [0, 0, 1, 0, 0, 0, 1] + [ + 343432, 343433, 343434, 343435, 343436, 343437, 343438, 343439, 343440, 343441, 343442, 343443, 343444, 343445, 343446, 343447, 343448, 343449, 343450, 343451, 343452 + ], + [8203, 79, 8203, 8203, 8203, 0, 0, 0, 0, 0, 0, 8203, 80, 8205, 8205, 0, 0, 0, 0, 0, 0], + [49231, 56, 49232, 1, 49233, 0, 0, 0, 0, 0, 0, 49233, 224, 123, 123, 0, 0, 0, 0, 0, 0], + [0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0] ) } + #[test] fn test_4() -> Field { main( 1, - [343672, 343673, 343674, 343675, 343676, 343677, 343678], - [8203, 79, 8203, 8203, 80, 8205, 8205], - [49231, 56, 49232, 49232, 224, 0, 1], - [0, 0, 1, 0, 0, 0, 1] + [ + 343432, 343433, 343434, 343435, 343436, 343437, 343438, 343439, 343440, 343441, 343442, 343443, 343444, 343445, 343446, 343447, 343448, 343449, 343450, 343451, 343452 + ], + [8203, 79, 8203, 8203, 8203, 0, 0, 0, 0, 0, 0, 8203, 80, 8205, 8205, 0, 0, 0, 0, 0, 0], + [49231, 56, 49232, 1, 49233, 0, 0, 0, 0, 0, 0, 49233, 224, 0, 1, 0, 0, 0, 0, 0, 0], + [0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0] ) } + #[test] fn test_5() -> Field { main( 1, - [343732, 343733, 343734, 343735, 343736, 343737, 343738], - [8203, 79, 8203, 8203, 80, 8205, 8205], - [49231, 56, 49232, 49232, 224, 36, 37], - [0, 0, 1, 0, 0, 0, 1] + [ + 343432, 343433, 343434, 343435, 343436, 343437, 343438, 343439, 343440, 343441, 343442, 343443, 343444, 343445, 343446, 343447, 343448, 343449, 343450, 343451, 343452 + ], + [8203, 79, 8203, 8203, 8203, 0, 0, 0, 0, 0, 0, 8203, 80, 8205, 8205, 0, 0, 0, 0, 0, 0], + [49231, 56, 49232, 1, 49233, 0, 0, 0, 0, 0, 0, 49233, 224, 36, 37, 0, 0, 0, 0, 0, 0], + [0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0] ) } diff --git a/circuits/instr/sed/src/main.nr b/circuits/instr/sed/src/main.nr index a1eadcf..0ec4d5d 100644 --- a/circuits/instr/sed/src/main.nr +++ b/circuits/instr/sed/src/main.nr @@ -10,59 +10,72 @@ use dep::std; fn main( r: Field, - op_sorted_step: [Field; 7], - op_sorted_addr: [Field; 7], - op_sorted_val: [Field; 7], - op_sorted_op_rw: [Field; 7] + op_sorted_step: [Field; 21], + op_sorted_addr: [Field; 21], + op_sorted_val: [Field; 21], + op_sorted_op_rw: [Field; 21] ) -> pub Field { - - //check the program counter + //check the program counter assert(op_sorted_addr[0] == 8203); assert(op_sorted_op_rw[0] == 0); let pc = op_sorted_val[0]; //check the opcode - assert(op_sorted_val[1] == 248); //0xF8 - assert(op_sorted_op_rw[1] == 0); - + assert(op_sorted_val[1] == 248); //0xF8 + assert(op_sorted_op_rw[1] == 0); + let opcode = op_sorted_val[1]; + //update the PC assert(op_sorted_addr[2] == 8203); assert(op_sorted_op_rw[2] == 1); assert(op_sorted_val[2] == pc + 1); - let mut sub_arr_addr: [Field; 2] = [0,0]; - let mut sub_arr_val: [Field; 2] = [0,0]; - let mut sub_arr_op_rw: [Field; 2] = [0,0]; - let offset = 3; - for i in 0..2 { + //check the mode + assert(op_sorted_addr[3] == 8203); + assert(op_sorted_op_rw[3] == 0); + let _ = op_sorted_val[3]; + + //update the PC + assert(op_sorted_addr[4] == 8203); + assert(op_sorted_op_rw[4] == 1); + assert(op_sorted_val[4] == pc + 2); + + // addressing + let mut sub_arr_addr: [Field; 8] = [0, 0, 0, 0, 0, 0, 0, 0]; + let mut sub_arr_val: [Field; 8] = [0, 0, 0, 0, 0, 0, 0, 0]; + let mut sub_arr_op_rw: [Field; 8] = [0, 0, 0, 0, 0, 0, 0, 0]; + let offset = 5; + + for i in 0..8 { sub_arr_addr[i] = op_sorted_addr[offset + i]; sub_arr_val[i] = op_sorted_val[offset + i]; sub_arr_op_rw[i] = op_sorted_op_rw[offset + i]; } - helpers::imp( - sub_arr_addr, - sub_arr_val, - sub_arr_op_rw - ); + helpers::addressing_helpers(opcode, 0, sub_arr_addr, sub_arr_val, sub_arr_op_rw); //read status register - assert(op_sorted_addr[5] == 8205); - assert(op_sorted_op_rw[5] == 0); - let sr = op_sorted_val[5]; + assert(op_sorted_addr[13] == 8205); + assert(op_sorted_op_rw[13] == 0); + let sr = op_sorted_val[13]; let mut status = helpers::convert_to_status(sr); //set the decimal bit status = helpers::set_decimal_bit(status); let comp_status = helpers::status_to_num(status); - //write on status register - assert(op_sorted_addr[6] == 8205); - assert(op_sorted_op_rw[6] == 1); - assert(op_sorted_val[6] == comp_status); + assert(op_sorted_addr[14] == 8205); + assert(op_sorted_op_rw[14] == 1); + assert(op_sorted_val[14] == comp_status); - helpers::compute_permutation_7( + for i in 15..21 { + assert(op_sorted_addr[i] == 0); + assert(op_sorted_val[i] == 0); + assert(op_sorted_op_rw[i] == 0); + } + + helpers::compute_permutation_21( r, op_sorted_step, op_sorted_addr, @@ -75,61 +88,77 @@ fn main( fn test_0() -> Field { main( 1, - [343432, 343433, 343434, 343435, 343436, 343437, 343438], - [8203, 79, 8203, 8203, 80, 8205, 8205], - [49231, 248, 49232, 49232, 224, 38, 46], - [0, 0, 1, 0, 0, 0, 1] + [ + 343432, 343433, 343434, 343435, 343436, 343437, 343438, 343439, 343440, 343441, 343442, 343443, 343444, 343445, 343446, 343447, 343448, 343449, 343450, 343451, 343452 + ], + [8203, 79, 8203, 8203, 8203, 0, 0, 0, 0, 0, 0, 8203, 80, 8205, 8205, 0, 0, 0, 0, 0, 0], + [49231, 248, 49232, 1, 49233, 0, 0, 0, 0, 0, 0, 49233, 224, 38, 46, 0, 0, 0, 0, 0, 0], + [0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0] ) } + #[test] fn test_1() -> Field { main( 1, - [343492, 343493, 343494, 343495, 343496, 343497, 343498], - [8203, 79, 8203, 8203, 80, 8205, 8205], - [49231, 248, 49232, 49232, 224, 1, 9], - [0, 0, 1, 0, 0, 0, 1] + [ + 343432, 343433, 343434, 343435, 343436, 343437, 343438, 343439, 343440, 343441, 343442, 343443, 343444, 343445, 343446, 343447, 343448, 343449, 343450, 343451, 343452 + ], + [8203, 79, 8203, 8203, 8203, 0, 0, 0, 0, 0, 0, 8203, 80, 8205, 8205, 0, 0, 0, 0, 0, 0], + [49231, 248, 49232, 1, 49233, 0, 0, 0, 0, 0, 0, 49233, 224, 1, 9, 0, 0, 0, 0, 0, 0], + [0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0] ) } + #[test] fn test_2() -> Field { main( 1, - [343552, 343553, 343554, 343555, 343556, 343557, 343558], - [8203, 79, 8203, 8203, 80, 8205, 8205], - [49231, 248, 49232, 49232, 224, 255, 255], - [0, 0, 1, 0, 0, 0, 1] + [ + 343432, 343433, 343434, 343435, 343436, 343437, 343438, 343439, 343440, 343441, 343442, 343443, 343444, 343445, 343446, 343447, 343448, 343449, 343450, 343451, 343452 + ], + [8203, 79, 8203, 8203, 8203, 0, 0, 0, 0, 0, 0, 8203, 80, 8205, 8205, 0, 0, 0, 0, 0, 0], + [49231, 248, 49232, 1, 49233, 0, 0, 0, 0, 0, 0, 49233, 224, 255, 255, 0, 0, 0, 0, 0, 0], + [0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0] ) } + #[test] fn test_3() -> Field { main( 1, - [343612, 343613, 343614, 343615, 343616, 343617, 343618], - [8203, 79, 8203, 8203, 80, 8205, 8205], - [49231, 248, 49232, 49232, 224, 128, 136], - [0, 0, 1, 0, 0, 0, 1] + [ + 343432, 343433, 343434, 343435, 343436, 343437, 343438, 343439, 343440, 343441, 343442, 343443, 343444, 343445, 343446, 343447, 343448, 343449, 343450, 343451, 343452 + ], + [8203, 79, 8203, 8203, 8203, 0, 0, 0, 0, 0, 0, 8203, 80, 8205, 8205, 0, 0, 0, 0, 0, 0], + [49231, 248, 49232, 1, 49233, 0, 0, 0, 0, 0, 0, 49233, 224, 128, 136, 0, 0, 0, 0, 0, 0], + [0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0] ) } + #[test] fn test_4() -> Field { main( 1, - [343672, 343673, 343674, 343675, 343676, 343677, 343678], - [8203, 79, 8203, 8203, 80, 8205, 8205], - [49231, 248, 49232, 49232, 224, 0, 8], - [0, 0, 1, 0, 0, 0, 1] + [ + 343432, 343433, 343434, 343435, 343436, 343437, 343438, 343439, 343440, 343441, 343442, 343443, 343444, 343445, 343446, 343447, 343448, 343449, 343450, 343451, 343452 + ], + [8203, 79, 8203, 8203, 8203, 0, 0, 0, 0, 0, 0, 8203, 80, 8205, 8205, 0, 0, 0, 0, 0, 0], + [49231, 248, 49232, 1, 49233, 0, 0, 0, 0, 0, 0, 49233, 224, 0, 8, 0, 0, 0, 0, 0, 0], + [0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0] ) } + #[test] fn test_5() -> Field { main( 1, - [343732, 343733, 343734, 343735, 343736, 343737, 343738], - [8203, 79, 8203, 8203, 80, 8205, 8205], - [49231, 248, 49232, 49232, 224, 36, 44], - [0, 0, 1, 0, 0, 0, 1] + [ + 343432, 343433, 343434, 343435, 343436, 343437, 343438, 343439, 343440, 343441, 343442, 343443, 343444, 343445, 343446, 343447, 343448, 343449, 343450, 343451, 343452 + ], + [8203, 79, 8203, 8203, 8203, 0, 0, 0, 0, 0, 0, 8203, 80, 8205, 8205, 0, 0, 0, 0, 0, 0], + [49231, 248, 49232, 1, 49233, 0, 0, 0, 0, 0, 0, 49233, 224, 36, 44, 0, 0, 0, 0, 0, 0], + [0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0] ) } - diff --git a/circuits/instr/sei/src/main.nr b/circuits/instr/sei/src/main.nr index d0d9f69..2c582c0 100644 --- a/circuits/instr/sei/src/main.nr +++ b/circuits/instr/sei/src/main.nr @@ -10,10 +10,10 @@ use dep::std; fn main( r: Field, - op_sorted_step: [Field; 7], - op_sorted_addr: [Field; 7], - op_sorted_val: [Field; 7], - op_sorted_op_rw: [Field; 7] + op_sorted_step: [Field; 21], + op_sorted_addr: [Field; 21], + op_sorted_val: [Field; 21], + op_sorted_op_rw: [Field; 21] ) -> pub Field { //check the program counter @@ -24,32 +24,41 @@ fn main( //check the opcode assert(op_sorted_val[1] == 120); //0x78 assert(op_sorted_op_rw[1] == 0); + let opcode = op_sorted_val[1]; //update the PC assert(op_sorted_addr[2] == 8203); assert(op_sorted_op_rw[2] == 1); assert(op_sorted_val[2] == pc + 1); - let mut sub_arr_addr: [Field; 2] = [0,0]; - let mut sub_arr_val: [Field; 2] = [0,0]; - let mut sub_arr_op_rw: [Field; 2] = [0,0]; - let offset = 3; - for i in 0..2 { + //check the mode + assert(op_sorted_addr[3] == 8203); + assert(op_sorted_op_rw[3] == 0); + let _ = op_sorted_val[3]; + + //update the PC + assert(op_sorted_addr[4] == 8203); + assert(op_sorted_op_rw[4] == 1); + assert(op_sorted_val[4] == pc + 2); + + // addressing + let mut sub_arr_addr: [Field; 8] = [0, 0, 0, 0, 0, 0, 0, 0]; + let mut sub_arr_val: [Field; 8] = [0, 0, 0, 0, 0, 0, 0, 0]; + let mut sub_arr_op_rw: [Field; 8] = [0, 0, 0, 0, 0, 0, 0, 0]; + let offset = 5; + + for i in 0..8 { sub_arr_addr[i] = op_sorted_addr[offset + i]; sub_arr_val[i] = op_sorted_val[offset + i]; sub_arr_op_rw[i] = op_sorted_op_rw[offset + i]; } - helpers::imp( - sub_arr_addr, - sub_arr_val, - sub_arr_op_rw - ); + helpers::addressing_helpers(opcode, 0, sub_arr_addr, sub_arr_val, sub_arr_op_rw); //read status register - assert(op_sorted_addr[5] == 8205); - assert(op_sorted_op_rw[5] == 0); - let sr = op_sorted_val[5]; + assert(op_sorted_addr[13] == 8205); + assert(op_sorted_op_rw[13] == 0); + let sr = op_sorted_val[13]; let mut status = helpers::convert_to_status(sr); @@ -58,11 +67,17 @@ fn main( let comp_status = helpers::status_to_num(status); //write on status register - assert(op_sorted_addr[6] == 8205); - assert(op_sorted_op_rw[6] == 1); - assert(op_sorted_val[6] == comp_status); + assert(op_sorted_addr[14] == 8205); + assert(op_sorted_op_rw[14] == 1); + assert(op_sorted_val[14] == comp_status); + + for i in 15..21{ + assert(op_sorted_addr[i] == 0); + assert(op_sorted_val[i] == 0); + assert(op_sorted_op_rw[i] == 0); + } - helpers::compute_permutation_7( + helpers::compute_permutation_21( r, op_sorted_step, op_sorted_addr, @@ -75,10 +90,12 @@ fn main( fn test_0() -> Field { main( 1, - [343432, 343433, 343434, 343435, 343436, 343437, 343438], - [8203, 79, 8203, 8203, 80, 8205, 8205], - [49231, 120, 49232, 49232, 224, 38, 38], - [0, 0, 1, 0, 0, 0, 1] + [ + 343432, 343433, 343434, 343435, 343436, 343437, 343438, 343439, 343440, 343441, 343442, 343443, 343444, 343445, 343446, 343447, 343448, 343449, 343450, 343451, 343452 + ], + [8203, 79, 8203, 8203, 8203, 0, 0, 0, 0, 0, 0, 8203, 80, 8205, 8205, 0, 0, 0, 0, 0, 0], + [49231, 120, 49232, 1, 49233, 0, 0, 0, 0, 0, 0, 49233, 224, 38, 38, 0, 0, 0, 0, 0, 0], + [0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0] ) } @@ -86,10 +103,12 @@ fn test_0() -> Field { fn test_1() -> Field { main( 1, - [343492, 343493, 343494, 343495, 343496, 343497, 343498], - [8203, 79, 8203, 8203, 80, 8205, 8205], - [49231, 120, 49232, 49232, 224, 1, 5], - [0, 0, 1, 0, 0, 0, 1] + [ + 343432, 343433, 343434, 343435, 343436, 343437, 343438, 343439, 343440, 343441, 343442, 343443, 343444, 343445, 343446, 343447, 343448, 343449, 343450, 343451, 343452 + ], + [8203, 79, 8203, 8203, 8203, 0, 0, 0, 0, 0, 0, 8203, 80, 8205, 8205, 0, 0, 0, 0, 0, 0], + [49231, 120, 49232, 1, 49233, 0, 0, 0, 0, 0, 0, 49233, 224, 1, 5, 0, 0, 0, 0, 0, 0], + [0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0] ) } @@ -97,41 +116,50 @@ fn test_1() -> Field { fn test_2() -> Field { main( 1, - [343552, 343553, 343554, 343555, 343556, 343557, 343558], - [8203, 79, 8203, 8203, 80, 8205, 8205], - [49231, 120, 49232, 49232, 224, 255, 255], - [0, 0, 1, 0, 0, 0, 1] + [ + 343432, 343433, 343434, 343435, 343436, 343437, 343438, 343439, 343440, 343441, 343442, 343443, 343444, 343445, 343446, 343447, 343448, 343449, 343450, 343451, 343452 + ], + [8203, 79, 8203, 8203, 8203, 0, 0, 0, 0, 0, 0, 8203, 80, 8205, 8205, 0, 0, 0, 0, 0, 0], + [49231, 120, 49232, 1, 49233, 0, 0, 0, 0, 0, 0, 49233, 224, 255, 255, 0, 0, 0, 0, 0, 0], + [0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0] ) } + #[test] fn test_3() -> Field { main( 1, - [343612, 343613, 343614, 343615, 343616, 343617, 343618], - [8203, 79, 8203, 8203, 80, 8205, 8205], - [49231, 120, 49232, 49232, 224, 123, 127], - [0, 0, 1, 0, 0, 0, 1] + [ + 343432, 343433, 343434, 343435, 343436, 343437, 343438, 343439, 343440, 343441, 343442, 343443, 343444, 343445, 343446, 343447, 343448, 343449, 343450, 343451, 343452 + ], + [8203, 79, 8203, 8203, 8203, 0, 0, 0, 0, 0, 0, 8203, 80, 8205, 8205, 0, 0, 0, 0, 0, 0], + [49231, 120, 49232, 1, 49233, 0, 0, 0, 0, 0, 0, 49233, 224, 123, 127, 0, 0, 0, 0, 0, 0], + [0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0] ) } + #[test] fn test_4() -> Field { main( 1, - [343672, 343673, 343674, 343675, 343676, 343677, 343678], - [8203, 79, 8203, 8203, 80, 8205, 8205], - [49231, 120, 49232, 49232, 224, 0, 4], - [0, 0, 1, 0, 0, 0, 1] + [ + 343432, 343433, 343434, 343435, 343436, 343437, 343438, 343439, 343440, 343441, 343442, 343443, 343444, 343445, 343446, 343447, 343448, 343449, 343450, 343451, 343452 + ], + [8203, 79, 8203, 8203, 8203, 0, 0, 0, 0, 0, 0, 8203, 80, 8205, 8205, 0, 0, 0, 0, 0, 0], + [49231, 120, 49232, 1, 49233, 0, 0, 0, 0, 0, 0, 49233, 224, 0, 4, 0, 0, 0, 0, 0, 0], + [0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0] ) } + #[test] fn test_5() -> Field { main( 1, - [343732, 343733, 343734, 343735, 343736, 343737, 343738], - [8203, 79, 8203, 8203, 80, 8205, 8205], - [49231, 120, 49232, 49232, 224, 36, 36], - [0, 0, 1, 0, 0, 0, 1] + [ + 343432, 343433, 343434, 343435, 343436, 343437, 343438, 343439, 343440, 343441, 343442, 343443, 343444, 343445, 343446, 343447, 343448, 343449, 343450, 343451, 343452 + ], + [8203, 79, 8203, 8203, 8203, 0, 0, 0, 0, 0, 0, 8203, 80, 8205, 8205, 0, 0, 0, 0, 0, 0], + [49231, 120, 49232, 1, 49233, 0, 0, 0, 0, 0, 0, 49233, 224, 36, 36, 0, 0, 0, 0, 0, 0], + [0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0] ) } - - diff --git a/circuits/instr/sta/src/main.nr b/circuits/instr/sta/src/main.nr index 3767608..5dd56c5 100644 --- a/circuits/instr/sta/src/main.nr +++ b/circuits/instr/sta/src/main.nr @@ -10,10 +10,10 @@ use dep::std; fn main( r: Field, - op_sorted_step: [Field; 15], - op_sorted_addr: [Field; 15], - op_sorted_val: [Field; 15], - op_sorted_op_rw: [Field; 15] + op_sorted_step: [Field; 21], + op_sorted_addr: [Field; 21], + op_sorted_val: [Field; 21], + op_sorted_op_rw: [Field; 21] ) -> pub Field { //check the program counter assert(op_sorted_addr[0] == 8203); @@ -71,7 +71,13 @@ fn main( assert(op_sorted_op_rw[14] == 1); assert(op_sorted_val[14] == a); - helpers::compute_permutation_15( + for i in 15..21{ + assert(op_sorted_addr[i] == 0); + assert(op_sorted_val[i] == 0); + assert(op_sorted_op_rw[i] == 0); + } + + helpers::compute_permutation_21( r, op_sorted_step, op_sorted_addr, @@ -85,11 +91,11 @@ fn test_0() -> Field { main( 1, [ - 343432, 343433, 343434, 343435, 343436, 343437, 343438, 343439, 343440, 343441, 343442, 343443, 343444, 343445, 343446 + 343432, 343433, 343434, 343435, 343436, 343437, 343438, 343439, 343440, 343441, 343442, 343443, 343444, 343445, 343446, 343447, 343448, 343449, 343450, 343451, 343452 ], - [8203, 79, 8203,8203,8203, 0, 0, 0,0,0,8203,49233,8203,8200,8204], - [49231, 133, 49232, 1, 49233,0, 0, 0,0,0, 49233,69,49234,567,567], - [0, 0, 1, 0, 1, 0, 0, 0, 0, 0,0,0,1,0,1] + [8203, 79, 8203,8203,8203, 0, 0, 0,0,0,8203,49233,8203,8200,8204,0,0,0,0,0,0], + [49231, 133, 49232, 1, 49233,0, 0, 0,0,0, 49233,69,49234,567,567,0,0,0,0,0,0], + [0, 0, 1, 0, 1, 0, 0, 0, 0, 0,0,0,1,0,1,0,0,0,0,0,0] ) } @@ -98,11 +104,11 @@ fn test_1() -> Field { main( 1, [ - 343492, 343493, 343494, 343495, 343496, 343497, 343498, 343499, 343500, 343501, 343502, 343503, 343504, 343505, 343506 + 343492, 343493, 343494, 343495, 343496, 343497, 343498, 343499, 343500, 343501, 343502, 343503, 343504, 343505, 343506 , 343507, 343508, 343509, 343510, 343511, 343512 ], - [8203, 79, 8203,8203,8203,0,0,0,8203,49233,8203,13,8202,8200,8204], - [49231, 149 , 49232, 1, 49233,0,0,0,49233,13,49234,0,69,567,567], - [0, 0, 1, 0, 1,0,0,0,0,0,1,0,0,0,1] + [8203, 79, 8203,8203,8203,0,0,0,8203,49233,8203,13,8202,8200,8204,0,0,0,0,0,0], + [49231, 149 , 49232, 1, 49233,0,0,0,49233,13,49234,0,69,567,567,0,0,0,0,0,0], + [0, 0, 1, 0, 1,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0] ) } @@ -111,11 +117,11 @@ fn test_2() -> Field { main( 1, [ - 343552, 343553, 343554, 343555, 343556, 343557, 343558, 343559, 343560, 343561, 343562, 343563, 343564, 343565, 343566 + 343552, 343553, 343554, 343555, 343556, 343557, 343558, 343559, 343560, 343561, 343562, 343563, 343564, 343565, 343566 , 343567, 343568, 343569, 343570, 343571, 343572 ], - [8203, 79, 8203,8203,8203,0,0,8203,49233,8203,8203,49234, 8203,8200,8204], - [49231, 141, 49232, 1, 49233,0,0,49233,1,49234,49234,2,49235,567,567], - [0, 0, 1, 0, 1,0,0,0,0,1,0,0,1,0,1] + [8203, 79, 8203,8203,8203,0,0,8203,49233,8203,8203,49234, 8203,8200,8204,0,0,0,0,0,0], + [49231, 141, 49232, 1, 49233,0,0,49233,1,49234,49234,2,49235,567,567,0,0,0,0,0,0], + [0, 0, 1, 0, 1,0,0,0,0,1,0,0,1,0,1,0,0,0,0,0,0] ) } @@ -124,11 +130,11 @@ fn test_3() -> Field { main( 1, [ - 343612, 343613, 343614, 343615, 343616, 343617, 343618, 343619, 343620, 343621, 343622, 343623, 343624, 343625, 343626 + 343612, 343613, 343614, 343615, 343616, 343617, 343618, 343619, 343620, 343621, 343622, 343623, 343624, 343625, 343626 , 343627, 343628, 343629, 343630, 343631, 343632 ], - [8203, 79, 8203,8203,8203,8203, 49233, 8203, 8203, 49234, 8203, 8201, 582, 8200,8204], - [49231, 157, 49232, 0, 49233,49233, 1, 49234, 49234, 2, 49235, 69, 80,567,567], - [0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0,1] + [8203, 79, 8203,8203,8203,8203, 49233, 8203, 8203, 49234, 8203, 8201, 582, 8200,8204,0,0,0,0,0,0], + [49231, 157, 49232, 0, 49233,49233, 1, 49234, 49234, 2, 49235, 69, 80,567,567,0,0,0,0,0,0], + [0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0,1,0,0,0,0,0,0] ) } @@ -137,11 +143,11 @@ fn test_4() -> Field { main( 1, [ - 343712, 343713, 343714, 343715, 343716, 343717, 343718, 343719, 343720, 343721, 343722, 343723, 343724, 343725, 343726 + 343712, 343713, 343714, 343715, 343716, 343717, 343718, 343719, 343720, 343721, 343722, 343723, 343724, 343725, 343726 , 343727, 343728, 343729, 343730, 343731, 343732 ], - [8203,79,8203,8203,8203,8203, 49233, 8203, 8203, 49234, 8203, 8202, 582, 8200,8204], - [49231,153, 49232,1,49233,49233, 1, 49234, 49234, 2, 49235, 69, 80,567,567], - [0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0,1] + [8203,79,8203,8203,8203,8203, 49233, 8203, 8203, 49234, 8203, 8202, 582, 8200,8204,0,0,0,0,0,0], + [49231,153, 49232,1,49233,49233, 1, 49234, 49234, 2, 49235, 69, 80,567,567,0,0,0,0,0,0], + [0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0,1,0,0,0,0,0,0] ) } @@ -150,11 +156,11 @@ fn test_5() -> Field { main( 1, [ - 343812, 343813, 343814, 343815, 343816, 343817, 343818, 343819, 343820, 343821, 343822, 343823, 343824, 343825, 343826 + 343812, 343813, 343814, 343815, 343816, 343817, 343818, 343819, 343820, 343821, 343822, 343823, 343824, 343825, 343826 , 343827, 343828, 343829, 343830, 343831, 343832 ], - [8203,79,8203,8203,8203,0,8203,49233,8203,5675,8201,5688,5689,8200,8204 ], - [49231,129, 49232,1,49233,0,49233,5675,5676,69,13,1,2,567,567 ], - [0, 0, 1, 0, 1, 0,0,0,1,0,0,0,0,0,1 ] + [8203,79,8203,8203,8203,0,8203,49233,8203,5675,8201,5688,5689,8200,8204,0,0,0,0,0,0], + [49231,129, 49232,1,49233,0,49233,5675,5676,69,13,1,2,567,567,0,0,0,0,0,0], + [0, 0, 1, 0, 1, 0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,0] ) } @@ -163,11 +169,11 @@ fn test_6() -> Field { main( 1, [ - 343912, 343913, 343914, 343915, 343916, 343917, 343918, 343919, 343920, 343921, 343922, 343923, 343924, 343925, 343926 + 343912, 343913, 343914, 343915, 343916, 343917, 343918, 343919, 343920, 343921, 343922, 343923, 343924, 343925, 343926 , 343927, 343928, 343929, 343930, 343931, 343932 ], - [8203,79,8203,8203,8203,0,8203,49233,8203,5675,5676,8202,582,8200,8204 ], - [49231,145, 49232,0,49233,0,49233,5675,5676,1,2,69,112,567,567 ], - [0, 0, 1, 0, 1,0,0,0,1,0,0,0,0,0,1] + [8203,79,8203,8203,8203,0,8203,49233,8203,5675,5676,8202,582,8200,8204,0,0,0,0,0,0], + [49231,145, 49232,0,49233,0,49233,5675,5676,1,2,69,112,567,567,0,0,0,0,0,0], + [0, 0, 1, 0, 1,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,0] ) } diff --git a/circuits/instr/stx/src/main.nr b/circuits/instr/stx/src/main.nr index bad8697..d8b9424 100644 --- a/circuits/instr/stx/src/main.nr +++ b/circuits/instr/stx/src/main.nr @@ -10,10 +10,10 @@ use dep::std; fn main( r: Field, - op_sorted_step: [Field; 15], - op_sorted_addr: [Field; 15], - op_sorted_val: [Field; 15], - op_sorted_op_rw: [Field; 15] + op_sorted_step: [Field; 21], + op_sorted_addr: [Field; 21], + op_sorted_val: [Field; 21], + op_sorted_op_rw: [Field; 21] ) -> pub Field { //check the program counter assert(op_sorted_addr[0] == 8203); @@ -68,7 +68,13 @@ fn main( assert(op_sorted_op_rw[14] == 1); assert(op_sorted_val[14] == x); - helpers::compute_permutation_15( + for i in 15..21{ + assert(op_sorted_addr[i] == 0); + assert(op_sorted_val[i] == 0); + assert(op_sorted_op_rw[i] == 0); + } + + helpers::compute_permutation_21( r, op_sorted_step, op_sorted_addr, @@ -82,11 +88,11 @@ fn test_0() -> Field { main( 1, [ - 343432, 343433, 343434, 343435, 343436, 343437, 343438, 343439, 343440, 343441, 343442, 343443, 343444, 343445, 343446 + 343432, 343433, 343434, 343435, 343436, 343437, 343438, 343439, 343440, 343441, 343442, 343443, 343444, 343445, 343446, 343447, 343448, 343449, 343450, 343451, 343452 ], - [8203, 79, 8203,8203,8203, 0, 0, 0,0,0,8203,49233,8203,8201,8204], - [49231, 134, 49232, 1, 49233,0, 0, 0,0,0, 49233,69,49234,567,567], - [0, 0, 1, 0, 1, 0, 0, 0, 0, 0,0,0,1,0,1] + [8203, 79, 8203,8203,8203, 0, 0, 0,0,0,8203,49233,8203,8201,8204,0,0,0,0,0,0], + [49231, 134, 49232, 1, 49233,0, 0, 0,0,0, 49233,69,49234,567,567,0,0,0,0,0,0], + [0, 0, 1, 0, 1, 0, 0, 0, 0, 0,0,0,1,0,1,0,0,0,0,0,0] ) } @@ -95,11 +101,11 @@ fn test_1() -> Field { main( 1, [ - 343492, 343493, 343494, 343495, 343496, 343497, 343498, 343499, 343500, 343501, 343502, 343503, 343504, 343505, 343506 + 343492, 343493, 343494, 343495, 343496, 343497, 343498, 343499, 343500, 343501, 343502, 343503, 343504, 343505, 343506, 343507, 343508, 343509, 343510, 343511, 343512 ], - [8203, 79, 8203,8203,8203,0,0,0,8203,49233,8203,13,8202,8201,8204], - [49231, 150 , 49232, 1, 49233,0,0,0,49233,13,49234,0,69,567,567], - [0, 0, 1, 0, 1,0,0,0,0,0,1,0,0,0,1] + [8203, 79, 8203,8203,8203,0,0,0,8203,49233,8203,13,8202,8201,8204,0,0,0,0,0,0], + [49231, 150 , 49232, 1, 49233,0,0,0,49233,13,49234,0,69,567,567,0,0,0,0,0,0], + [0, 0, 1, 0, 1,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0] ) } @@ -108,10 +114,10 @@ fn test_2() -> Field { main( 1, [ - 343552, 343553, 343554, 343555, 343556, 343557, 343558, 343559, 343560, 343561, 343562, 343563, 343564, 343565, 343566 + 343552, 343553, 343554, 343555, 343556, 343557, 343558, 343559, 343560, 343561, 343562, 343563, 343564, 343565, 343566, 343567, 343568, 343569, 343570, 343571, 343572 ], - [8203, 79, 8203,8203,8203,0,0,8203,49233,8203,8203,49234, 8203,8201,8204], - [49231, 142, 49232, 1, 49233,0,0,49233,1,49234,49234,2,49235,567,567], - [0, 0, 1, 0, 1,0,0,0,0,1,0,0,1,0,1] + [8203, 79, 8203,8203,8203,0,0,8203,49233,8203,8203,49234, 8203,8201,8204,0,0,0,0,0,0], + [49231, 142, 49232, 1, 49233,0,0,49233,1,49234,49234,2,49235,567,567,0,0,0,0,0,0], + [0, 0, 1, 0, 1,0,0,0,0,1,0,0,1,0,1,0,0,0,0,0,0] ) } \ No newline at end of file diff --git a/circuits/instr/sty/src/main.nr b/circuits/instr/sty/src/main.nr index c1f2878..c00f103 100644 --- a/circuits/instr/sty/src/main.nr +++ b/circuits/instr/sty/src/main.nr @@ -10,10 +10,10 @@ use dep::std; fn main( r: Field, - op_sorted_step: [Field; 15], - op_sorted_addr: [Field; 15], - op_sorted_val: [Field; 15], - op_sorted_op_rw: [Field; 15] + op_sorted_step: [Field; 21], + op_sorted_addr: [Field; 21], + op_sorted_val: [Field; 21], + op_sorted_op_rw: [Field; 21] ) -> pub Field { //check the program counter assert(op_sorted_addr[0] == 8203); @@ -66,8 +66,14 @@ fn main( assert(op_sorted_addr[14] == 8204); assert(op_sorted_op_rw[14] == 1); assert(op_sorted_val[14] == y); + + for i in 15..21 { + assert(op_sorted_addr[i] == 0); + assert(op_sorted_val[i] == 0); + assert(op_sorted_op_rw[i] == 0); + } - helpers::compute_permutation_15( + helpers::compute_permutation_21( r, op_sorted_step, op_sorted_addr, @@ -81,11 +87,11 @@ fn test_0() -> Field { main( 1, [ - 343432, 343433, 343434, 343435, 343436, 343437, 343438, 343439, 343440, 343441, 343442, 343443, 343444, 343445, 343446 + 343432, 343433, 343434, 343435, 343436, 343437, 343438, 343439, 343440, 343441, 343442, 343443, 343444, 343445, 343446, 343447, 343448, 343449, 343450, 343451, 343452 ], - [8203, 79, 8203,8203,8203, 0, 0, 0,0,0,8203,49233,8203,8202,8204], - [49231, 132, 49232, 1, 49233,0, 0, 0,0,0, 49233,69,49234,567,567], - [0, 0, 1, 0, 1, 0, 0, 0, 0, 0,0,0,1,0,1] + [8203, 79, 8203,8203,8203, 0, 0, 0,0,0,8203,49233,8203,8202,8204,0,0,0,0,0,0], + [49231, 132, 49232, 1, 49233,0, 0, 0,0,0, 49233,69,49234,567,567,0,0,0,0,0,0], + [0, 0, 1, 0, 1, 0, 0, 0, 0, 0,0,0,1,0,1,0,0,0,0,0,0] ) } @@ -94,11 +100,11 @@ fn test_1() -> Field { main( 1, [ - 343492, 343493, 343494, 343495, 343496, 343497, 343498, 343499, 343500, 343501, 343502, 343503, 343504, 343505, 343506 + 343492, 343493, 343494, 343495, 343496, 343497, 343498, 343499, 343500, 343501, 343502, 343503, 343504, 343505, 343506, 343507, 343508, 343509, 343510, 343511, 343512 ], - [8203, 79, 8203,8203,8203,0,0,0,8203,49233,8203,13,8202,8202,8204], - [49231, 148 , 49232, 1, 49233,0,0,0,49233,13,49234,0,69,567,567], - [0, 0, 1, 0, 1,0,0,0,0,0,1,0,0,0,1] + [8203, 79, 8203,8203,8203,0,0,0,8203,49233,8203,13,8202,8202,8204,0,0,0,0,0,0], + [49231, 148 , 49232, 1, 49233,0,0,0,49233,13,49234,0,69,567,567,0,0,0,0,0,0], + [0, 0, 1, 0, 1,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0] ) } @@ -107,10 +113,10 @@ fn test_2() -> Field { main( 1, [ - 343552, 343553, 343554, 343555, 343556, 343557, 343558, 343559, 343560, 343561, 343562, 343563, 343564, 343565, 343566 + 343552, 343553, 343554, 343555, 343556, 343557, 343558, 343559, 343560, 343561, 343562, 343563, 343564, 343565, 343566, 343567, 343568, 343569, 343570, 343571, 343572 ], - [8203, 79, 8203,8203,8203,0,0,8203,49233,8203,8203,49234, 8203,8202,8204], - [49231, 140, 49232, 1, 49233,0,0,49233,1,49234,49234,2,49235,567,567], - [0, 0, 1, 0, 1,0,0,0,0,1,0,0,1,0,1] + [8203, 79, 8203,8203,8203,0,0,8203,49233,8203,8203,49234, 8203,8202,8204,0,0,0,0,0,0], + [49231, 140, 49232, 1, 49233,0,0,49233,1,49234,49234,2,49235,567,567,0,0,0,0,0,0], + [0, 0, 1, 0, 1,0,0,0,0,1,0,0,1,0,1,0,0,0,0,0,0] ) } diff --git a/circuits/instr/tax/src/main.nr b/circuits/instr/tax/src/main.nr index 1fbcdd6..9a8cd53 100644 --- a/circuits/instr/tax/src/main.nr +++ b/circuits/instr/tax/src/main.nr @@ -10,10 +10,10 @@ use dep::std; fn main( r: Field, - op_sorted_step: [Field; 7], - op_sorted_addr: [Field; 7], - op_sorted_val: [Field; 7], - op_sorted_op_rw: [Field; 7] + op_sorted_step: [Field; 21], + op_sorted_addr: [Field; 21], + op_sorted_val: [Field; 21], + op_sorted_op_rw: [Field; 21] ) -> pub Field { //check the program counter @@ -24,39 +24,55 @@ fn main( //check the opcode assert(op_sorted_val[1] == 170); //0xaa assert(op_sorted_op_rw[1] == 0); + let opcode = op_sorted_val[1]; //update the PC assert(op_sorted_addr[2] == 8203); assert(op_sorted_op_rw[2] == 1); assert(op_sorted_val[2] == pc + 1); - let mut sub_arr_addr: [Field; 2] = [0,0]; - let mut sub_arr_val: [Field; 2] = [0,0]; - let mut sub_arr_op_rw: [Field; 2] = [0,0]; - let offset = 3; - for i in 0..2 { + //check the mode + assert(op_sorted_addr[3] == 8203); + assert(op_sorted_op_rw[3] == 0); + let _ = op_sorted_val[3]; + + //update the PC + assert(op_sorted_addr[4] == 8203); + assert(op_sorted_op_rw[4] == 1); + assert(op_sorted_val[4] == pc + 2); + + // addressing + let mut sub_arr_addr: [Field; 8] = [0, 0, 0, 0, 0, 0, 0, 0]; + let mut sub_arr_val: [Field; 8] = [0, 0, 0, 0, 0, 0, 0, 0]; + let mut sub_arr_op_rw: [Field; 8] = [0, 0, 0, 0, 0, 0, 0, 0]; + let offset = 5; + + for i in 0..8 { sub_arr_addr[i] = op_sorted_addr[offset + i]; sub_arr_val[i] = op_sorted_val[offset + i]; sub_arr_op_rw[i] = op_sorted_op_rw[offset + i]; } - helpers::imp( - sub_arr_addr, - sub_arr_val, - sub_arr_op_rw - ); + helpers::addressing_helpers(opcode, 0, sub_arr_addr, sub_arr_val, sub_arr_op_rw); + //read accumulator - assert(op_sorted_addr[5] == 8200); - assert(op_sorted_op_rw[5] == 0); - let sr = op_sorted_val[5]; + assert(op_sorted_addr[13] == 8200); + assert(op_sorted_op_rw[13] == 0); + let sr = op_sorted_val[13]; //write on X register - assert(op_sorted_addr[6] == 8201); - assert(op_sorted_op_rw[6] == 1); - assert(op_sorted_val[6] == sr); + assert(op_sorted_addr[14] == 8201); + assert(op_sorted_op_rw[14] == 1); + assert(op_sorted_val[14] == sr); + + for i in 15..21{ + assert(op_sorted_addr[i] == 0); + assert(op_sorted_val[i] == 0); + assert(op_sorted_op_rw[i] == 0); + } - helpers::compute_permutation_7( + helpers::compute_permutation_21( r, op_sorted_step, op_sorted_addr, @@ -69,60 +85,77 @@ fn main( fn test_0() -> Field { main( 1, - [343432, 343433, 343434, 343435, 343436, 343437, 343438], - [8203, 79, 8203, 8203, 80, 8200, 8201], - [49231, 170, 49232, 49232, 224, 38, 38], - [0, 0, 1, 0, 0, 0, 1] + [ + 343432, 343433, 343434, 343435, 343436, 343437, 343438, 343439, 343440, 343441, 343442, 343443, 343444, 343445, 343446, 343447, 343448, 343449, 343450, 343451, 343452 + ], + [8203, 79, 8203, 8203, 8203, 0, 0, 0, 0, 0, 0, 8203, 80,8200,8201, 0, 0, 0, 0 ,0,0], + [49231, 170, 49232, 1, 49233, 0, 0, 0, 0, 0, 0, 49233, 224 ,36, 36, 0, 0, 0, 0,0,0], + [0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0,0,0] ) } + #[test] fn test_1() -> Field { main( 1, - [343492, 343493, 343494, 343495, 343496, 343497, 343498], - [8203, 79, 8203, 8203, 80, 8200, 8201], - [49231, 170, 49232, 49232, 224, 1, 1], - [0, 0, 1, 0, 0, 0, 1] + [ + 343432, 343433, 343434, 343435, 343436, 343437, 343438, 343439, 343440, 343441, 343442, 343443, 343444, 343445, 343446, 343447, 343448, 343449, 343450, 343451, 343452 + ], + [8203, 79, 8203, 8203, 8203, 0, 0, 0, 0, 0, 0, 8203, 80,8200,8201, 0, 0, 0, 0 ,0,0], + [49231, 170, 49232, 1, 49233, 0, 0, 0, 0, 0, 0, 49233, 224 ,1, 1, 0, 0, 0, 0,0,0], + [0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0,0,0] ) } + #[test] fn test_2() -> Field { main( 1, - [343552, 343553, 343554, 343555, 343556, 343557, 343558], - [8203, 79, 8203, 8203, 80, 8200, 8201], - [49231, 170, 49232, 49232, 224, 255, 255], - [0, 0, 1, 0, 0, 0, 1] + [ + 343432, 343433, 343434, 343435, 343436, 343437, 343438, 343439, 343440, 343441, 343442, 343443, 343444, 343445, 343446, 343447, 343448, 343449, 343450, 343451, 343452 + ], + [8203, 79, 8203, 8203, 8203, 0, 0, 0, 0, 0, 0, 8203, 80,8200,8201, 0, 0, 0, 0 ,0,0], + [49231, 170, 49232, 1, 49233, 0, 0, 0, 0, 0, 0, 49233, 224 ,255, 255, 0, 0, 0, 0,0,0], + [0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0,0,0] ) } + #[test] fn test_3() -> Field { main( 1, - [343612, 343613, 343614, 343615, 343616, 343617, 343618], - [8203, 79, 8203, 8203, 80, 8200, 8201], - [49231, 170, 49232, 49232, 224, 123, 123], - [0, 0, 1, 0, 0, 0, 1] + [ + 343432, 343433, 343434, 343435, 343436, 343437, 343438, 343439, 343440, 343441, 343442, 343443, 343444, 343445, 343446, 343447, 343448, 343449, 343450, 343451, 343452 + ], + [8203, 79, 8203, 8203, 8203, 0, 0, 0, 0, 0, 0, 8203, 80,8200,8201, 0, 0, 0, 0 ,0,0], + [49231, 170, 49232, 1, 49233, 0, 0, 0, 0, 0, 0, 49233, 224 ,123, 123, 0, 0, 0, 0,0,0], + [0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0,0,0] ) } + #[test] fn test_4() -> Field { main( 1, - [343672, 343673, 343674, 343675, 343676, 343677, 343678], - [8203, 79, 8203, 8203, 80, 8200, 8201], - [49231, 170, 49232, 49232, 224, 0, 0], - [0, 0, 1, 0, 0, 0, 1] + [ + 343432, 343433, 343434, 343435, 343436, 343437, 343438, 343439, 343440, 343441, 343442, 343443, 343444, 343445, 343446, 343447, 343448, 343449, 343450, 343451, 343452 + ], + [8203, 79, 8203, 8203, 8203, 0, 0, 0, 0, 0, 0, 8203, 80,8200,8201, 0, 0, 0, 0 ,0,0], + [49231, 170, 49232, 1, 49233, 0, 0, 0, 0, 0, 0, 49233, 224 ,0, 0, 0, 0, 0, 0,0,0], + [0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0,0,0] ) } + #[test] fn test_5() -> Field { main( 1, - [343732, 343733, 343734, 343735, 343736, 343737, 343738], - [8203, 79, 8203, 8203, 80, 8200, 8201], - [49231, 170, 49232, 49232, 224, 36, 36], - [0, 0, 1, 0, 0, 0, 1] + [ + 343432, 343433, 343434, 343435, 343436, 343437, 343438, 343439, 343440, 343441, 343442, 343443, 343444, 343445, 343446, 343447, 343448, 343449, 343450, 343451, 343452 + ], + [8203, 79, 8203, 8203, 8203, 0, 0, 0, 0, 0, 0, 8203, 80,8200,8201, 0, 0, 0, 0 ,0,0], + [49231, 170, 49232, 1, 49233, 0, 0, 0, 0, 0, 0, 49233, 224 ,36, 36, 0, 0, 0, 0,0,0], + [0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,0, 0, 0, 0,0,0] ) } diff --git a/circuits/instr/tay/src/main.nr b/circuits/instr/tay/src/main.nr index 33794c9..62f5353 100644 --- a/circuits/instr/tay/src/main.nr +++ b/circuits/instr/tay/src/main.nr @@ -10,10 +10,10 @@ use dep::std; fn main( r: Field, - op_sorted_step: [Field; 7], - op_sorted_addr: [Field; 7], - op_sorted_val: [Field; 7], - op_sorted_op_rw: [Field; 7] + op_sorted_step: [Field; 21], + op_sorted_addr: [Field; 21], + op_sorted_val: [Field; 21], + op_sorted_op_rw: [Field; 21] ) -> pub Field { //check the program counter @@ -24,39 +24,55 @@ fn main( //check the opcode assert(op_sorted_val[1] == 168); //0xa8 assert(op_sorted_op_rw[1] == 0); + let opcode = op_sorted_val[1]; //update the PC assert(op_sorted_addr[2] == 8203); assert(op_sorted_op_rw[2] == 1); assert(op_sorted_val[2] == pc + 1); - let mut sub_arr_addr: [Field; 2] = [0,0]; - let mut sub_arr_val: [Field; 2] = [0,0]; - let mut sub_arr_op_rw: [Field; 2] = [0,0]; - let offset = 3; - for i in 0..2 { + //check the mode + assert(op_sorted_addr[3] == 8203); + assert(op_sorted_op_rw[3] == 0); + let _ = op_sorted_val[3]; + + //update the PC + assert(op_sorted_addr[4] == 8203); + assert(op_sorted_op_rw[4] == 1); + assert(op_sorted_val[4] == pc + 2); + + // addressing + let mut sub_arr_addr: [Field; 8] = [0, 0, 0, 0, 0, 0, 0, 0]; + let mut sub_arr_val: [Field; 8] = [0, 0, 0, 0, 0, 0, 0, 0]; + let mut sub_arr_op_rw: [Field; 8] = [0, 0, 0, 0, 0, 0, 0, 0]; + let offset = 5; + + for i in 0..8 { sub_arr_addr[i] = op_sorted_addr[offset + i]; sub_arr_val[i] = op_sorted_val[offset + i]; sub_arr_op_rw[i] = op_sorted_op_rw[offset + i]; } - helpers::imp( - sub_arr_addr, - sub_arr_val, - sub_arr_op_rw - ); + helpers::addressing_helpers(opcode, 0, sub_arr_addr, sub_arr_val, sub_arr_op_rw); + //read accumulator - assert(op_sorted_addr[5] == 8200); - assert(op_sorted_op_rw[5] == 0); - let sr = op_sorted_val[5]; + assert(op_sorted_addr[13] == 8200); + assert(op_sorted_op_rw[13] == 0); + let sr = op_sorted_val[13]; //write on Y register - assert(op_sorted_addr[6] == 8202); - assert(op_sorted_op_rw[6] == 1); - assert(op_sorted_val[6] == sr); + assert(op_sorted_addr[14] == 8202); + assert(op_sorted_op_rw[14] == 1); + assert(op_sorted_val[14] == sr); + + for i in 15..21{ + assert(op_sorted_addr[i] == 0); + assert(op_sorted_val[i] == 0); + assert(op_sorted_op_rw[i] == 0); + } - helpers::compute_permutation_7( + helpers::compute_permutation_21( r, op_sorted_step, op_sorted_addr, @@ -69,60 +85,77 @@ fn main( fn test_0() -> Field { main( 1, - [343432, 343433, 343434, 343435, 343436, 343437, 343438], - [8203, 79, 8203, 8203, 80, 8200, 8202], - [49231, 168, 49232, 49232, 224, 38, 38], - [0, 0, 1, 0, 0, 0, 1] + [ + 343432, 343433, 343434, 343435, 343436, 343437, 343438, 343439, 343440, 343441, 343442, 343443, 343444, 343445, 343446, 343447, 343448, 343449, 343450, 343451, 343452 + ], + [8203, 79, 8203, 8203, 8203, 0, 0, 0, 0, 0, 0, 8203, 80,8200,8202, 0, 0, 0, 0 ,0,0], + [49231, 168, 49232, 1, 49233, 0, 0, 0, 0, 0, 0, 49233, 224 ,38, 38, 0, 0, 0, 0,0,0], + [0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0,0,0] ) } + #[test] fn test_1() -> Field { main( 1, - [343492, 343493, 343494, 343495, 343496, 343497, 343498], - [8203, 79, 8203, 8203, 80, 8200, 8202], - [49231, 168, 49232, 49232, 224, 1, 1], - [0, 0, 1, 0, 0, 0, 1] + [ + 343432, 343433, 343434, 343435, 343436, 343437, 343438, 343439, 343440, 343441, 343442, 343443, 343444, 343445, 343446, 343447, 343448, 343449, 343450, 343451, 343452 + ], + [8203, 79, 8203, 8203, 8203, 0, 0, 0, 0, 0, 0, 8203, 80,8200,8202, 0, 0, 0, 0 ,0,0], + [49231, 168, 49232, 1, 49233, 0, 0, 0, 0, 0, 0, 49233, 224 ,1, 1, 0, 0, 0, 0,0,0], + [0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0,0,0] ) } + #[test] fn test_2() -> Field { main( 1, - [343552, 343553, 343554, 343555, 343556, 343557, 343558], - [8203, 79, 8203, 8203, 80, 8200, 8202], - [49231, 168, 49232, 49232, 224, 255, 255], - [0, 0, 1, 0, 0, 0, 1] + [ + 343432, 343433, 343434, 343435, 343436, 343437, 343438, 343439, 343440, 343441, 343442, 343443, 343444, 343445, 343446, 343447, 343448, 343449, 343450, 343451, 343452 + ], + [8203, 79, 8203, 8203, 8203, 0, 0, 0, 0, 0, 0, 8203, 80,8200,8202, 0, 0, 0, 0 ,0,0], + [49231, 168, 49232, 1, 49233, 0, 0, 0, 0, 0, 0, 49233, 224 ,255, 255, 0, 0, 0, 0,0,0], + [0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0,0,0] ) } + #[test] fn test_3() -> Field { main( 1, - [343612, 343613, 343614, 343615, 343616, 343617, 343618], - [8203, 79, 8203, 8203, 80, 8200, 8202], - [49231, 168, 49232, 49232, 224, 123, 123], - [0, 0, 1, 0, 0, 0, 1] + [ + 343432, 343433, 343434, 343435, 343436, 343437, 343438, 343439, 343440, 343441, 343442, 343443, 343444, 343445, 343446, 343447, 343448, 343449, 343450, 343451, 343452 + ], + [8203, 79, 8203, 8203, 8203, 0, 0, 0, 0, 0, 0, 8203, 80,8200,8202, 0, 0, 0, 0 ,0,0], + [49231, 168, 49232, 1, 49233, 0, 0, 0, 0, 0, 0, 49233, 224 ,123, 123, 0, 0, 0, 0,0,0], + [0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0,0,0] ) } + #[test] fn test_4() -> Field { main( 1, - [343672, 343673, 343674, 343675, 343676, 343677, 343678], - [8203, 79, 8203, 8203, 80, 8200, 8202], - [49231, 168, 49232, 49232, 224, 0, 0], - [0, 0, 1, 0, 0, 0, 1] + [ + 343432, 343433, 343434, 343435, 343436, 343437, 343438, 343439, 343440, 343441, 343442, 343443, 343444, 343445, 343446, 343447, 343448, 343449, 343450, 343451, 343452 + ], + [8203, 79, 8203, 8203, 8203, 0, 0, 0, 0, 0, 0, 8203, 80,8200,8202, 0, 0, 0, 0 ,0,0], + [49231, 168, 49232, 1, 49233, 0, 0, 0, 0, 0, 0, 49233, 224 ,0, 0, 0, 0, 0, 0,0,0], + [0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0,0,0] ) } + #[test] fn test_5() -> Field { main( 1, - [343732, 343733, 343734, 343735, 343736, 343737, 343738], - [8203, 79, 8203, 8203, 80, 8200, 8202], - [49231, 168, 49232, 49232, 224, 36, 36], - [0, 0, 1, 0, 0, 0, 1] + [ + 343432, 343433, 343434, 343435, 343436, 343437, 343438, 343439, 343440, 343441, 343442, 343443, 343444, 343445, 343446, 343447, 343448, 343449, 343450, 343451, 343452 + ], + [8203, 79, 8203, 8203, 8203, 0, 0, 0, 0, 0, 0, 8203, 80,8200,8202, 0, 0, 0, 0 ,0,0], + [49231, 168, 49232, 1, 49233, 0, 0, 0, 0, 0, 0, 49233, 224 ,36, 36, 0, 0, 0, 0,0,0], + [0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0,0,0] ) } diff --git a/circuits/instr/txa/src/main.nr b/circuits/instr/txa/src/main.nr index f6cb85d..269e1e9 100644 --- a/circuits/instr/txa/src/main.nr +++ b/circuits/instr/txa/src/main.nr @@ -10,10 +10,10 @@ use dep::std; fn main( r: Field, - op_sorted_step: [Field; 7], - op_sorted_addr: [Field; 7], - op_sorted_val: [Field; 7], - op_sorted_op_rw: [Field; 7] + op_sorted_step: [Field; 21], + op_sorted_addr: [Field; 21], + op_sorted_val: [Field; 21], + op_sorted_op_rw: [Field; 21] ) -> pub Field { //check the program counter @@ -24,40 +24,55 @@ fn main( //check the opcode assert(op_sorted_val[1] == 138); //0x8a assert(op_sorted_op_rw[1] == 0); + let opcode = op_sorted_val[1]; //update the PC assert(op_sorted_addr[2] == 8203); assert(op_sorted_op_rw[2] == 1); assert(op_sorted_val[2] == pc + 1); - let mut sub_arr_addr: [Field; 2] = [0,0]; - let mut sub_arr_val: [Field; 2] = [0,0]; - let mut sub_arr_op_rw: [Field; 2] = [0,0]; - let offset = 3; - - for i in 0..2 { + //check the mode + assert(op_sorted_addr[3] == 8203); + assert(op_sorted_op_rw[3] == 0); + let _ = op_sorted_val[3]; + + //update the PC + assert(op_sorted_addr[4] == 8203); + assert(op_sorted_op_rw[4] == 1); + assert(op_sorted_val[4] == pc + 2); + + // addressing + let mut sub_arr_addr: [Field; 8] = [0, 0, 0, 0, 0, 0, 0, 0]; + let mut sub_arr_val: [Field; 8] = [0, 0, 0, 0, 0, 0, 0, 0]; + let mut sub_arr_op_rw: [Field; 8] = [0, 0, 0, 0, 0, 0, 0, 0]; + let offset = 5; + + for i in 0..8 { sub_arr_addr[i] = op_sorted_addr[offset + i]; sub_arr_val[i] = op_sorted_val[offset + i]; sub_arr_op_rw[i] = op_sorted_op_rw[offset + i]; } - helpers::imp( - sub_arr_addr, - sub_arr_val, - sub_arr_op_rw - ); + helpers::addressing_helpers(opcode, 0, sub_arr_addr, sub_arr_val, sub_arr_op_rw); + //read X - assert(op_sorted_addr[5] == 8201); - assert(op_sorted_op_rw[5] == 0); - let sr = op_sorted_val[5]; + assert(op_sorted_addr[13] == 8201); + assert(op_sorted_op_rw[13] == 0); + let sr = op_sorted_val[13]; //write Accumulator - assert(op_sorted_addr[6] == 8200); - assert(op_sorted_op_rw[6] == 1); - assert(op_sorted_val[6] == sr); + assert(op_sorted_addr[14] == 8200); + assert(op_sorted_op_rw[14] == 1); + assert(op_sorted_val[14] == sr); + + for i in 15..21{ + assert(op_sorted_addr[i] == 0); + assert(op_sorted_val[i] == 0); + assert(op_sorted_op_rw[i] == 0); + } - helpers::compute_permutation_7( + helpers::compute_permutation_21( r, op_sorted_step, op_sorted_addr, @@ -70,61 +85,77 @@ fn main( fn test_0() -> Field { main( 1, - [343432, 343433, 343434, 343435, 343436, 343437, 343438], - [8203, 79, 8203, 8203, 80, 8201, 8200], - [49231, 138, 49232, 49232, 224, 38, 38], - [0, 0, 1, 0, 0, 0, 1] + [ + 343432, 343433, 343434, 343435, 343436, 343437, 343438, 343439, 343440, 343441, 343442, 343443, 343444, 343445, 343446, 343447, 343448, 343449, 343450, 343451, 343452 + ], + [8203, 79, 8203, 8203, 8203, 0, 0, 0, 0, 0, 0, 8203, 80,8201,8200, 0, 0, 0, 0 ,0,0], + [49231, 138, 49232, 1, 49233, 0, 0, 0, 0, 0, 0, 49233, 224 ,38, 38, 0, 0, 0, 0,0,0], + [0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0,0,0] ) } + #[test] fn test_1() -> Field { main( 1, - [343492, 343493, 343494, 343495, 343496, 343497, 343498], - [8203, 79, 8203, 8203, 80, 8201, 8200], - [49231, 138, 49232, 49232, 224, 1, 1], - [0, 0, 1, 0, 0, 0, 1] + [ + 343432, 343433, 343434, 343435, 343436, 343437, 343438, 343439, 343440, 343441, 343442, 343443, 343444, 343445, 343446, 343447, 343448, 343449, 343450, 343451, 343452 + ], + [8203, 79, 8203, 8203, 8203, 0, 0, 0, 0, 0, 0, 8203, 80,8201,8200, 0, 0, 0, 0 ,0,0], + [49231, 138, 49232, 1, 49233, 0, 0, 0, 0, 0, 0, 49233, 224 ,1, 1, 0, 0, 0, 0,0,0], + [0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0,0,0] ) } + #[test] fn test_2() -> Field { main( 1, - [343552, 343553, 343554, 343555, 343556, 343557, 343558], - [8203, 79, 8203, 8203, 80, 8201, 8200], - [49231, 138, 49232, 49232, 224, 255, 255], - [0, 0, 1, 0, 0, 0, 1] + [ + 343432, 343433, 343434, 343435, 343436, 343437, 343438, 343439, 343440, 343441, 343442, 343443, 343444, 343445, 343446, 343447, 343448, 343449, 343450, 343451, 343452 + ], + [8203, 79, 8203, 8203, 8203, 0, 0, 0, 0, 0, 0, 8203, 80,8201,8200, 0, 0, 0, 0 ,0,0], + [49231, 138, 49232, 1, 49233, 0, 0, 0, 0, 0, 0, 49233, 224 ,255, 255, 0, 0, 0, 0,0,0], + [0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0,0,0] ) } + #[test] fn test_3() -> Field { main( 1, - [343612, 343613, 343614, 343615, 343616, 343617, 343618], - [8203, 79, 8203, 8203, 80, 8201, 8200], - [49231, 138, 49232, 49232, 224, 123, 123], - [0, 0, 1, 0, 0, 0, 1] + [ + 343432, 343433, 343434, 343435, 343436, 343437, 343438, 343439, 343440, 343441, 343442, 343443, 343444, 343445, 343446, 343447, 343448, 343449, 343450, 343451, 343452 + ], + [8203, 79, 8203, 8203, 8203, 0, 0, 0, 0, 0, 0, 8203, 80,8201,8200, 0, 0, 0, 0 ,0,0], + [49231, 138, 49232, 1, 49233, 0, 0, 0, 0, 0, 0, 49233, 224 ,123, 123, 0, 0, 0, 0,0,0], + [0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0,0,0] ) } + #[test] fn test_4() -> Field { main( 1, - [343672, 343673, 343674, 343675, 343676, 343677, 343678], - [8203, 79, 8203, 8203, 80, 8201, 8200], - [49231, 138, 49232, 49232, 224, 0, 0], - [0, 0, 1, 0, 0, 0, 1] + [ + 343432, 343433, 343434, 343435, 343436, 343437, 343438, 343439, 343440, 343441, 343442, 343443, 343444, 343445, 343446, 343447, 343448, 343449, 343450, 343451, 343452 + ], + [8203, 79, 8203, 8203, 8203, 0, 0, 0, 0, 0, 0, 8203, 80,8201,8200, 0, 0, 0, 0 ,0,0], + [49231, 138, 49232, 1, 49233, 0, 0, 0, 0, 0, 0, 49233, 224 ,0, 0, 0, 0, 0, 0,0,0], + [0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0,0,0] ) } + #[test] fn test_5() -> Field { main( 1, - [343732, 343733, 343734, 343735, 343736, 343737, 343738], - [8203, 79, 8203, 8203, 80, 8201, 8200], - [49231, 138, 49232, 49232, 224, 36, 36], - [0, 0, 1, 0, 0, 0, 1] + [ + 343432, 343433, 343434, 343435, 343436, 343437, 343438, 343439, 343440, 343441, 343442, 343443, 343444, 343445, 343446, 343447, 343448, 343449, 343450, 343451, 343452 + ], + [8203, 79, 8203, 8203, 8203, 0, 0, 0, 0, 0, 0, 8203, 80,8201,8200, 0, 0, 0, 0 ,0,0], + [49231, 138, 49232, 1, 49233, 0, 0, 0, 0, 0, 0, 49233, 224 ,36, 36, 0, 0, 0, 0,0,0], + [0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0,0,0] ) } - diff --git a/circuits/instr/tya/src/main.nr b/circuits/instr/tya/src/main.nr index 3062a06..840baad 100644 --- a/circuits/instr/tya/src/main.nr +++ b/circuits/instr/tya/src/main.nr @@ -10,13 +10,13 @@ use dep::std; fn main( r: Field, - op_sorted_step: [Field; 7], - op_sorted_addr: [Field; 7], - op_sorted_val: [Field; 7], - op_sorted_op_rw: [Field; 7] + op_sorted_step: [Field; 21], + op_sorted_addr: [Field; 21], + op_sorted_val: [Field; 21], + op_sorted_op_rw: [Field; 21] ) -> pub Field { - //check the program counter + //check the program counter assert(op_sorted_addr[0] == 8203); assert(op_sorted_op_rw[0] == 0); let pc = op_sorted_val[0]; @@ -24,39 +24,54 @@ fn main( //check the opcode assert(op_sorted_val[1] == 152); //0x98 assert(op_sorted_op_rw[1] == 0); + let opcode = op_sorted_val[1]; //update the PC assert(op_sorted_addr[2] == 8203); assert(op_sorted_op_rw[2] == 1); assert(op_sorted_val[2] == pc + 1); - let mut sub_arr_addr: [Field; 2] = [0,0]; - let mut sub_arr_val: [Field; 2] = [0,0]; - let mut sub_arr_op_rw: [Field; 2] = [0,0]; - let offset = 3; - for i in 0..2 { + //check the mode + assert(op_sorted_addr[3] == 8203); + assert(op_sorted_op_rw[3] == 0); + let _ = op_sorted_val[3]; + + //update the PC + assert(op_sorted_addr[4] == 8203); + assert(op_sorted_op_rw[4] == 1); + assert(op_sorted_val[4] == pc + 2); + + // addressing + let mut sub_arr_addr: [Field; 8] = [0, 0, 0, 0, 0, 0, 0, 0]; + let mut sub_arr_val: [Field; 8] = [0, 0, 0, 0, 0, 0, 0, 0]; + let mut sub_arr_op_rw: [Field; 8] = [0, 0, 0, 0, 0, 0, 0, 0]; + let offset = 5; + + for i in 0..8 { sub_arr_addr[i] = op_sorted_addr[offset + i]; sub_arr_val[i] = op_sorted_val[offset + i]; sub_arr_op_rw[i] = op_sorted_op_rw[offset + i]; } - helpers::imp( - sub_arr_addr, - sub_arr_val, - sub_arr_op_rw - ); + helpers::addressing_helpers(opcode, 0, sub_arr_addr, sub_arr_val, sub_arr_op_rw); //read Y - assert(op_sorted_addr[5] == 8202); - assert(op_sorted_op_rw[5] == 0); - let sr = op_sorted_val[5]; + assert(op_sorted_addr[13] == 8202); + assert(op_sorted_op_rw[13] == 0); + let sr = op_sorted_val[13]; //write Accumulator - assert(op_sorted_addr[6] == 8200); - assert(op_sorted_op_rw[6] == 1); - assert(op_sorted_val[6] == sr); + assert(op_sorted_addr[14] == 8200); + assert(op_sorted_op_rw[14] == 1); + assert(op_sorted_val[14] == sr); + + for i in 15..21{ + assert(op_sorted_addr[i] == 0); + assert(op_sorted_val[i] == 0); + assert(op_sorted_op_rw[i] == 0); + } - helpers::compute_permutation_7( + helpers::compute_permutation_21( r, op_sorted_step, op_sorted_addr, @@ -69,60 +84,77 @@ fn main( fn test_0() -> Field { main( 1, - [343432, 343433, 343434, 343435, 343436, 343437, 343438], - [8203, 79, 8203, 8203, 80, 8202, 8200], - [49231, 152, 49232, 49232, 224, 38, 38], - [0, 0, 1, 0, 0, 0, 1] + [ + 343432, 343433, 343434, 343435, 343436, 343437, 343438, 343439, 343440, 343441, 343442, 343443, 343444, 343445, 343446, 343447, 343448, 343449, 343450, 343451, 343452 + ], + [8203, 79, 8203, 8203, 8203, 0, 0, 0, 0, 0, 0, 8203, 80,8202,8200, 0, 0, 0, 0 ,0,0], + [49231, 152, 49232, 1, 49233, 0, 0, 0, 0, 0, 0, 49233, 224 ,38, 38, 0, 0, 0, 0,0,0], + [0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0,0,0] ) } + #[test] fn test_1() -> Field { main( 1, - [343492, 343493, 343494, 343495, 343496, 343497, 343498], - [8203, 79, 8203, 8203, 80, 8202, 8200], - [49231, 152, 49232, 49232, 224, 1, 1], - [0, 0, 1, 0, 0, 0, 1] + [ + 343432, 343433, 343434, 343435, 343436, 343437, 343438, 343439, 343440, 343441, 343442, 343443, 343444, 343445, 343446, 343447, 343448, 343449, 343450, 343451, 343452 + ], + [8203, 79, 8203, 8203, 8203, 0, 0, 0, 0, 0, 0, 8203, 80,8202,8200, 0, 0, 0, 0 ,0,0], + [49231, 152, 49232, 1, 49233, 0, 0, 0, 0, 0, 0, 49233, 224 ,1, 1, 0, 0, 0, 0,0,0], + [0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0,0,0] ) } + #[test] fn test_2() -> Field { main( 1, - [343552, 343553, 343554, 343555, 343556, 343557, 343558], - [8203, 79, 8203, 8203, 80, 8202, 8200], - [49231, 152, 49232, 49232, 224, 255, 255], - [0, 0, 1, 0, 0, 0, 1] + [ + 343432, 343433, 343434, 343435, 343436, 343437, 343438, 343439, 343440, 343441, 343442, 343443, 343444, 343445, 343446, 343447, 343448, 343449, 343450, 343451, 343452 + ], + [8203, 79, 8203, 8203, 8203, 0, 0, 0, 0, 0, 0, 8203, 80,8202,8200, 0, 0, 0, 0 ,0,0], + [49231, 152, 49232, 1, 49233, 0, 0, 0, 0, 0, 0, 49233, 224 ,255, 255, 0, 0, 0, 0,0,0], + [0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0,0,0] ) } + #[test] fn test_3() -> Field { main( 1, - [343612, 343613, 343614, 343615, 343616, 343617, 343618], - [8203, 79, 8203, 8203, 80, 8202, 8200], - [49231, 152, 49232, 49232, 224, 123, 123], - [0, 0, 1, 0, 0, 0, 1] + [ + 343432, 343433, 343434, 343435, 343436, 343437, 343438, 343439, 343440, 343441, 343442, 343443, 343444, 343445, 343446, 343447, 343448, 343449, 343450, 343451, 343452 + ], + [8203, 79, 8203, 8203, 8203, 0, 0, 0, 0, 0, 0, 8203, 80,8202,8200, 0, 0, 0, 0 ,0,0], + [49231, 152, 49232, 1, 49233, 0, 0, 0, 0, 0, 0, 49233, 224 ,123, 123, 0, 0, 0, 0,0,0], + [0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0,0,0] ) } + #[test] fn test_4() -> Field { main( 1, - [343672, 343673, 343674, 343675, 343676, 343677, 343678], - [8203, 79, 8203, 8203, 80, 8202, 8200], - [49231, 152, 49232, 49232, 224, 0, 0], - [0, 0, 1, 0, 0, 0, 1] + [ + 343432, 343433, 343434, 343435, 343436, 343437, 343438, 343439, 343440, 343441, 343442, 343443, 343444, 343445, 343446, 343447, 343448, 343449, 343450, 343451, 343452 + ], + [8203, 79, 8203, 8203, 8203, 0, 0, 0, 0, 0, 0, 8203, 80,8202,8200, 0, 0, 0, 0 ,0,0], + [49231, 152, 49232, 1, 49233, 0, 0, 0, 0, 0, 0, 49233, 224 ,0, 0, 0, 0, 0, 0,0,0], + [0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0,0,0] ) } + #[test] fn test_5() -> Field { main( 1, - [343732, 343733, 343734, 343735, 343736, 343737, 343738], - [8203, 79, 8203, 8203, 80, 8202, 8200], - [49231, 152, 49232, 49232, 224, 36, 36], - [0, 0, 1, 0, 0, 0, 1] + [ + 343432, 343433, 343434, 343435, 343436, 343437, 343438, 343439, 343440, 343441, 343442, 343443, 343444, 343445, 343446, 343447, 343448, 343449, 343450, 343451, 343452 + ], + [8203, 79, 8203, 8203, 8203, 0, 0, 0, 0, 0, 0, 8203, 80,8202,8200, 0, 0, 0, 0 ,0,0], + [49231, 152, 49232, 1, 49233, 0, 0, 0, 0, 0, 0, 49233, 224 ,36, 36, 0, 0, 0, 0,0,0], + [0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0,0,0] ) }