From 3ea144228968bb72f7980896f33803869a621952 Mon Sep 17 00:00:00 2001 From: thomaslavaur Date: Wed, 26 Mar 2025 14:44:56 +0100 Subject: [PATCH] add a constant file and fixed a bad dst in commitment --- circom_circuits/ledger/merkle.circom | 5 +-- circom_circuits/ledger/notes.circom | 15 +++---- circom_circuits/misc/constants.circom | 60 +++++++++++++++++++++++++++ 3 files changed, 70 insertions(+), 10 deletions(-) create mode 100644 circom_circuits/misc/constants.circom diff --git a/circom_circuits/ledger/merkle.circom b/circom_circuits/ledger/merkle.circom index 56348ed..74d2bda 100644 --- a/circom_circuits/ledger/merkle.circom +++ b/circom_circuits/ledger/merkle.circom @@ -1,8 +1,8 @@ //test pragma circom 2.1.9; -include "poseidon2_hash.circom"; -include "comparator.circom"; +include "../hash_bn/poseidon2_hash.circom"; +include "../misc/comparator.circom"; // proof of Merkle membership of depth n // /!\ To call this function, it's important to check that each selector is a bit before!!! @@ -11,7 +11,6 @@ template proof_of_membership(n) { signal input selector[n]; // it's the leaf's indice in big endian bits signal input root; signal input leaf; - component compression_hash[n]; diff --git a/circom_circuits/ledger/notes.circom b/circom_circuits/ledger/notes.circom index 4f10b7d..2d339f3 100644 --- a/circom_circuits/ledger/notes.circom +++ b/circom_circuits/ledger/notes.circom @@ -1,8 +1,9 @@ //test pragma circom 2.1.9; -include "poseidon2_hash.circom"; +include "../hash_bn/poseidon2_hash.circom"; include "merkle.circom"; +include "../misc/constants.circom"; // The unit of the note is supposed to be NMO template commitment(){ @@ -15,8 +16,8 @@ template commitment(){ signal output out; component hash = Poseidon2_hash(7); - // int.from_bytes(hashlib.sha256(b"NOMOS_NOTE_CM").digest()[:-1], "little") = 181645510297841241569044198526601622686169271532834574969543446901055041748 - hash.inp[0] <== 181645510297841241569044198526601622686169271532834574969543446901055041748; + component dst = NOMOS_NOTE_CM(); + hash.inp[0] <== dst.out; hash.inp[1] <== state; hash.inp[2] <== value; hash.inp[3] <== unit; @@ -33,8 +34,8 @@ template nullifier(){ signal output out; component hash = Poseidon2_hash(3); - // int.from_bytes(hashlib.sha256(b"NOMOS_NOTE_NF").digest()[:-1], "little") = 310945536431723660304787929213143698356852257431717126117833288836338828411 - hash.inp[0] <== 310945536431723660304787929213143698356852257431717126117833288836338828411; + component dst = NOMOS_NOTE_NF(); + hash.inp[0] <== dst.out; hash.inp[1] <== commitment; hash.inp[2] <== secret_key; @@ -46,8 +47,8 @@ template derive_public_key(){ signal output out; component hash = Poseidon2_hash(2); - // int.from_bytes(hashlib.sha256(b"NOMOS_KDF").digest()[:-1], "little") = 355994159511987982411097843485998670968942801951585260613801918349630142543 - hash.inp[0] <== 355994159511987982411097843485998670968942801951585260613801918349630142543; + component dst = NOMOS_KDF(); + hash.inp[0] <== dst.out; hash.inp[1] <== secret_key; out <== hash.out; } diff --git a/circom_circuits/misc/constants.circom b/circom_circuits/misc/constants.circom new file mode 100644 index 0000000..8d38423 --- /dev/null +++ b/circom_circuits/misc/constants.circom @@ -0,0 +1,60 @@ +//test +pragma circom 2.1.9; + +include "../circomlib/circuits/bitify.circom"; +include "../circomlib/circuits/comparators.circom"; + +// int.from_bytes(hashlib.sha256(b"LEAD").digest()[:-1], "little") = 137836078329650723736739065075984465408055658421620421917147974048265460598 +template LEAD(){ + signal output out; + out <== 137836078329650723736739065075984465408055658421620421917147974048265460598; +} + + +// int.from_bytes(hashlib.sha256(b"NOMOS_SECRET_KEY").digest()[:-1], "little") = 344114695764831179145057610008294480248205750382057360672614582644594850870 +template NOMOS_SECRET_KEY(){ + signal output out; + out <== 344114695764831179145057610008294480248205750382057360672614582644594850870; +} + + +// int.from_bytes(hashlib.sha256(b"NOMOS_NONCE_CONTRIB").digest()[:-1], "little") = 193275670388587576544090216996849534520361117581542778964162861667418671481 +template NOMOS_NONCE_CONTRIB(){ + signal output out; + out <== 193275670388587576544090216996849534520361117581542778964162861667418671481; +} + + +// int.from_bytes(hashlib.sha256(b"NMO").digest()[:-1], "little") = 161796427070100155131822184769584603407573991022311108406630770340454367555 +template NMO(){ + signal output out; + out <== 161796427070100155131822184769584603407573991022311108406630770340454367555; +} + + +// int.from_bytes(hashlib.sha256(b"PAYMENT").digest()[:-1], "little") = 281646683567839822174419720505039861445414630574005374635737888376398200354 +template PAYMENT(){ + signal output out; + out <== 281646683567839822174419720505039861445414630574005374635737888376398200354; +} + + +// int.from_bytes(hashlib.sha256(b"NOMOS_NOTE_CM").digest()[:-1], "little") = 181645510297841241569044198526601622686169271532834574969543446901055041748 +template NOMOS_NOTE_CM(){ + signal output out; + out <== 181645510297841241569044198526601622686169271532834574969543446901055041748; +} + + +// int.from_bytes(hashlib.sha256(b"NOMOS_NOTE_NF").digest()[:-1], "little") = 310945536431723660304787929213143698356852257431717126117833288836338828411 +template NOMOS_NOTE_NF(){ + signal output out; + out <== 310945536431723660304787929213143698356852257431717126117833288836338828411; +} + + +// int.from_bytes(hashlib.sha256(b"NOMOS_KDF").digest()[:-1], "little") = 355994159511987982411097843485998670968942801951585260613801918349630142543 +template NOMOS_KDF(){ + signal output out; + out <== 355994159511987982411097843485998670968942801951585260613801918349630142543; +} \ No newline at end of file