mirror of
https://github.com/logos-blockchain/logos-blockchain-pocs.git
synced 2026-01-02 21:23:08 +00:00
We audited it with Mehmet
This commit is contained in:
parent
cfbf7f3c4d
commit
fa940b1ed2
@ -73,11 +73,11 @@ template would_win_leadership(secret_depth){
|
||||
|
||||
// Derivation of the secrets root from the slot secret at position slot - starting_slot
|
||||
// Verify that the substraction wont underflow (starting_slot < slot)
|
||||
component checker = SafeLessEqThan(252);
|
||||
checker.in[0] <== starting_slot;
|
||||
checker.in[1] <== slot;
|
||||
component checker = SafeFullLessThan();
|
||||
checker.a <== starting_slot;
|
||||
checker.b <== slot;
|
||||
|
||||
// Compute the positions related to slot - starting_slot (and make sure secret_depth = 25 bits)
|
||||
// Compute the positions related to slot - starting_slot and make sure slot - starting_slot is a 25 bits number
|
||||
component bits = Num2Bits(secret_depth);
|
||||
bits.in <== slot - starting_slot;
|
||||
|
||||
@ -142,7 +142,7 @@ template would_win_leadership(secret_depth){
|
||||
|
||||
|
||||
// Check that the ticket is winning
|
||||
component winning = FullLessThan();
|
||||
component winning = SafeFullLessThan();
|
||||
winning.a <== ticket.out;
|
||||
winning.b <== threshold;
|
||||
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
pragma circom 2.1.9;
|
||||
|
||||
include "../hash_bn/poseidon2_hash.circom";
|
||||
include "../ledger/merkle.circom";
|
||||
include "../hash_bn/merkle.circom";
|
||||
include "../misc/constants.circom";
|
||||
|
||||
template derive_voucher_nullifier(){
|
||||
|
||||
@ -6,58 +6,6 @@ include "../circomlib/circuits/comparators.circom";
|
||||
|
||||
// If a or b isn't guaranteed to be less than p use SafeFullComparator
|
||||
// See https://www.notion.so/nomos-tech/Comparisons-1fd261aa09df81feae1ff3e6612b92a0
|
||||
template FullLessThan() {
|
||||
signal input a;
|
||||
signal input b;
|
||||
signal output out;
|
||||
|
||||
component bitifier_a = Num2Bits(254);
|
||||
component bitifier_b = Num2Bits(254);
|
||||
|
||||
bitifier_a.in <== a;
|
||||
bitifier_b.in <== b;
|
||||
|
||||
component numifier_a = Bits2Num(252);
|
||||
component numifier_b = Bits2Num(252);
|
||||
|
||||
for(var i =0; i<252; i++){
|
||||
numifier_a.in[i] <== bitifier_a.out[i+2];
|
||||
numifier_b.in[i] <== bitifier_b.out[i+2];
|
||||
}
|
||||
|
||||
component A = LessThan(252);
|
||||
A.in[0] <== numifier_b.out;
|
||||
A.in[1] <== numifier_a.out;
|
||||
|
||||
component B = IsEqual();
|
||||
B.in[0] <== numifier_a.out;
|
||||
B.in[1] <== numifier_b.out;
|
||||
|
||||
component C = IsEqual();
|
||||
C.in[0] <== bitifier_a.out[1];
|
||||
C.in[1] <== bitifier_b.out[1];
|
||||
|
||||
component D = IsEqual();
|
||||
D.in[0] <== bitifier_a.out[1];
|
||||
D.in[1] <== 1;
|
||||
|
||||
component E = IsEqual();
|
||||
E.in[0] <== bitifier_a.out[0];
|
||||
E.in[1] <== bitifier_b.out[0];
|
||||
|
||||
component F = IsEqual();
|
||||
F.in[0] <== bitifier_a.out[0];
|
||||
F.in[1] <== 1;
|
||||
|
||||
signal intermediate_results[4];
|
||||
intermediate_results[0] <== (1 - C.out) * (1-D.out);
|
||||
intermediate_results[1] <== (1 - C.out) * (1-E.out);
|
||||
intermediate_results[2] <== intermediate_results[1] * (1- F.out);
|
||||
intermediate_results[3] <== B.out * (intermediate_results[0] + intermediate_results[2]);
|
||||
|
||||
out <== (1 - A.out) * ((1 - B.out) + intermediate_results[3]);
|
||||
|
||||
}
|
||||
|
||||
template SafeFullLessThan() {
|
||||
signal input a;
|
||||
@ -109,44 +57,4 @@ template SafeFullLessThan() {
|
||||
intermediate_results[3] <== B.out * (intermediate_results[0] + intermediate_results[2]);
|
||||
|
||||
out <== (1 - A.out) * ((1 - B.out) + intermediate_results[3]);
|
||||
}
|
||||
|
||||
// Safely compare two n-bit numbers
|
||||
// Performs range checks on the inputs to avoid overflow. Range is n <= 252
|
||||
template SafeLessThan(n) {
|
||||
assert(n <= 252);
|
||||
signal input in[2];
|
||||
signal output out;
|
||||
|
||||
component aInRange = Num2Bits(n);
|
||||
aInRange.in <== in[0];
|
||||
component bInRange = Num2Bits(n);
|
||||
bInRange.in <== in[1];
|
||||
|
||||
component lt = LessThan(n);
|
||||
|
||||
lt.in[0] <== in[0];
|
||||
lt.in[1] <== in[1];
|
||||
|
||||
out <== lt.out;
|
||||
}
|
||||
|
||||
// Safely compare two n-bit numbers
|
||||
// Performs range checks on the inputs to avoid overflow. Range is n <= 252
|
||||
template SafeLessEqThan(n) {
|
||||
assert(n <= 252);
|
||||
signal input in[2];
|
||||
signal output out;
|
||||
|
||||
component aInRange = Num2Bits(n);
|
||||
aInRange.in <== in[0];
|
||||
component bInRange = Num2Bits(n);
|
||||
bInRange.in <== in[1];
|
||||
|
||||
component lt = LessEqThan(n);
|
||||
|
||||
lt.in[0] <== in[0];
|
||||
lt.in[1] <== in[1];
|
||||
|
||||
out <== lt.out;
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user