From d9e48cbdbbeffee78e6087da2725945622e84e6c Mon Sep 17 00:00:00 2001 From: Stefan Nikolov Date: Fri, 23 Jun 2023 19:16:41 +0300 Subject: [PATCH 1/2] feat(circom): Add tests to IsEqaulArrays --- .../circom/test/is_equal_arrays/circuit.circom | 5 +++++ .../circom/test/is_equal_arrays/data/case01/input.json | 1 + .../circom/test/is_equal_arrays/data/case01/output.json | 1 + .../circom/test/is_equal_arrays/data/case02/input.json | 1 + .../circom/test/is_equal_arrays/data/case02/output.json | 1 + .../circom/test/is_equal_arrays/data/case03/input.json | 1 + .../circom/test/is_equal_arrays/data/case03/output.json | 1 + 7 files changed, 11 insertions(+) create mode 100644 beacon-light-client/circom/test/is_equal_arrays/circuit.circom create mode 100644 beacon-light-client/circom/test/is_equal_arrays/data/case01/input.json create mode 100644 beacon-light-client/circom/test/is_equal_arrays/data/case01/output.json create mode 100644 beacon-light-client/circom/test/is_equal_arrays/data/case02/input.json create mode 100644 beacon-light-client/circom/test/is_equal_arrays/data/case02/output.json create mode 100644 beacon-light-client/circom/test/is_equal_arrays/data/case03/input.json create mode 100644 beacon-light-client/circom/test/is_equal_arrays/data/case03/output.json diff --git a/beacon-light-client/circom/test/is_equal_arrays/circuit.circom b/beacon-light-client/circom/test/is_equal_arrays/circuit.circom new file mode 100644 index 000000000..af7cb9c21 --- /dev/null +++ b/beacon-light-client/circom/test/is_equal_arrays/circuit.circom @@ -0,0 +1,5 @@ +pragma circom 2.1.5; + +include "../../circuits/utils/arrays.circom"; + +component main = IsEqualArrays(3) // N must be equal to length in both arrays in input["in"] diff --git a/beacon-light-client/circom/test/is_equal_arrays/data/case01/input.json b/beacon-light-client/circom/test/is_equal_arrays/data/case01/input.json new file mode 100644 index 000000000..3f047d2c5 --- /dev/null +++ b/beacon-light-client/circom/test/is_equal_arrays/data/case01/input.json @@ -0,0 +1 @@ +{"in": [["1","2","2"],["1","2","2"]]} diff --git a/beacon-light-client/circom/test/is_equal_arrays/data/case01/output.json b/beacon-light-client/circom/test/is_equal_arrays/data/case01/output.json new file mode 100644 index 000000000..f4209a168 --- /dev/null +++ b/beacon-light-client/circom/test/is_equal_arrays/data/case01/output.json @@ -0,0 +1 @@ +{"out": "1"} diff --git a/beacon-light-client/circom/test/is_equal_arrays/data/case02/input.json b/beacon-light-client/circom/test/is_equal_arrays/data/case02/input.json new file mode 100644 index 000000000..23271aee5 --- /dev/null +++ b/beacon-light-client/circom/test/is_equal_arrays/data/case02/input.json @@ -0,0 +1 @@ +{"in": [["100","2","2"],["1","2","101"]]} diff --git a/beacon-light-client/circom/test/is_equal_arrays/data/case02/output.json b/beacon-light-client/circom/test/is_equal_arrays/data/case02/output.json new file mode 100644 index 000000000..8b71f4187 --- /dev/null +++ b/beacon-light-client/circom/test/is_equal_arrays/data/case02/output.json @@ -0,0 +1 @@ +{"out": "0"} diff --git a/beacon-light-client/circom/test/is_equal_arrays/data/case03/input.json b/beacon-light-client/circom/test/is_equal_arrays/data/case03/input.json new file mode 100644 index 000000000..9a6d16302 --- /dev/null +++ b/beacon-light-client/circom/test/is_equal_arrays/data/case03/input.json @@ -0,0 +1 @@ +{"in": [["10","8","7"],["7","8","10"]]} diff --git a/beacon-light-client/circom/test/is_equal_arrays/data/case03/output.json b/beacon-light-client/circom/test/is_equal_arrays/data/case03/output.json new file mode 100644 index 000000000..8b71f4187 --- /dev/null +++ b/beacon-light-client/circom/test/is_equal_arrays/data/case03/output.json @@ -0,0 +1 @@ +{"out": "0"} From 764651628eca3e64c62e7eaa6fb5a2a721706305 Mon Sep 17 00:00:00 2001 From: Stefan Nikolov Date: Fri, 23 Jun 2023 19:16:41 +0300 Subject: [PATCH 2/2] feat(circom): Add tests to IsEqaulArrays --- .../circom/circuits/utils/arrays.circom | 13 +++++++++++++ .../circom/circuits/utils/numerical.circom | 6 ++++++ .../circom/test/is_equal_arrays/circuit.circom | 5 +++++ .../test/is_equal_arrays/data/case01/input.json | 1 + .../test/is_equal_arrays/data/case01/output.json | 1 + .../test/is_equal_arrays/data/case02/input.json | 1 + .../test/is_equal_arrays/data/case02/output.json | 1 + .../test/is_equal_arrays/data/case03/input.json | 1 + .../test/is_equal_arrays/data/case03/output.json | 1 + 9 files changed, 30 insertions(+) create mode 100644 beacon-light-client/circom/test/is_equal_arrays/circuit.circom create mode 100644 beacon-light-client/circom/test/is_equal_arrays/data/case01/input.json create mode 100644 beacon-light-client/circom/test/is_equal_arrays/data/case01/output.json create mode 100644 beacon-light-client/circom/test/is_equal_arrays/data/case02/input.json create mode 100644 beacon-light-client/circom/test/is_equal_arrays/data/case02/output.json create mode 100644 beacon-light-client/circom/test/is_equal_arrays/data/case03/input.json create mode 100644 beacon-light-client/circom/test/is_equal_arrays/data/case03/output.json diff --git a/beacon-light-client/circom/circuits/utils/arrays.circom b/beacon-light-client/circom/circuits/utils/arrays.circom index 475e62c95..7d47add7f 100644 --- a/beacon-light-client/circom/circuits/utils/arrays.circom +++ b/beacon-light-client/circom/circuits/utils/arrays.circom @@ -27,6 +27,19 @@ template Selector(N) { out <== sums[N]; } +<<<<<<< HEAD +======= +template RangeCheck(n) { + signal input in[3]; + signal output out; + + signal first <== LessThanBitsCheck(64)([in[0], in[1]]); + signal second <== LessThanBitsCheck(64)([in[1], in[2]]); + + out <== first * second; +} + +>>>>>>> d2c78b2f19ec512a921c39fedcba5413061c5a30 template IsEqualArrays(N) { signal input in[2][N]; signal output out; diff --git a/beacon-light-client/circom/circuits/utils/numerical.circom b/beacon-light-client/circom/circuits/utils/numerical.circom index 20466df54..cf6101a89 100644 --- a/beacon-light-client/circom/circuits/utils/numerical.circom +++ b/beacon-light-client/circom/circuits/utils/numerical.circom @@ -26,6 +26,7 @@ template LessThanOrEqualBitsCheck(n) { out <== LessEqThan(n)(in); } +<<<<<<< HEAD template RangeCheck(n) { signal input in[3]; signal output out; @@ -36,13 +37,18 @@ template RangeCheck(n) { out <== first * second; } +======= +>>>>>>> d2c78b2f19ec512a921c39fedcba5413061c5a30 template DivisionVerification() { signal input dividend; signal input divisor; signal input quotient; signal input remainder; +<<<<<<< HEAD //TODO: Needs additional constraint +======= +>>>>>>> d2c78b2f19ec512a921c39fedcba5413061c5a30 dividend === divisor * quotient + remainder; } diff --git a/beacon-light-client/circom/test/is_equal_arrays/circuit.circom b/beacon-light-client/circom/test/is_equal_arrays/circuit.circom new file mode 100644 index 000000000..af7cb9c21 --- /dev/null +++ b/beacon-light-client/circom/test/is_equal_arrays/circuit.circom @@ -0,0 +1,5 @@ +pragma circom 2.1.5; + +include "../../circuits/utils/arrays.circom"; + +component main = IsEqualArrays(3) // N must be equal to length in both arrays in input["in"] diff --git a/beacon-light-client/circom/test/is_equal_arrays/data/case01/input.json b/beacon-light-client/circom/test/is_equal_arrays/data/case01/input.json new file mode 100644 index 000000000..3f047d2c5 --- /dev/null +++ b/beacon-light-client/circom/test/is_equal_arrays/data/case01/input.json @@ -0,0 +1 @@ +{"in": [["1","2","2"],["1","2","2"]]} diff --git a/beacon-light-client/circom/test/is_equal_arrays/data/case01/output.json b/beacon-light-client/circom/test/is_equal_arrays/data/case01/output.json new file mode 100644 index 000000000..f4209a168 --- /dev/null +++ b/beacon-light-client/circom/test/is_equal_arrays/data/case01/output.json @@ -0,0 +1 @@ +{"out": "1"} diff --git a/beacon-light-client/circom/test/is_equal_arrays/data/case02/input.json b/beacon-light-client/circom/test/is_equal_arrays/data/case02/input.json new file mode 100644 index 000000000..23271aee5 --- /dev/null +++ b/beacon-light-client/circom/test/is_equal_arrays/data/case02/input.json @@ -0,0 +1 @@ +{"in": [["100","2","2"],["1","2","101"]]} diff --git a/beacon-light-client/circom/test/is_equal_arrays/data/case02/output.json b/beacon-light-client/circom/test/is_equal_arrays/data/case02/output.json new file mode 100644 index 000000000..8b71f4187 --- /dev/null +++ b/beacon-light-client/circom/test/is_equal_arrays/data/case02/output.json @@ -0,0 +1 @@ +{"out": "0"} diff --git a/beacon-light-client/circom/test/is_equal_arrays/data/case03/input.json b/beacon-light-client/circom/test/is_equal_arrays/data/case03/input.json new file mode 100644 index 000000000..9a6d16302 --- /dev/null +++ b/beacon-light-client/circom/test/is_equal_arrays/data/case03/input.json @@ -0,0 +1 @@ +{"in": [["10","8","7"],["7","8","10"]]} diff --git a/beacon-light-client/circom/test/is_equal_arrays/data/case03/output.json b/beacon-light-client/circom/test/is_equal_arrays/data/case03/output.json new file mode 100644 index 000000000..8b71f4187 --- /dev/null +++ b/beacon-light-client/circom/test/is_equal_arrays/data/case03/output.json @@ -0,0 +1 @@ +{"out": "0"}