-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Recurssive light client commit inputs #227
base: main
Are you sure you want to change the base?
Changes from all commits
e7163d1
9bcd219
63fed8d
e185499
90deca9
c5e3f0b
eb54547
828ee19
8cb5348
f0f8eb3
3611abd
0825981
1166db3
0a4e13e
cb27716
e77977d
3e3a204
e21c3d6
31cbf71
7c48b57
4241bb0
bd9e685
93e9c0e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
pragma circom 2.1.5; | ||
|
||
include "../../../node_modules/circomlib/circuits/poseidon.circom"; | ||
|
||
template HashTreeRootPoseidon(N) { | ||
signal input leaves[N]; | ||
signal output out; | ||
|
||
component hashers[N - 1]; | ||
|
||
for(var i = 0; i < N - 1; i++) { | ||
hashers[i] = Poseidon(2); | ||
} | ||
|
||
for(var i = 0; i < N / 2; i++) { | ||
hashers[i].inputs[0] <== leaves[i * 2]; | ||
hashers[i].inputs[1] <== leaves[i * 2 + 1]; | ||
} | ||
|
||
var k = 0; | ||
for(var i = N / 2; i < N - 1; i++) { | ||
hashers[i].inputs[0] <== hashers[k * 2].out; | ||
hashers[i].inputs[1] <== hashers[k * 2 + 1].out; | ||
|
||
k++; | ||
} | ||
|
||
out <== hashers[N - 2].out; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
pragma circom 2.1.5; | ||
|
||
include "../../../node_modules/circomlib/circuits/poseidon.circom"; | ||
|
||
template VerifierPoseidon(pubInpCount, k) { | ||
signal input originator[2]; | ||
signal input nextHeaderHashNum[2]; | ||
signal input historicSyncCommitteeHashTreeRoot; | ||
signal input syncCommitteeHistoricParticipationIndex; | ||
|
||
// Verification Key | ||
signal input negalfa1xbeta2[6][2][k]; // e(-alfa1, beta2) | ||
signal input gamma2[2][2][k]; | ||
signal input delta2[2][2][k]; | ||
signal input IC[pubInpCount+1][2][k]; | ||
signal input domain[256]; | ||
|
||
signal output out; | ||
|
||
var negalfa1xbeta2_index = 6 * 2 * k; | ||
var gamma2_index = 2 * 2 * k; | ||
var delta2_index = 2 * 2 * k; | ||
var IC_index = (pubInpCount + 1) * 2 * k; | ||
|
||
var cummulative_index = 0; | ||
|
||
var commitment_size = 2 + 2 + 1 + negalfa1xbeta2_index + gamma2_index + delta2_index + IC_index; | ||
|
||
component commitment = HashTreeRootPoseidon(185); | ||
|
||
for (var i = 0; i < 6; i++) { | ||
for (var j = 0; j < 2; j++) { | ||
for (var q = 0; q < k; q++) { | ||
commitment.in[cummulative_index + i*2*k + j*k + q] <== negalfa1xbeta2[i][j][q]; | ||
} | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add an empty line after the bracket |
||
|
||
cummulative_index += 6 * 2 * k; | ||
|
||
for (var i = 0; i < 2; i++) { | ||
for (var j = 0; j < 2; j++) { | ||
for (var q = 0; q < k; q++) { | ||
commitment.in[cummulative_index + i*2*k + j*k + q] <== gamma2[i][j][q]; | ||
} | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add an empty line after the bracket |
||
|
||
cummulative_index += 2 * 2 * k; | ||
|
||
for (var i = 0; i < 2; i++) { | ||
for (var j = 0; j < 2; j++) { | ||
for (var q = 0; q < k; q++) { | ||
commitment.in[cummulative_index + i*2*k + j*k + q] <== delta2[i][j][q]; | ||
} | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add empty line |
||
|
||
cummulative_index += 2 * 2 * k; | ||
|
||
for (var i = 0; i < pubInpCount + 1; i++) { | ||
for (var j = 0; j < 2; j++) { | ||
for (var q = 0; q < k; q++) { | ||
commitment.in[cummulative_index + i*2*k + j*k + q] <== IC[i][j][q]; | ||
} | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add an empty line after the bracket |
||
|
||
cummulative_index += (pubInpCount + 1)*2*k; | ||
|
||
for (var i = 0; i < 2; i++) { | ||
commitment.in[cummulative_index + i] <== originator[i]; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add an empty line after the bracket |
||
|
||
cummulative_index += 2; | ||
|
||
for (var i = 0; i < 2; i++) { | ||
commitment.in[cummulative_index + i] <== nextHeaderHashNum[i]; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add an empty line after the bracket |
||
|
||
cummulative_index += 2; | ||
|
||
for (var i = 0; i < 256; i++) { | ||
commitment.in[cummulative_index + i] <== domain[i]; | ||
} | ||
|
||
cummulative_index += 256; | ||
|
||
commitment.in[cummulative_index] <== historicSyncCommitteeHashTreeRoot; | ||
|
||
cummulative_index += 1; | ||
|
||
commitment.in[cummulative_index] <== syncCommitteeHistoricParticipationIndex; | ||
|
||
out <== commitment.out; | ||
} |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should extend the recursive verification code starting at line 214. Specifically the public inputs part starting line 246. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
pragma circom 2.1.5; | ||
|
||
include "../../../node_modules/circomlib/circuits/comparators.circom"; | ||
|
||
template UpdateSyncCommitteeHistoricParticipation(N, PERIODS) { | ||
signal input participationRateArray[PERIODS]; | ||
signal input currentIndex; | ||
signal input bitmask[N]; | ||
|
||
signal output out[PERIODS]; | ||
|
||
var participationRate = 0; | ||
for (var i=0;i<N;i++) { | ||
participationRate += bitmask[i]; | ||
} | ||
|
||
//Constrain | ||
signal isValidIndex <== LessThan(32)([currentIndex, PERIODS]); | ||
isValidIndex === 1; | ||
|
||
component isZero[PERIODS]; | ||
for (var i=currentIndex;i<PERIODS;i++) { | ||
isZero[i] = IsZero(); | ||
isZero[i].in <== participationRateArray[i]; | ||
isZero[i].out === 1; | ||
} | ||
|
||
for (var i=0;i<currentIndex;i++) { | ||
isZero[i] = IsZero(); | ||
isZero[i].in <== participationRateArray[i]; | ||
isZero[i].out === 0; | ||
} | ||
|
||
//Calc. new entry | ||
var bitmask_sum = 0; | ||
for (var i=0;i<N;i++) { | ||
bitmask_sum += bitmask[i]; | ||
} | ||
|
||
// Assign | ||
for (var i=0;i<currentIndex;i++) { | ||
out[i] <== participationRateArray[i]; | ||
} | ||
|
||
out[currentIndex] <== bitmask_sum; | ||
|
||
for (var i=currentIndex + 1;i<PERIODS;i++) { | ||
out[i] <== 0; | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the domain should also be part of the commitment