mirror of
https://github.com/yi-sun/zk-attestor.git
synced 2026-01-09 21:48:07 -05:00
Refactor: Change variable names to be consistent
This commit is contained in:
@@ -85,20 +85,67 @@ template EthBlockHashHex() {
|
||||
}
|
||||
}
|
||||
|
||||
template EthStorageProof(depth) {
|
||||
template EthStorageProof(maxDepth) {
|
||||
signal input storageRootHexs[64];
|
||||
|
||||
// uint256
|
||||
signal input slotHexLen;
|
||||
signal input slotHexs[64];
|
||||
|
||||
signal input valueRlpHexLen;
|
||||
signal input slotHashHexs[64];
|
||||
signal input valueRlpHexs[66];
|
||||
|
||||
signal input storageRootHexs[64];
|
||||
|
||||
signal input leafRlpLengthHexLen;
|
||||
signal input leafPathRlpHexLen;
|
||||
signal input leafPathPrefixHexLen;
|
||||
signal input leafPathHexLen;
|
||||
signal input leafRlpValueLenHexLen;
|
||||
signal input leafValueLenHexLen;
|
||||
signal input leafRlpHexs[maxLeafRlpHexLen];
|
||||
|
||||
signal input nodeRlpLengthHexLen[maxDepth - 1];
|
||||
signal input nodePathRlpHexLen[maxDepth - 1];
|
||||
signal input nodePathPrefixHexLen[maxDepth - 1];
|
||||
signal input nodePathHexLen[maxDepth - 1];
|
||||
signal input nodeRefHexLen[maxDepth - 1][16];
|
||||
signal input nodeRlpHexs[maxDepth - 1][maxBranchRlpHexLen];
|
||||
|
||||
signal input nodeTypes[maxDepth - 1];
|
||||
signal input depth;
|
||||
|
||||
signal output out;
|
||||
|
||||
component mpt_proof = MPTInclusionFixedKeyHexLen(maxDepth, 64, 66);
|
||||
|
||||
for (var idx = 0; idx < 64; idx++) {
|
||||
keyHexs[idx] <== slotHashHexs[idx];
|
||||
}
|
||||
for (var idx = 0; idx < 66; idx++) {
|
||||
valueHexs[idx] <== valueRlpHexs[idx];
|
||||
}
|
||||
for (var idx = 0; idx < 64; idx++) {
|
||||
rootHashHexs[idx] <== storageRootHexs[idx];
|
||||
}
|
||||
|
||||
signal input leafRlpLengthHexLen;
|
||||
signal input leafPathRlpHexLen;
|
||||
signal input leafPathPrefixHexLen;
|
||||
signal input leafPathHexLen;
|
||||
signal input leafRlpValueLenHexLen;
|
||||
signal input leafValueLenHexLen;
|
||||
signal input leafRlpHexs[maxLeafRlpHexLen];
|
||||
|
||||
signal input nodeRlpLengthHexLen[maxDepth - 1];
|
||||
signal input nodePathRlpHexLen[maxDepth - 1];
|
||||
signal input nodePathPrefixHexLen[maxDepth - 1];
|
||||
signal input nodePathHexLen[maxDepth - 1];
|
||||
signal input nodeRefHexLen[maxDepth - 1][16];
|
||||
signal input nodeRlpHexs[maxDepth - 1][maxBranchRlpHexLen];
|
||||
|
||||
signal input nodeTypes[maxDepth - 1];
|
||||
signal input depth;
|
||||
|
||||
out <== mpt_proof.out;
|
||||
}
|
||||
|
||||
template EthAddressProof(depth) {
|
||||
template EthAddressProof(maxDepth) {
|
||||
signal input stateRootHexs[64];
|
||||
|
||||
signal input addressHexs[40];
|
||||
@@ -108,7 +155,7 @@ template EthAddressProof(depth) {
|
||||
signal output out;
|
||||
}
|
||||
|
||||
template EthAddressStorageProof(addressDepth, storageDepth) {
|
||||
template EthAddressStorageProof(addressMaxDepth, storageMaxDepth) {
|
||||
signal input blockHashHexs[64];
|
||||
|
||||
signal input rlpPrefixHexs[6];
|
||||
@@ -141,7 +188,7 @@ template EthAddressStorageProof(addressDepth, storageDepth) {
|
||||
signal output out;
|
||||
}
|
||||
|
||||
template EthTransactionProof(txMaxDepth) {
|
||||
template EthTransactionProof(maxDepth) {
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -25,19 +25,19 @@ template LeafCheck(maxKeyHexLen, maxValueHexLen) {
|
||||
|
||||
// leaf = rlp_prefix [2]
|
||||
// rlp_length [0, 2 * ceil(log_8(1 + ceil(log_8(keyHexLen + 2)) + 4 + keyHexLen + 2 + 2 * ceil(log_8(maxValueHexLen)) + maxValueHexLen))]
|
||||
// rlp_path_rlp_prefix [2]
|
||||
// rlp_path_rlp_length [0, 2 * ceil(log_8(keyHexLen + 2))]
|
||||
// path_prefix [1, 2]
|
||||
// path_rlp_prefix [2]
|
||||
// path_rlp_length [0, 2 * ceil(log_8(keyHexLen + 2))]
|
||||
// path_prefix [0, 1, 2]
|
||||
// path [0, keyHexLen]
|
||||
// rlp_value_prefix [2]
|
||||
// rlp_value_len [0, 2 * ceil(log_8(maxValueHexLen))]
|
||||
// value_rlp_prefix [2]
|
||||
// value_rlp_length [0, 2 * ceil(log_8(maxValueHexLen))]
|
||||
// value [0, maxValueHexLen]
|
||||
signal input leafRlpLengthHexLen;
|
||||
signal input leafPathRlpHexLen;
|
||||
signal input leafPathRlpLengthHexLen;
|
||||
signal input leafPathPrefixHexLen;
|
||||
signal input leafPathHexLen;
|
||||
signal input leafRlpValueLenHexLen;
|
||||
signal input leafValueLenHexLen;
|
||||
signal input leafValueRlpLengthHexLen;
|
||||
signal input leafValueHexLen;
|
||||
signal input leafRlpHexs[maxLeafRlpHexLen];
|
||||
|
||||
signal output out;
|
||||
@@ -48,11 +48,11 @@ template LeafCheck(maxKeyHexLen, maxValueHexLen) {
|
||||
|
||||
log(keyNibbleHexLen);
|
||||
log(leafRlpLengthHexLen);
|
||||
log(leafPathRlpHexLen);
|
||||
log(leafPathRlpLengthHexLen);
|
||||
log(leafPathPrefixHexLen);
|
||||
log(leafPathHexLen);
|
||||
log(leafRlpValueLenHexLen);
|
||||
log(leafValueLenHexLen);
|
||||
log(leafValueRlpLengthHexLen);
|
||||
log(leafValueHexLen);
|
||||
|
||||
for (var idx = 0; idx < maxKeyHexLen; idx++) {
|
||||
log(keyNibbleHexs[idx]);
|
||||
@@ -79,8 +79,8 @@ template LeafCheck(maxKeyHexLen, maxValueHexLen) {
|
||||
for (var idx = 0; idx < maxLeafRlpHexLen; idx++) {
|
||||
leaf_to_path.in[idx] <== leafRlpHexs[idx];
|
||||
}
|
||||
leaf_to_path.start <== 2 + leafRlpLengthHexLen + 2 + leafPathRlpHexLen + leafPathPrefixHexLen;
|
||||
leaf_to_path.end <== 2 + leafRlpLengthHexLen + 2 + leafPathRlpHexLen + leafPathPrefixHexLen + leafPathHexLen;
|
||||
leaf_to_path.start <== 2 + leafRlpLengthHexLen + 2 + leafPathRlpLengthHexLen + leafPathPrefixHexLen;
|
||||
leaf_to_path.end <== 2 + leafRlpLengthHexLen + 2 + leafPathRlpLengthHexLen + leafPathPrefixHexLen + leafPathHexLen;
|
||||
|
||||
component key_path_match = ArrayEq(maxKeyHexLen);
|
||||
for (var idx = 0; idx < maxKeyHexLen; idx++) {
|
||||
@@ -101,15 +101,15 @@ template LeafCheck(maxKeyHexLen, maxValueHexLen) {
|
||||
for (var idx = 0; idx < maxLeafRlpHexLen; idx++) {
|
||||
leaf_to_value.in[idx] <== leafRlpHexs[idx];
|
||||
}
|
||||
leaf_to_value.start <== 2 + leafRlpLengthHexLen + 2 + leafPathRlpHexLen + leafPathPrefixHexLen + leafPathHexLen + 2 + leafRlpValueLenHexLen;
|
||||
leaf_to_value.end <== 2 + leafRlpLengthHexLen + 2 + leafPathRlpHexLen + leafPathPrefixHexLen + leafPathHexLen + 2 + leafRlpValueLenHexLen + leafValueLenHexLen;
|
||||
leaf_to_value.start <== 2 + leafRlpLengthHexLen + 2 + leafPathRlpLengthHexLen + leafPathPrefixHexLen + leafPathHexLen + 2 + leafValueRlpLengthHexLen;
|
||||
leaf_to_value.end <== 2 + leafRlpLengthHexLen + 2 + leafPathRlpLengthHexLen + leafPathPrefixHexLen + leafPathHexLen + 2 + leafValueRlpLengthHexLen + leafValueHexLen;
|
||||
|
||||
component leaf_value_match = ArrayEq(maxValueHexLen);
|
||||
for (var idx = 0; idx < maxValueHexLen; idx++) {
|
||||
leaf_value_match.a[idx] <== leaf_to_value.out[idx];
|
||||
leaf_value_match.b[idx] <== valueHexs[idx];
|
||||
}
|
||||
leaf_value_match.inLen <== leafValueLenHexLen;
|
||||
leaf_value_match.inLen <== leafValueHexLen;
|
||||
|
||||
out <== key_path + leaf_value_match.out;
|
||||
|
||||
@@ -131,17 +131,19 @@ template ExtensionCheck(maxKeyHexLen, maxNodeRefHexLen) {
|
||||
|
||||
// extension = rlp_prefix [2]
|
||||
// rlp_length [0, 2 * ceil((...))]
|
||||
// rlp_path_rlp_prefix [2]
|
||||
// rlp_path_rlp_length [0, 2 * ceil(log_8(keyHexLen + 2))]
|
||||
// path_rlp_prefix [2]
|
||||
// path_rlp_length [0, 2 * ceil(log_8(keyHexLen + 2))]
|
||||
// path_prefix [1, 2]
|
||||
// path [0, keyHexLen]
|
||||
// rlp_node_ref_prefix [2]
|
||||
// node_ref_rlp_prefix [2]
|
||||
// node_ref [0, 64]
|
||||
signal input nodeRlpLengthHexLen;
|
||||
signal input nodePathRlpHexLen;
|
||||
|
||||
signal input nodePathRlpLengthHexLen;
|
||||
signal input nodePathPrefixHexLen;
|
||||
signal input nodePathHexLen;
|
||||
signal input nodeRefExtHexLen;
|
||||
|
||||
signal input extNodeRefHexLen;
|
||||
signal input nodeRlpHexs[maxExtensionRlpHexLen];
|
||||
|
||||
signal output out;
|
||||
@@ -153,10 +155,10 @@ template ExtensionCheck(maxKeyHexLen, maxNodeRefHexLen) {
|
||||
log(keyNibbleHexLen);
|
||||
log(nodeRefHexLen);
|
||||
log(nodeRlpLengthHexLen);
|
||||
log(nodePathRlpHexLen);
|
||||
log(nodePathRlpLengthHexLen);
|
||||
log(nodePathPrefixHexLen);
|
||||
log(nodePathHexLen);
|
||||
log(nodeRefExtHexLen);
|
||||
log(nodeRefHexLen);
|
||||
|
||||
for (var idx = 0; idx < maxKeyHexLen; idx++) {
|
||||
log(keyNibbleHexs[idx]);
|
||||
@@ -182,8 +184,8 @@ template ExtensionCheck(maxKeyHexLen, maxNodeRefHexLen) {
|
||||
for (var idx = 0; idx < maxExtensionRlpHexLen; idx++) {
|
||||
extension_to_path.in[idx] <== nodeRlpHexs[idx];
|
||||
}
|
||||
extension_to_path.start <== 2 + nodeRlpLengthHexLen + 2 + nodePathRlpHexLen + nodePathPrefixHexLen;
|
||||
extension_to_path.end <== 2 + nodeRlpLengthHexLen + 2 + nodePathRlpHexLen + nodePathPrefixHexLen + nodePathHexLen;
|
||||
extension_to_path.start <== 2 + nodeRlpLengthHexLen + 2 + nodePathRlpLengthHexLen + nodePathPrefixHexLen;
|
||||
extension_to_path.end <== 2 + nodeRlpLengthHexLen + 2 + nodePathRlpLengthHexLen + nodePathPrefixHexLen + nodePathHexLen;
|
||||
|
||||
component key_path_match = ArrayEq(maxKeyHexLen);
|
||||
for (var idx = 0; idx < maxKeyHexLen; idx++) {
|
||||
@@ -204,8 +206,8 @@ template ExtensionCheck(maxKeyHexLen, maxNodeRefHexLen) {
|
||||
for (var idx = 0; idx < maxExtensionRlpHexLen; idx++) {
|
||||
extension_to_node_ref.in[idx] <== nodeRlpHexs[idx];
|
||||
}
|
||||
extension_to_node_ref.start <== 2 + nodeRlpLengthHexLen + 2 + nodePathRlpHexLen + nodePathPrefixHexLen + nodePathHexLen + 2;
|
||||
extension_to_node_ref.end <== 2 + nodeRlpLengthHexLen + 2 + nodePathRlpHexLen + nodePathPrefixHexLen + nodePathHexLen + 2 + nodeRefExtHexLen;
|
||||
extension_to_node_ref.start <== 2 + nodeRlpLengthHexLen + 2 + nodePathRlpLengthHexLen + nodePathPrefixHexLen + nodePathHexLen + 2;
|
||||
extension_to_node_ref.end <== 2 + nodeRlpLengthHexLen + 2 + nodePathRlpLengthHexLen + nodePathPrefixHexLen + nodePathHexLen + 2 + extNodeRefHexLen;
|
||||
|
||||
component node_ref_match = ArrayEq(maxNodeRefHexLen);
|
||||
for (var idx = 0; idx < maxNodeRefHexLen; idx++) {
|
||||
@@ -216,7 +218,7 @@ template ExtensionCheck(maxKeyHexLen, maxNodeRefHexLen) {
|
||||
|
||||
component node_ref_len_match = IsEqual();
|
||||
node_ref_len_match.in[0] <== nodeRefHexLen;
|
||||
node_ref_len_match.in[1] <== nodeRefExtHexLen;
|
||||
node_ref_len_match.in[1] <== extNodeRefHexLen;
|
||||
|
||||
signal node_ref;
|
||||
node_ref <== node_ref_match.out * node_ref_len_match.out;
|
||||
@@ -229,99 +231,7 @@ template ExtensionCheck(maxKeyHexLen, maxNodeRefHexLen) {
|
||||
log(node_ref_len_match.out);
|
||||
}
|
||||
|
||||
template BranchFixedKeyHexLen(maxNodeRefHexLen) {
|
||||
var maxBranchRlpHexLen = 1064;
|
||||
var BRANCH_BITS = 11;
|
||||
|
||||
signal input keyNibble;
|
||||
|
||||
signal input nodeRefHexLen;
|
||||
signal input nodeRefHexs[maxNodeRefHexLen];
|
||||
|
||||
// branch = rlp_prefix [2]
|
||||
// rlp_length [0, 8]
|
||||
// v0_rlp_prefix [2]
|
||||
// v0 [0, 64]
|
||||
// ...
|
||||
// v15_rlp_prefix [2]
|
||||
// v15 [0, 64]
|
||||
// vt_rlp_prefix [2]
|
||||
signal input nodeRlpLengthHexLen;
|
||||
// v0, ..., v15 _or_ node_ref
|
||||
signal input nodeValueLenHexLen[16];
|
||||
signal input nodeRlpHexs[maxBranchRlpHexLen];
|
||||
|
||||
signal output out;
|
||||
|
||||
log(111111100003);
|
||||
log(maxNodeRefHexLen);
|
||||
log(keyNibble);
|
||||
log(nodeRefHexLen);
|
||||
log(nodeRlpLengthHexLen);
|
||||
log(maxBranchRlpHexLen);
|
||||
for (var idx = 0; idx < maxNodeRefHexLen; idx++) {
|
||||
log(nodeRefHexs[idx]);
|
||||
}
|
||||
for (var idx = 0; idx < 16; idx++) {
|
||||
log(nodeValueLenHexLen[idx]);
|
||||
}
|
||||
for (var idx = 0; idx < maxBranchRlpHexLen; idx++) {
|
||||
log(nodeRlpHexs[idx]);
|
||||
}
|
||||
|
||||
// check input hexs are hexs
|
||||
component hexChecks[maxBranchRlpHexLen];
|
||||
for (var idx = 0; idx < maxBranchRlpHexLen; idx++) {
|
||||
hexChecks[idx] = Num2Bits(4);
|
||||
hexChecks[idx].in <== nodeRlpHexs[idx];
|
||||
}
|
||||
|
||||
// * [ignore] check validity of RLP encoding
|
||||
// * [ignore] check validity of inputs
|
||||
|
||||
// * check node_ref at index of nibble matches child
|
||||
signal nodeRefStartHexIdx[16];
|
||||
nodeRefStartHexIdx[0] <== 2 + nodeRlpLengthHexLen + 2;
|
||||
for (var idx = 1; idx < 16; idx++) {
|
||||
nodeRefStartHexIdx[idx] <== nodeRefStartHexIdx[idx - 1] + nodeValueLenHexLen[idx - 1] + 2;
|
||||
}
|
||||
|
||||
component nodeStartSelector = Multiplexer(1, 16);
|
||||
component nodeRefLenSelector = Multiplexer(1, 16);
|
||||
for (var idx = 0; idx < 16; idx++) {
|
||||
nodeStartSelector.inp[idx][0] <== nodeRefStartHexIdx[idx];
|
||||
nodeRefLenSelector.inp[idx][0] <== nodeValueLenHexLen[idx];
|
||||
}
|
||||
nodeStartSelector.sel <== keyNibble;
|
||||
nodeRefLenSelector.sel <== keyNibble;
|
||||
|
||||
// find the node_ref at the index of nibble
|
||||
component branch_to_node_ref = SubArray(maxBranchRlpHexLen, maxNodeRefHexLen, BRANCH_BITS);
|
||||
for (var idx = 0; idx < maxBranchRlpHexLen; idx++) {
|
||||
branch_to_node_ref.in[idx] <== nodeRlpHexs[idx];
|
||||
}
|
||||
branch_to_node_ref.start <== nodeStartSelector.out[0];
|
||||
branch_to_node_ref.end <== nodeStartSelector.out[0] + nodeRefLenSelector.out[0];
|
||||
|
||||
component node_ref_match = ArrayEq(maxNodeRefHexLen);
|
||||
for (var idx = 0; idx < maxNodeRefHexLen; idx++) {
|
||||
node_ref_match.a[idx] <== branch_to_node_ref.out[idx];
|
||||
node_ref_match.b[idx] <== nodeRefHexs[idx];
|
||||
}
|
||||
node_ref_match.inLen <== nodeRefHexLen;
|
||||
|
||||
component node_ref_len_match = IsEqual();
|
||||
node_ref_len_match.in[0] <== nodeRefHexLen;
|
||||
node_ref_len_match.in[1] <== nodeRefLenSelector.out[0];
|
||||
|
||||
out <== node_ref_match.out + node_ref_len_match.out;
|
||||
|
||||
log(out);
|
||||
log(node_ref_match.out);
|
||||
log(node_ref_len_match.out);
|
||||
}
|
||||
|
||||
template EmptyTerminalBranchCheck(maxNodeRefHexLen, maxValueHexLen) {
|
||||
template EmptyVtBranchCheck(maxNodeRefHexLen) {
|
||||
var maxBranchRlpHexLen = 1064;
|
||||
var BRANCH_BITS = 11;
|
||||
|
||||
@@ -338,18 +248,17 @@ template EmptyTerminalBranchCheck(maxNodeRefHexLen, maxValueHexLen) {
|
||||
// v15_rlp_prefix [2]
|
||||
// v15 [0, 64]
|
||||
// vt_rlp_prefix [2]
|
||||
// vt_rlp_len [0]
|
||||
// vt_rlp_length [0]
|
||||
// vt [0]
|
||||
signal input nodeRlpLengthHexLen;
|
||||
// v0, ..., v15: literal _or_ node_ref
|
||||
signal input nodeValueLenHexLen[16];
|
||||
signal input nodeValueHexLen[16];
|
||||
signal input nodeRlpHexs[maxBranchRlpHexLen];
|
||||
|
||||
signal output out;
|
||||
|
||||
log(111111100004);
|
||||
log(maxNodeRefHexLen);
|
||||
log(maxValueHexLen);
|
||||
|
||||
log(keyNibble);
|
||||
log(nodeRefHexLen);
|
||||
@@ -360,7 +269,7 @@ template EmptyTerminalBranchCheck(maxNodeRefHexLen, maxValueHexLen) {
|
||||
log(nodeRefHexs[idx]);
|
||||
}
|
||||
for (var idx = 0; idx < 16; idx++) {
|
||||
log(nodeValueLenHexLen[idx]);
|
||||
log(nodeValueHexLen[idx]);
|
||||
}
|
||||
for (var idx = 0; idx < maxBranchRlpHexLen; idx++) {
|
||||
log(nodeRlpHexs[idx]);
|
||||
@@ -383,7 +292,7 @@ template EmptyTerminalBranchCheck(maxNodeRefHexLen, maxValueHexLen) {
|
||||
signal nodeRefStartHexIdx[16];
|
||||
nodeRefStartHexIdx[0] <== 2 + nodeRlpLengthHexLen + 2;
|
||||
for (var idx = 1; idx < 16; idx++) {
|
||||
nodeRefStartHexIdx[idx] <== nodeRefStartHexIdx[idx - 1] + nodeValueLenHexLen[idx - 1] + 2;
|
||||
nodeRefStartHexIdx[idx] <== nodeRefStartHexIdx[idx - 1] + nodeValueHexLen[idx - 1] + 2;
|
||||
}
|
||||
|
||||
// check node_ref at index of nibble / value matches child / value
|
||||
@@ -391,7 +300,7 @@ template EmptyTerminalBranchCheck(maxNodeRefHexLen, maxValueHexLen) {
|
||||
component nodeRefLenSelector = Multiplexer(1, 16);
|
||||
for (var idx = 0; idx < 16; idx++) {
|
||||
nodeStartSelector.inp[idx][0] <== nodeRefStartHexIdx[idx];
|
||||
nodeRefLenSelector.inp[idx][0] <== nodeValueLenHexLen[idx];
|
||||
nodeRefLenSelector.inp[idx][0] <== nodeValueHexLen[idx];
|
||||
}
|
||||
nodeStartSelector.sel <== keyNibble;
|
||||
nodeRefLenSelector.sel <== keyNibble;
|
||||
@@ -443,10 +352,10 @@ template NonTerminalBranchCheck(maxNodeRefHexLen, maxValueHexLen) {
|
||||
// vt [0, maxValueHexLen]
|
||||
signal input nodeRlpLengthHexLen;
|
||||
// v0, ..., v15: literal _or_ node_ref
|
||||
signal input nodeValueLenHexLen[16];
|
||||
signal input nodeValueHexLen[16];
|
||||
// vt: NULL or rlp(value)
|
||||
signal input nodeVtRlpLenHexLen;
|
||||
signal input nodeVtValueHexLen;
|
||||
signal input nodeVtRlpLengthHexLen;
|
||||
signal input nodeVtHexLen;
|
||||
|
||||
signal input nodeRlpHexs[maxBranchRlpHexLen];
|
||||
|
||||
@@ -459,15 +368,15 @@ template NonTerminalBranchCheck(maxNodeRefHexLen, maxValueHexLen) {
|
||||
log(keyNibble);
|
||||
log(nodeRefHexLen);
|
||||
log(nodeRlpLengthHexLen);
|
||||
log(nodeVtRlpLenHexLen);
|
||||
log(nodeVtValueHexLen);
|
||||
log(nodeVtRlpLengthHexLen);
|
||||
log(nodeVtHexLen);
|
||||
|
||||
log(maxBranchRlpHexLen);
|
||||
for (var idx = 0; idx < maxNodeRefHexLen; idx++) {
|
||||
log(nodeRefHexs[idx]);
|
||||
}
|
||||
for (var idx = 0; idx < 16; idx++) {
|
||||
log(nodeValueLenHexLen[idx]);
|
||||
log(nodeValueHexLen[idx]);
|
||||
}
|
||||
for (var idx = 0; idx < maxBranchRlpHexLen; idx++) {
|
||||
log(nodeRlpHexs[idx]);
|
||||
@@ -490,7 +399,7 @@ template NonTerminalBranchCheck(maxNodeRefHexLen, maxValueHexLen) {
|
||||
signal nodeRefStartHexIdx[16];
|
||||
nodeRefStartHexIdx[0] <== 2 + nodeRlpLengthHexLen + 2;
|
||||
for (var idx = 1; idx < 16; idx++) {
|
||||
nodeRefStartHexIdx[idx] <== nodeRefStartHexIdx[idx - 1] + nodeValueLenHexLen[idx - 1] + 2;
|
||||
nodeRefStartHexIdx[idx] <== nodeRefStartHexIdx[idx - 1] + nodeValueHexLen[idx - 1] + 2;
|
||||
}
|
||||
|
||||
// check node_ref at index of nibble / value matches child / value
|
||||
@@ -498,7 +407,7 @@ template NonTerminalBranchCheck(maxNodeRefHexLen, maxValueHexLen) {
|
||||
component nodeRefLenSelector = Multiplexer(1, 16);
|
||||
for (var idx = 0; idx < 16; idx++) {
|
||||
nodeStartSelector.inp[idx][0] <== nodeRefStartHexIdx[idx];
|
||||
nodeRefLenSelector.inp[idx][0] <== nodeValueLenHexLen[idx];
|
||||
nodeRefLenSelector.inp[idx][0] <== nodeValueHexLen[idx];
|
||||
}
|
||||
nodeStartSelector.sel <== keyNibble;
|
||||
nodeRefLenSelector.sel <== keyNibble;
|
||||
@@ -544,14 +453,14 @@ template TerminalBranchCheck(maxNodeRefHexLen, maxValueHexLen) {
|
||||
// v15_rlp_prefix [2]
|
||||
// v15 [0, 64]
|
||||
// vt_rlp_prefix [2]
|
||||
// vt_rlp_len [0, 2 * ceil(log_8(maxValueHexLen / 2))]
|
||||
// vt_rlp_length [0, 2 * ceil(log_8(maxValueHexLen / 2))]
|
||||
// vt [0, maxValueHexLen]
|
||||
signal input nodeRlpLengthHexLen;
|
||||
// v0, ..., v15: literal _or_ node_ref
|
||||
signal input nodeValueLenHexLen[16];
|
||||
signal input nodeValueHexLen[16];
|
||||
// vt: NULL or rlp(value)
|
||||
signal input nodeVtRlpLenHexLen;
|
||||
signal input nodeVtValueHexLen;
|
||||
signal input nodeVtRlpLengthHexLen;
|
||||
signal input nodeVtHexLen;
|
||||
|
||||
signal input nodeRlpHexs[maxBranchRlpHexLen];
|
||||
|
||||
@@ -563,15 +472,15 @@ template TerminalBranchCheck(maxNodeRefHexLen, maxValueHexLen) {
|
||||
|
||||
log(valueHexLen);
|
||||
log(nodeRlpLengthHexLen);
|
||||
log(nodeVtRlpLenHexLen);
|
||||
log(nodeVtValueHexLen);
|
||||
log(nodeVtRlpLengthHexLen);
|
||||
log(nodeVtHexLen);
|
||||
|
||||
log(maxBranchRlpHexLen);
|
||||
for (var idx = 0; idx < maxValueHexLen; idx++) {
|
||||
log(valueHexs[idx]);
|
||||
}
|
||||
for (var idx = 0; idx < 16; idx++) {
|
||||
log(nodeValueLenHexLen[idx]);
|
||||
log(nodeValueHexLen[idx]);
|
||||
}
|
||||
for (var idx = 0; idx < maxBranchRlpHexLen; idx++) {
|
||||
log(nodeRlpHexs[idx]);
|
||||
@@ -595,7 +504,7 @@ template TerminalBranchCheck(maxNodeRefHexLen, maxValueHexLen) {
|
||||
|
||||
// find starting point of value
|
||||
signal valueStartHexIdx;
|
||||
valueStartHexIdx <== 2 + nodeRlpLengthHexLen + 2 + 2 * 16 + nodeValueLenHexLen[0] + nodeValueLenHexLen[1] + nodeValueLenHexLen[2] + nodeValueLenHexLen[3] + nodeValueLenHexLen[4] + nodeValueLenHexLen[5] + nodeValueLenHexLen[6] + nodeValueLenHexLen[7] + nodeValueLenHexLen[8] + nodeValueLenHexLen[9] + nodeValueLenHexLen[10] + nodeValueLenHexLen[11] + nodeValueLenHexLen[12] + nodeValueLenHexLen[13] + nodeValueLenHexLen[14] + nodeValueLenHexLen[15] + nodeVtRlpLenHexLen;
|
||||
valueStartHexIdx <== 2 + nodeRlpLengthHexLen + 2 + 2 * 16 + nodeValueHexLen[0] + nodeValueHexLen[1] + nodeValueHexLen[2] + nodeValueHexLen[3] + nodeValueHexLen[4] + nodeValueHexLen[5] + nodeValueHexLen[6] + nodeValueHexLen[7] + nodeValueHexLen[8] + nodeValueHexLen[9] + nodeValueHexLen[10] + nodeValueHexLen[11] + nodeValueHexLen[12] + nodeValueHexLen[13] + nodeValueHexLen[14] + nodeValueHexLen[15] + nodeVtRlpLengthHexLen;
|
||||
|
||||
// check vt matches value
|
||||
component branch_to_value = SubArray(maxBranchRlpHexLen, maxValueHexLen, BRANCH_BITS);
|
||||
@@ -603,7 +512,7 @@ template TerminalBranchCheck(maxNodeRefHexLen, maxValueHexLen) {
|
||||
branch_to_value.in[idx] <== nodeRlpHexs[idx];
|
||||
}
|
||||
branch_to_value.start <== valueStartHexIdx;
|
||||
branch_to_value.end <== valueStartHexIdx + nodeVtValueHexLen;
|
||||
branch_to_value.end <== valueStartHexIdx + nodeVtHexLen;
|
||||
|
||||
component value_match = ArrayEq(maxValueHexLen);
|
||||
for (var idx = 0; idx < maxValueHexLen; idx++) {
|
||||
@@ -614,7 +523,7 @@ template TerminalBranchCheck(maxNodeRefHexLen, maxValueHexLen) {
|
||||
|
||||
component value_len_match = IsEqual();
|
||||
value_len_match.in[0] <== valueHexLen;
|
||||
value_len_match.in[1] <== nodeVtValueHexLen;
|
||||
value_len_match.in[1] <== nodeVtHexLen;
|
||||
|
||||
out <== value_match.out + value_len_match.out;
|
||||
|
||||
@@ -638,47 +547,52 @@ template MPTInclusionFixedKeyHexLen(maxDepth, keyHexLen, maxValueHexLen) {
|
||||
signal input rootHashHexs[64];
|
||||
|
||||
// leaf = rlp_prefix [2]
|
||||
// rlp_length [0, 2 * ceil(log_8(1 + ceil(log_8(keyHexLen + 2)) + 4 + keyHexLen + 2 + 2 * ceil(log_8(maxValueHexLen)) + maxValueHexLen))]
|
||||
// rlp_path_rlp_prefix [2]
|
||||
// rlp_path_rlp_length [0, 2 * ceil(log_8(keyHexLen + 2))]
|
||||
// path_prefix [1, 2]
|
||||
// rlp_length [0, 2 * ceil(log_8(1 + ceil(log_8(4 * keyHexLen + 4)) + 4 + keyHexLen + 2 + 2 * ceil(log_8(maxValueHexLen)) + maxValueHexLen))]
|
||||
// path_rlp_prefix [2]
|
||||
// path_rlp_length [0, 2 * ceil(log_8(keyHexLen + 2))]
|
||||
// path_prefix [0, 1, 2] // 0 if path is literal
|
||||
// path [0, keyHexLen]
|
||||
// rlp_value_prefix [2]
|
||||
// rlp_value_len [0, 2 * ceil(log_8(maxValueHexLen))]
|
||||
// value_rlp_prefix [2]
|
||||
// value_rlp_length [0, 2 * ceil(log_8(maxValueHexLen))]
|
||||
// value [0, maxValueHexLen]
|
||||
signal input leafRlpLengthHexLen;
|
||||
signal input leafPathRlpHexLen;
|
||||
|
||||
signal input leafPathRlpLengthHexLen;
|
||||
signal input leafPathPrefixHexLen;
|
||||
signal input leafPathHexLen;
|
||||
signal input leafRlpValueLenHexLen;
|
||||
signal input leafValueLenHexLen;
|
||||
|
||||
signal input leafValueRlpLengthHexLen;
|
||||
signal input leafValueHexLen;
|
||||
|
||||
signal input leafRlpHexs[maxLeafRlpHexLen];
|
||||
|
||||
// extension = rlp_prefix [2]
|
||||
// rlp_length [0, 2 * ceil((...))]
|
||||
// rlp_path_rlp_prefix [2]
|
||||
// rlp_path_rlp_length [0, 2 * ceil(log_8(keyHexLen + 2))]
|
||||
// path_prefix [1, 2]
|
||||
// path_rlp_prefix [2]
|
||||
// path_rlp_length [0, 2 * ceil(log_8(4 * keyHexLen + 4))]
|
||||
// path_prefix [0, 1, 2] // 0 if path is literal
|
||||
// path [0, keyHexLen]
|
||||
// rlp_node_ref_prefix [2]
|
||||
// nodeRef_rlp_prefix [2]
|
||||
// node_ref [0, 64]
|
||||
// branch = rlp_prefix [2]
|
||||
// rlp_length [0, 8]
|
||||
// rlp_length [0, 6]
|
||||
// v0_rlp_prefix [2]
|
||||
// v0 [0, 64]
|
||||
// ...
|
||||
// v15_rlp_prefix [2]
|
||||
// v15 [0, 64]
|
||||
// vt_prefix [2]
|
||||
signal input nodeRlpLengthHexLen[maxDepth - 1];
|
||||
signal input nodePathRlpHexLen[maxDepth - 1];
|
||||
// vt_rlp_prefix [2]
|
||||
signal input nodeRlpLengthHexLen[maxDepth - 1];
|
||||
|
||||
signal input nodePathRlpLengthHexLen[maxDepth - 1];
|
||||
signal input nodePathPrefixHexLen[maxDepth - 1];
|
||||
signal input nodePathHexLen[maxDepth - 1];
|
||||
signal input nodeRefHexLen[maxDepth - 1][16];
|
||||
signal input nodePathHexLen[maxDepth - 1];
|
||||
|
||||
signal input nodeRefHexLen[maxDepth - 1][16];
|
||||
|
||||
signal input nodeRlpHexs[maxDepth - 1][maxBranchRlpHexLen];
|
||||
|
||||
// index 0 = root
|
||||
// 0 = branch, 1 = extension
|
||||
// index 0 = root; value 0 = branch, 1 = extension
|
||||
signal input nodeTypes[maxDepth - 1];
|
||||
signal input depth;
|
||||
|
||||
@@ -701,7 +615,7 @@ template MPTInclusionFixedKeyHexLen(maxDepth, keyHexLen, maxValueHexLen) {
|
||||
for (var idx = 0; idx < maxLeafRlpHexLen; idx++) {
|
||||
leafHash.in[idx] <== leafRlpHexs[idx];
|
||||
}
|
||||
leafHash.inLen <== 2 + leafRlpLengthHexLen + 2 + leafPathRlpHexLen + leafPathPrefixHexLen + leafPathHexLen + 2 + leafRlpValueLenHexLen + leafValueLenHexLen;
|
||||
leafHash.inLen <== 2 + leafRlpLengthHexLen + 2 + leafPathRlpLengthHexLen + leafPathPrefixHexLen + leafPathHexLen + 2 + leafValueRlpLengthHexLen + leafValueHexLen;
|
||||
|
||||
// hashes of nodes along path
|
||||
var maxNodeRlpHexLen = 1064;
|
||||
@@ -712,7 +626,7 @@ template MPTInclusionFixedKeyHexLen(maxDepth, keyHexLen, maxValueHexLen) {
|
||||
for (var idx = 0; idx < maxNodeRlpHexLen; idx++) {
|
||||
nodeHashes[layer].in[idx] <== nodeRlpHexs[layer][idx];
|
||||
}
|
||||
nodeHashes[layer].inLen <== nodeTypes[layer] * (2 + nodeRlpLengthHexLen[layer] + 2 + nodePathRlpHexLen[layer] + nodePathPrefixHexLen[layer] + nodePathHexLen[layer] + 2 + nodeRefHexLen[layer][0] - (2 + nodeRlpLengthHexLen[layer] + 2 * 17 + nodeRefHexLen[layer][0] + nodeRefHexLen[layer][1] + nodeRefHexLen[layer][2] + nodeRefHexLen[layer][3] + nodeRefHexLen[layer][4] + nodeRefHexLen[layer][5] + nodeRefHexLen[layer][6] + nodeRefHexLen[layer][7] + nodeRefHexLen[layer][8] + nodeRefHexLen[layer][9] + nodeRefHexLen[layer][10] + nodeRefHexLen[layer][11] + nodeRefHexLen[layer][12] + nodeRefHexLen[layer][13] + nodeRefHexLen[layer][14] + nodeRefHexLen[layer][15])) + (2 + nodeRlpLengthHexLen[layer] + 2 * 17 + nodeRefHexLen[layer][0] + nodeRefHexLen[layer][1] + nodeRefHexLen[layer][2] + nodeRefHexLen[layer][3] + nodeRefHexLen[layer][4] + nodeRefHexLen[layer][5] + nodeRefHexLen[layer][6] + nodeRefHexLen[layer][7] + nodeRefHexLen[layer][8] + nodeRefHexLen[layer][9] + nodeRefHexLen[layer][10] + nodeRefHexLen[layer][11] + nodeRefHexLen[layer][12] + nodeRefHexLen[layer][13] + nodeRefHexLen[layer][14] + nodeRefHexLen[layer][15]);
|
||||
nodeHashes[layer].inLen <== nodeTypes[layer] * (2 + nodeRlpLengthHexLen[layer] + 2 + nodePathRlpLengthHexLen[layer] + nodePathPrefixHexLen[layer] + nodePathHexLen[layer] + 2 + nodeRefHexLen[layer][0] - (2 + nodeRlpLengthHexLen[layer] + 2 * 17 + nodeRefHexLen[layer][0] + nodeRefHexLen[layer][1] + nodeRefHexLen[layer][2] + nodeRefHexLen[layer][3] + nodeRefHexLen[layer][4] + nodeRefHexLen[layer][5] + nodeRefHexLen[layer][6] + nodeRefHexLen[layer][7] + nodeRefHexLen[layer][8] + nodeRefHexLen[layer][9] + nodeRefHexLen[layer][10] + nodeRefHexLen[layer][11] + nodeRefHexLen[layer][12] + nodeRefHexLen[layer][13] + nodeRefHexLen[layer][14] + nodeRefHexLen[layer][15])) + (2 + nodeRlpLengthHexLen[layer] + 2 * 17 + nodeRefHexLen[layer][0] + nodeRefHexLen[layer][1] + nodeRefHexLen[layer][2] + nodeRefHexLen[layer][3] + nodeRefHexLen[layer][4] + nodeRefHexLen[layer][5] + nodeRefHexLen[layer][6] + nodeRefHexLen[layer][7] + nodeRefHexLen[layer][8] + nodeRefHexLen[layer][9] + nodeRefHexLen[layer][10] + nodeRefHexLen[layer][11] + nodeRefHexLen[layer][12] + nodeRefHexLen[layer][13] + nodeRefHexLen[layer][14] + nodeRefHexLen[layer][15]);
|
||||
}
|
||||
|
||||
// check rootHash
|
||||
@@ -741,9 +655,6 @@ template MPTInclusionFixedKeyHexLen(maxDepth, keyHexLen, maxValueHexLen) {
|
||||
start[layer + 1] <== start[layer] + 1 - nodeTypes[layer] + nodeTypes[layer] * (nodePathHexLen[layer] + isLiteralPath[layer].out);
|
||||
}
|
||||
|
||||
// constrain Leaf: rlp([prefix (20 or 3) | path, value])
|
||||
component leaf = LeafCheck(keyHexLen, maxValueHexLen);
|
||||
|
||||
component leafStartSelector = Multiplexer(1, maxDepth);
|
||||
for (var idx = 0; idx < maxDepth; idx++) {
|
||||
leafStartSelector.inp[idx][0] <== start[idx];
|
||||
@@ -757,6 +668,8 @@ template MPTInclusionFixedKeyHexLen(maxDepth, keyHexLen, maxValueHexLen) {
|
||||
leafSelector.start <== leafStartSelector.out[0];
|
||||
leafSelector.end <== keyHexLen;
|
||||
|
||||
// constrain Leaf: rlp([prefix (20 or 3) | path, value])
|
||||
component leaf = LeafCheck(keyHexLen, maxValueHexLen);
|
||||
leaf.keyNibbleHexLen <== leafSelector.outLen;
|
||||
for (var idx = 0; idx < keyHexLen; idx++) {
|
||||
leaf.keyNibbleHexs[idx] <== leafSelector.out[idx];
|
||||
@@ -765,11 +678,11 @@ template MPTInclusionFixedKeyHexLen(maxDepth, keyHexLen, maxValueHexLen) {
|
||||
leaf.valueHexs[idx] <== valueHexs[idx];
|
||||
}
|
||||
leaf.leafRlpLengthHexLen <== leafRlpLengthHexLen;
|
||||
leaf.leafPathRlpHexLen <== leafPathRlpHexLen;
|
||||
leaf.leafPathRlpLengthHexLen <== leafPathRlpLengthHexLen;
|
||||
leaf.leafPathPrefixHexLen <== leafPathPrefixHexLen;
|
||||
leaf.leafPathHexLen <== leafPathHexLen;
|
||||
leaf.leafRlpValueLenHexLen <== leafRlpValueLenHexLen;
|
||||
leaf.leafValueLenHexLen <== leafValueLenHexLen;
|
||||
leaf.leafValueRlpLengthHexLen <== leafValueRlpLengthHexLen;
|
||||
leaf.leafValueHexLen <== leafValueHexLen;
|
||||
for (var idx = 0; idx < maxLeafRlpHexLen; idx++) {
|
||||
leaf.leafRlpHexs[idx] <== leafRlpHexs[idx];
|
||||
}
|
||||
@@ -814,10 +727,10 @@ template MPTInclusionFixedKeyHexLen(maxDepth, keyHexLen, maxValueHexLen) {
|
||||
}
|
||||
|
||||
exts[layer].nodeRlpLengthHexLen <== nodeRlpLengthHexLen[layer];
|
||||
exts[layer].nodePathRlpHexLen <== nodePathRlpHexLen[layer];
|
||||
exts[layer].nodePathRlpLengthHexLen <== nodePathRlpLengthHexLen[layer];
|
||||
exts[layer].nodePathPrefixHexLen <== nodePathPrefixHexLen[layer];
|
||||
exts[layer].nodePathHexLen <== nodePathHexLen[layer];
|
||||
exts[layer].nodeRefExtHexLen <== nodeRefHexLen[layer][0];
|
||||
exts[layer].extNodeRefHexLen <== nodeRefHexLen[layer][0];
|
||||
for (var idx = 0; idx < maxExtensionRlpHexLen; idx++) {
|
||||
exts[layer].nodeRlpHexs[idx] <== nodeRlpHexs[layer][idx];
|
||||
}
|
||||
@@ -827,7 +740,7 @@ template MPTInclusionFixedKeyHexLen(maxDepth, keyHexLen, maxValueHexLen) {
|
||||
component branches[maxDepth - 1];
|
||||
component nibbleSelector[maxDepth - 1];
|
||||
for (var layer = 0; layer < maxDepth - 1; layer++) {
|
||||
branches[layer] = BranchFixedKeyHexLen(64);
|
||||
branches[layer] = EmptyVtBranchCheck(64);
|
||||
|
||||
nibbleSelector[layer] = Multiplexer(1, keyHexLen);
|
||||
for (var idx = 0; idx < keyHexLen; idx++) {
|
||||
@@ -853,7 +766,7 @@ template MPTInclusionFixedKeyHexLen(maxDepth, keyHexLen, maxValueHexLen) {
|
||||
branches[layer].nodeRlpLengthHexLen <== nodeRlpLengthHexLen[layer];
|
||||
// v0, ..., v15 _or_ node_ref
|
||||
for (var idx = 0; idx < 16; idx++) {
|
||||
branches[layer].nodeValueLenHexLen[idx] <== nodeRefHexLen[layer][idx];
|
||||
branches[layer].nodeValueHexLen[idx] <== nodeRefHexLen[layer][idx];
|
||||
}
|
||||
for (var idx = 0; idx < maxBranchRlpHexLen; idx++) {
|
||||
branches[layer].nodeRlpHexs[idx] <== nodeRlpHexs[layer][idx];
|
||||
@@ -897,36 +810,38 @@ template MPTInclusion(maxDepth, maxKeyHexLen, maxValueHexLen) {
|
||||
|
||||
// leaf = rlp_prefix [2]
|
||||
// rlp_length [0, 2 * ceil(log_8(1 + ceil(log_8(maxKeyHexLen + 2)) + 4 + maxKeyHexLen + 2 + 2 * ceil(log_8(maxValueHexLen)) + maxValueHexLen))]
|
||||
// rlp_path_rlp_prefix [2]
|
||||
// rlp_path_rlp_length [0, 2 * ceil(log_8(maxKeyHexLen + 2))]
|
||||
// path_rlp_prefix [2]
|
||||
// path_rlp_length [0, 2 * ceil(log_8(maxKeyHexLen + 2))]
|
||||
// path_prefix [1, 2]
|
||||
// path [0, maxKeyHexLen]
|
||||
// rlp_value_prefix [2]
|
||||
// rlp_value_len [0, 2 * ceil(log_8(maxValueHexLen))]
|
||||
// value_rlp_prefix [2]
|
||||
// value_rlp_length [0, 2 * ceil(log_8(maxValueHexLen))]
|
||||
// value [0, maxValueHexLen]
|
||||
signal input leafRlpLengthHexLen;
|
||||
signal input leafPathRlpHexLen;
|
||||
|
||||
signal input leafPathRlpLengthHexLen;
|
||||
signal input leafPathPrefixHexLen;
|
||||
signal input leafPathHexLen;
|
||||
signal input leafRlpValueLenHexLen;
|
||||
signal input leafValueLenHexLen;
|
||||
|
||||
signal input leafValueRlpLengthHexLen;
|
||||
signal input leafValueHexLen;
|
||||
signal input leafRlpHexs[maxLeafRlpHexLen];
|
||||
|
||||
// terminal branch info
|
||||
signal input terminalBranchRlpLengthHexLen;
|
||||
signal input terminalBranchNodeRefHexLen[16];
|
||||
signal input terminalBranchVtRlpLenHexLen;
|
||||
signal input terminalBranchVtValueHexLen;
|
||||
signal input terminalBranchVtRlpLengthHexLen;
|
||||
signal input terminalBranchVtHexLen;
|
||||
|
||||
signal input terminalBranchRlpHexs[maxBranchRlpHexLen];
|
||||
|
||||
// extension = rlp_prefix [2]
|
||||
// rlp_length [0, 2 * ceil((...))]
|
||||
// rlp_path_rlp_prefix [2]
|
||||
// rlp_path_rlp_length [0, 2 * ceil(log_8(maxKeyHexLen + 2))]
|
||||
// path_rlp_prefix [2]
|
||||
// path_rlp_length [0, 2 * ceil(log_8(maxKeyHexLen + 2))]
|
||||
// path_prefix [1, 2]
|
||||
// path [0, maxKeyHexLen]
|
||||
// rlp_node_ref_prefix [2]
|
||||
// node_ref_rlp_prefix [2]
|
||||
// node_ref [0, 64]
|
||||
// branch = rlp_prefix [2]
|
||||
// rlp_length [0, 8]
|
||||
@@ -936,15 +851,18 @@ template MPTInclusion(maxDepth, maxKeyHexLen, maxValueHexLen) {
|
||||
// v15_rlp_prefix [2]
|
||||
// v15 [0, 64]
|
||||
// vt_rlp_prefix [2]
|
||||
// vt_rlp_len [0, 2 * ceil(log_8(maxValueHexLen / 2))]
|
||||
// vt_rlp_length [0, 2 * ceil(log_8(maxValueHexLen / 2))]
|
||||
// vt [0, maxValueHexLen]
|
||||
signal input nodeRlpLengthHexLen[maxDepth - 1];
|
||||
signal input nodePathRlpHexLen[maxDepth - 1];
|
||||
signal input nodeRlpLengthHexLen[maxDepth - 1];
|
||||
|
||||
signal input nodePathRlpLengthHexLen[maxDepth - 1];
|
||||
signal input nodePathPrefixHexLen[maxDepth - 1];
|
||||
signal input nodePathHexLen[maxDepth - 1];
|
||||
signal input nodePathHexLen[maxDepth - 1];
|
||||
|
||||
signal input nodeRefHexLen[maxDepth - 1][16];
|
||||
signal input nodeVtRlpLenHexLen[maxDepth - 1];
|
||||
signal input nodeVtValueHexLen[maxDepth - 1];
|
||||
|
||||
signal input nodeVtRlpLengthHexLen[maxDepth - 1];
|
||||
signal input nodeVtHexLen[maxDepth - 1];
|
||||
|
||||
signal input nodeRlpHexs[maxDepth - 1][maxBranchRlpHexLen];
|
||||
|
||||
@@ -996,7 +914,7 @@ template MPTInclusion(maxDepth, maxKeyHexLen, maxValueHexLen) {
|
||||
terminalHash.in[idx] <== terminalBranchRlpHexs[idx];
|
||||
}
|
||||
}
|
||||
terminalHash.inLen <== isTerminalBranch * ((2 + terminalBranchRlpLengthHexLen + 2 * 17 + terminalBranchNodeRefHexLen[0] + terminalBranchNodeRefHexLen[1] + terminalBranchNodeRefHexLen[2] + terminalBranchNodeRefHexLen[3] + terminalBranchNodeRefHexLen[4] + terminalBranchNodeRefHexLen[5] + terminalBranchNodeRefHexLen[6] + terminalBranchNodeRefHexLen[7] + terminalBranchNodeRefHexLen[8] + terminalBranchNodeRefHexLen[9] + terminalBranchNodeRefHexLen[10] + terminalBranchNodeRefHexLen[11] + terminalBranchNodeRefHexLen[12] + terminalBranchNodeRefHexLen[13] + terminalBranchNodeRefHexLen[14] + terminalBranchNodeRefHexLen[15] + terminalBranchVtRlpLenHexLen + terminalBranchVtValueHexLen) - (2 + leafRlpLengthHexLen + 2 + leafPathRlpHexLen + leafPathPrefixHexLen + leafPathHexLen + 2 + leafRlpValueLenHexLen + leafValueLenHexLen)) + (2 + leafRlpLengthHexLen + 2 + leafPathRlpHexLen + leafPathPrefixHexLen + leafPathHexLen + 2 + leafRlpValueLenHexLen + leafValueLenHexLen);
|
||||
terminalHash.inLen <== isTerminalBranch * ((2 + terminalBranchRlpLengthHexLen + 2 * 17 + terminalBranchNodeRefHexLen[0] + terminalBranchNodeRefHexLen[1] + terminalBranchNodeRefHexLen[2] + terminalBranchNodeRefHexLen[3] + terminalBranchNodeRefHexLen[4] + terminalBranchNodeRefHexLen[5] + terminalBranchNodeRefHexLen[6] + terminalBranchNodeRefHexLen[7] + terminalBranchNodeRefHexLen[8] + terminalBranchNodeRefHexLen[9] + terminalBranchNodeRefHexLen[10] + terminalBranchNodeRefHexLen[11] + terminalBranchNodeRefHexLen[12] + terminalBranchNodeRefHexLen[13] + terminalBranchNodeRefHexLen[14] + terminalBranchNodeRefHexLen[15] + terminalBranchVtRlpLengthHexLen + terminalBranchVtHexLen) - (2 + leafRlpLengthHexLen + 2 + leafPathRlpLengthHexLen + leafPathPrefixHexLen + leafPathHexLen + 2 + leafValueRlpLengthHexLen + leafValueHexLen)) + (2 + leafRlpLengthHexLen + 2 + leafPathRlpLengthHexLen + leafPathPrefixHexLen + leafPathHexLen + 2 + leafValueRlpLengthHexLen + leafValueHexLen);
|
||||
|
||||
// hashes of nodes along path
|
||||
var maxNodeRlpHexLen = maxBranchRlpHexLen;
|
||||
@@ -1007,7 +925,7 @@ template MPTInclusion(maxDepth, maxKeyHexLen, maxValueHexLen) {
|
||||
for (var idx = 0; idx < maxNodeRlpHexLen; idx++) {
|
||||
nodeHashes[layer].in[idx] <== nodeRlpHexs[layer][idx];
|
||||
}
|
||||
nodeHashes[layer].inLen <== nodeTypes[layer] * (2 + nodeRlpLengthHexLen[layer] + 2 + nodePathRlpHexLen[layer] + nodePathPrefixHexLen[layer] + nodePathHexLen[layer] + 2 + nodeRefHexLen[layer][0] - (2 + nodeRlpLengthHexLen[layer] + 2 * 17 + nodeRefHexLen[layer][0] + nodeRefHexLen[layer][1] + nodeRefHexLen[layer][2] + nodeRefHexLen[layer][3] + nodeRefHexLen[layer][4] + nodeRefHexLen[layer][5] + nodeRefHexLen[layer][6] + nodeRefHexLen[layer][7] + nodeRefHexLen[layer][8] + nodeRefHexLen[layer][9] + nodeRefHexLen[layer][10] + nodeRefHexLen[layer][11] + nodeRefHexLen[layer][12] + nodeRefHexLen[layer][13] + nodeRefHexLen[layer][14] + nodeRefHexLen[layer][15] + nodeVtRlpLenHexLen[layer] + nodeVtValueHexLen[layer])) + (2 + nodeRlpLengthHexLen[layer] + 2 * 17 + nodeRefHexLen[layer][0] + nodeRefHexLen[layer][1] + nodeRefHexLen[layer][2] + nodeRefHexLen[layer][3] + nodeRefHexLen[layer][4] + nodeRefHexLen[layer][5] + nodeRefHexLen[layer][6] + nodeRefHexLen[layer][7] + nodeRefHexLen[layer][8] + nodeRefHexLen[layer][9] + nodeRefHexLen[layer][10] + nodeRefHexLen[layer][11] + nodeRefHexLen[layer][12] + nodeRefHexLen[layer][13] + nodeRefHexLen[layer][14] + nodeRefHexLen[layer][15] + nodeVtRlpLenHexLen[layer] + nodeVtValueHexLen[layer]);
|
||||
nodeHashes[layer].inLen <== nodeTypes[layer] * (2 + nodeRlpLengthHexLen[layer] + 2 + nodePathRlpLengthHexLen[layer] + nodePathPrefixHexLen[layer] + nodePathHexLen[layer] + 2 + nodeRefHexLen[layer][0] - (2 + nodeRlpLengthHexLen[layer] + 2 * 17 + nodeRefHexLen[layer][0] + nodeRefHexLen[layer][1] + nodeRefHexLen[layer][2] + nodeRefHexLen[layer][3] + nodeRefHexLen[layer][4] + nodeRefHexLen[layer][5] + nodeRefHexLen[layer][6] + nodeRefHexLen[layer][7] + nodeRefHexLen[layer][8] + nodeRefHexLen[layer][9] + nodeRefHexLen[layer][10] + nodeRefHexLen[layer][11] + nodeRefHexLen[layer][12] + nodeRefHexLen[layer][13] + nodeRefHexLen[layer][14] + nodeRefHexLen[layer][15] + nodeVtRlpLengthHexLen[layer] + nodeVtHexLen[layer])) + (2 + nodeRlpLengthHexLen[layer] + 2 * 17 + nodeRefHexLen[layer][0] + nodeRefHexLen[layer][1] + nodeRefHexLen[layer][2] + nodeRefHexLen[layer][3] + nodeRefHexLen[layer][4] + nodeRefHexLen[layer][5] + nodeRefHexLen[layer][6] + nodeRefHexLen[layer][7] + nodeRefHexLen[layer][8] + nodeRefHexLen[layer][9] + nodeRefHexLen[layer][10] + nodeRefHexLen[layer][11] + nodeRefHexLen[layer][12] + nodeRefHexLen[layer][13] + nodeRefHexLen[layer][14] + nodeRefHexLen[layer][15] + nodeVtRlpLengthHexLen[layer] + nodeVtHexLen[layer]);
|
||||
}
|
||||
|
||||
// check rootHash
|
||||
@@ -1019,9 +937,6 @@ template MPTInclusion(maxDepth, maxKeyHexLen, maxValueHexLen) {
|
||||
}
|
||||
rootHashCheck.inLen <== 64;
|
||||
|
||||
// constrain Leaf: rlp([prefix (20 or 3) | path, value])
|
||||
component leaf = LeafCheck(maxKeyHexLen, maxValueHexLen);
|
||||
|
||||
component leafStartSelector = Multiplexer(1, maxDepth);
|
||||
for (var idx = 0; idx < maxDepth; idx++) {
|
||||
leafStartSelector.inp[idx][0] <== start[idx];
|
||||
@@ -1034,7 +949,9 @@ template MPTInclusion(maxDepth, maxKeyHexLen, maxValueHexLen) {
|
||||
}
|
||||
leafSelector.start <== leafStartSelector.out[0];
|
||||
leafSelector.end <== keyHexLen;
|
||||
|
||||
|
||||
// constrain Leaf: rlp([prefix (20 or 3) | path, value])
|
||||
component leaf = LeafCheck(maxKeyHexLen, maxValueHexLen);
|
||||
leaf.keyNibbleHexLen <== leafSelector.outLen;
|
||||
for (var idx = 0; idx < maxKeyHexLen; idx++) {
|
||||
leaf.keyNibbleHexs[idx] <== leafSelector.out[idx];
|
||||
@@ -1043,11 +960,11 @@ template MPTInclusion(maxDepth, maxKeyHexLen, maxValueHexLen) {
|
||||
leaf.valueHexs[idx] <== valueHexs[idx];
|
||||
}
|
||||
leaf.leafRlpLengthHexLen <== leafRlpLengthHexLen;
|
||||
leaf.leafPathRlpHexLen <== leafPathRlpHexLen;
|
||||
leaf.leafPathRlpLengthHexLen <== leafPathRlpLengthHexLen;
|
||||
leaf.leafPathPrefixHexLen <== leafPathPrefixHexLen;
|
||||
leaf.leafPathHexLen <== leafPathHexLen;
|
||||
leaf.leafRlpValueLenHexLen <== leafRlpValueLenHexLen;
|
||||
leaf.leafValueLenHexLen <== leafValueLenHexLen;
|
||||
leaf.leafValueRlpLengthHexLen <== leafValueRlpLengthHexLen;
|
||||
leaf.leafValueHexLen <== leafValueHexLen;
|
||||
for (var idx = 0; idx < maxLeafRlpHexLen; idx++) {
|
||||
leaf.leafRlpHexs[idx] <== leafRlpHexs[idx];
|
||||
}
|
||||
@@ -1060,10 +977,10 @@ template MPTInclusion(maxDepth, maxKeyHexLen, maxValueHexLen) {
|
||||
}
|
||||
terminalBranch.nodeRlpLengthHexLen <== terminalBranchRlpLengthHexLen;
|
||||
for (var idx = 0; idx < 16; idx++) {
|
||||
terminalBranch.nodeValueLenHexLen[idx] <== terminalBranchNodeRefHexLen[idx];
|
||||
terminalBranch.nodeValueHexLen[idx] <== terminalBranchNodeRefHexLen[idx];
|
||||
}
|
||||
terminalBranch.nodeVtRlpLenHexLen <== terminalBranchVtRlpLenHexLen;
|
||||
terminalBranch.nodeVtValueHexLen <== terminalBranchVtValueHexLen;
|
||||
terminalBranch.nodeVtRlpLengthHexLen <== terminalBranchVtRlpLengthHexLen;
|
||||
terminalBranch.nodeVtHexLen <== terminalBranchVtHexLen;
|
||||
for (var idx = 0; idx < maxBranchRlpHexLen; idx++) {
|
||||
terminalBranch.nodeRlpHexs[idx] <== terminalBranchRlpHexs[idx];
|
||||
}
|
||||
@@ -1108,10 +1025,10 @@ template MPTInclusion(maxDepth, maxKeyHexLen, maxValueHexLen) {
|
||||
}
|
||||
|
||||
exts[layer].nodeRlpLengthHexLen <== nodeRlpLengthHexLen[layer];
|
||||
exts[layer].nodePathRlpHexLen <== nodePathRlpHexLen[layer];
|
||||
exts[layer].nodePathRlpLengthHexLen <== nodePathRlpLengthHexLen[layer];
|
||||
exts[layer].nodePathPrefixHexLen <== nodePathPrefixHexLen[layer];
|
||||
exts[layer].nodePathHexLen <== nodePathHexLen[layer];
|
||||
exts[layer].nodeRefExtHexLen <== nodeRefHexLen[layer][0];
|
||||
exts[layer].extNodeRefHexLen <== nodeRefHexLen[layer][0];
|
||||
for (var idx = 0; idx < maxExtensionRlpHexLen; idx++) {
|
||||
exts[layer].nodeRlpHexs[idx] <== nodeRlpHexs[layer][idx];
|
||||
}
|
||||
@@ -1147,13 +1064,13 @@ template MPTInclusion(maxDepth, maxKeyHexLen, maxValueHexLen) {
|
||||
branches[layer].nodeRlpLengthHexLen <== nodeRlpLengthHexLen[layer];
|
||||
// v0, ..., v15 _or_ node_ref
|
||||
for (var idx = 0; idx < 16; idx++) {
|
||||
branches[layer].nodeValueLenHexLen[idx] <== nodeRefHexLen[layer][idx];
|
||||
branches[layer].nodeValueHexLen[idx] <== nodeRefHexLen[layer][idx];
|
||||
}
|
||||
for (var idx = 0; idx < maxBranchRlpHexLen; idx++) {
|
||||
branches[layer].nodeRlpHexs[idx] <== nodeRlpHexs[layer][idx];
|
||||
}
|
||||
branches[layer].nodeVtRlpLenHexLen <== nodeVtRlpLenHexLen[layer];
|
||||
branches[layer].nodeVtValueHexLen <== nodeVtValueHexLen[layer];
|
||||
branches[layer].nodeVtRlpLengthHexLen <== nodeVtRlpLengthHexLen[layer];
|
||||
branches[layer].nodeVtHexLen <== nodeVtHexLen[layer];
|
||||
}
|
||||
|
||||
component checksPassed = Multiplexer(1, maxDepth);
|
||||
@@ -1194,28 +1111,31 @@ template MPTInclusionNoBranchTermination(maxDepth, maxKeyHexLen, maxValueHexLen)
|
||||
|
||||
// leaf = rlp_prefix [2]
|
||||
// rlp_length [0, 2 * ceil(log_8(1 + ceil(log_8(maxKeyHexLen + 2)) + 4 + maxKeyHexLen + 2 + 2 * ceil(log_8(maxValueHexLen)) + maxValueHexLen))]
|
||||
// rlp_path_rlp_prefix [2]
|
||||
// rlp_path_rlp_length [0, 2 * ceil(log_8(maxKeyHexLen + 2))]
|
||||
// path_rlp_prefix [2]
|
||||
// path_rlp_length [0, 2 * ceil(log_8(maxKeyHexLen + 2))]
|
||||
// path_prefix [1, 2]
|
||||
// path [0, maxKeyHexLen]
|
||||
// rlp_value_prefix [2]
|
||||
// rlp_value_len [0, 2 * ceil(log_8(maxValueHexLen))]
|
||||
// value_rlp_prefix [2]
|
||||
// value_rlp_length [0, 2 * ceil(log_8(maxValueHexLen))]
|
||||
// value [0, maxValueHexLen]
|
||||
signal input leafRlpLengthHexLen;
|
||||
signal input leafPathRlpHexLen;
|
||||
|
||||
signal input leafPathRlpLengthHexLen;
|
||||
signal input leafPathPrefixHexLen;
|
||||
signal input leafPathHexLen;
|
||||
signal input leafRlpValueLenHexLen;
|
||||
signal input leafValueLenHexLen;
|
||||
|
||||
signal input leafValueRlpLengthHexLen;
|
||||
signal input leafValueHexLen;
|
||||
|
||||
signal input leafRlpHexs[maxLeafRlpHexLen];
|
||||
|
||||
// extension = rlp_prefix [2]
|
||||
// rlp_length [0, 2 * ceil((...))]
|
||||
// rlp_path_rlp_prefix [2]
|
||||
// rlp_path_rlp_length [0, 2 * ceil(log_8(maxKeyHexLen + 2))]
|
||||
// path_rlp_prefix [2]
|
||||
// path_rlp_length [0, 2 * ceil(log_8(maxKeyHexLen + 2))]
|
||||
// path_prefix [1, 2]
|
||||
// path [0, maxKeyHexLen]
|
||||
// rlp_node_ref_prefix [2]
|
||||
// node_ref_rlp_prefix [2]
|
||||
// node_ref [0, 64]
|
||||
// branch = rlp_prefix [2]
|
||||
// rlp_length [0, 8]
|
||||
@@ -1225,12 +1145,12 @@ template MPTInclusionNoBranchTermination(maxDepth, maxKeyHexLen, maxValueHexLen)
|
||||
// v15_rlp_prefix [2]
|
||||
// v15 [0, 64]
|
||||
// vt_rlp_prefix [2]
|
||||
// vt_rlp_len [0]
|
||||
// vt [0]
|
||||
signal input nodeRlpLengthHexLen[maxDepth - 1];
|
||||
signal input nodePathRlpHexLen[maxDepth - 1];
|
||||
signal input nodeRlpLengthHexLen[maxDepth - 1];
|
||||
|
||||
signal input nodePathRlpLengthHexLen[maxDepth - 1];
|
||||
signal input nodePathPrefixHexLen[maxDepth - 1];
|
||||
signal input nodePathHexLen[maxDepth - 1];
|
||||
signal input nodePathHexLen[maxDepth - 1];
|
||||
|
||||
signal input nodeRefHexLen[maxDepth - 1][16];
|
||||
|
||||
signal input nodeRlpHexs[maxDepth - 1][maxBranchRlpHexLen];
|
||||
@@ -1270,7 +1190,7 @@ template MPTInclusionNoBranchTermination(maxDepth, maxKeyHexLen, maxValueHexLen)
|
||||
for (var idx = 0; idx < maxLeafRlpHexLen; idx++) {
|
||||
terminalHash.in[idx] <== leafRlpHexs[idx];
|
||||
}
|
||||
terminalHash.inLen <== 2 + leafRlpLengthHexLen + 2 + leafPathRlpHexLen + leafPathPrefixHexLen + leafPathHexLen + 2 + leafRlpValueLenHexLen + leafValueLenHexLen;
|
||||
terminalHash.inLen <== 2 + leafRlpLengthHexLen + 2 + leafPathRlpLengthHexLen + leafPathPrefixHexLen + leafPathHexLen + 2 + leafValueRlpLengthHexLen + leafValueHexLen;
|
||||
|
||||
// hashes of nodes along path
|
||||
var maxNodeRlpHexLen = maxBranchRlpHexLen;
|
||||
@@ -1281,7 +1201,7 @@ template MPTInclusionNoBranchTermination(maxDepth, maxKeyHexLen, maxValueHexLen)
|
||||
for (var idx = 0; idx < maxNodeRlpHexLen; idx++) {
|
||||
nodeHashes[layer].in[idx] <== nodeRlpHexs[layer][idx];
|
||||
}
|
||||
nodeHashes[layer].inLen <== nodeTypes[layer] * (2 + nodeRlpLengthHexLen[layer] + 2 + nodePathRlpHexLen[layer] + nodePathPrefixHexLen[layer] + nodePathHexLen[layer] + 2 + nodeRefHexLen[layer][0] - (2 + nodeRlpLengthHexLen[layer] + 2 * 17 + nodeRefHexLen[layer][0] + nodeRefHexLen[layer][1] + nodeRefHexLen[layer][2] + nodeRefHexLen[layer][3] + nodeRefHexLen[layer][4] + nodeRefHexLen[layer][5] + nodeRefHexLen[layer][6] + nodeRefHexLen[layer][7] + nodeRefHexLen[layer][8] + nodeRefHexLen[layer][9] + nodeRefHexLen[layer][10] + nodeRefHexLen[layer][11] + nodeRefHexLen[layer][12] + nodeRefHexLen[layer][13] + nodeRefHexLen[layer][14] + nodeRefHexLen[layer][15])) + (2 + nodeRlpLengthHexLen[layer] + 2 * 17 + nodeRefHexLen[layer][0] + nodeRefHexLen[layer][1] + nodeRefHexLen[layer][2] + nodeRefHexLen[layer][3] + nodeRefHexLen[layer][4] + nodeRefHexLen[layer][5] + nodeRefHexLen[layer][6] + nodeRefHexLen[layer][7] + nodeRefHexLen[layer][8] + nodeRefHexLen[layer][9] + nodeRefHexLen[layer][10] + nodeRefHexLen[layer][11] + nodeRefHexLen[layer][12] + nodeRefHexLen[layer][13] + nodeRefHexLen[layer][14] + nodeRefHexLen[layer][15]);
|
||||
nodeHashes[layer].inLen <== nodeTypes[layer] * (2 + nodeRlpLengthHexLen[layer] + 2 + nodePathRlpLengthHexLen[layer] + nodePathPrefixHexLen[layer] + nodePathHexLen[layer] + 2 + nodeRefHexLen[layer][0] - (2 + nodeRlpLengthHexLen[layer] + 2 * 17 + nodeRefHexLen[layer][0] + nodeRefHexLen[layer][1] + nodeRefHexLen[layer][2] + nodeRefHexLen[layer][3] + nodeRefHexLen[layer][4] + nodeRefHexLen[layer][5] + nodeRefHexLen[layer][6] + nodeRefHexLen[layer][7] + nodeRefHexLen[layer][8] + nodeRefHexLen[layer][9] + nodeRefHexLen[layer][10] + nodeRefHexLen[layer][11] + nodeRefHexLen[layer][12] + nodeRefHexLen[layer][13] + nodeRefHexLen[layer][14] + nodeRefHexLen[layer][15])) + (2 + nodeRlpLengthHexLen[layer] + 2 * 17 + nodeRefHexLen[layer][0] + nodeRefHexLen[layer][1] + nodeRefHexLen[layer][2] + nodeRefHexLen[layer][3] + nodeRefHexLen[layer][4] + nodeRefHexLen[layer][5] + nodeRefHexLen[layer][6] + nodeRefHexLen[layer][7] + nodeRefHexLen[layer][8] + nodeRefHexLen[layer][9] + nodeRefHexLen[layer][10] + nodeRefHexLen[layer][11] + nodeRefHexLen[layer][12] + nodeRefHexLen[layer][13] + nodeRefHexLen[layer][14] + nodeRefHexLen[layer][15]);
|
||||
}
|
||||
|
||||
// check rootHash
|
||||
@@ -1308,7 +1228,6 @@ template MPTInclusionNoBranchTermination(maxDepth, maxKeyHexLen, maxValueHexLen)
|
||||
|
||||
// constrain Leaf: rlp([prefix (20 or 3) | path, value])
|
||||
component leaf = LeafCheck(maxKeyHexLen, maxValueHexLen);
|
||||
|
||||
leaf.keyNibbleHexLen <== leafSelector.outLen;
|
||||
for (var idx = 0; idx < maxKeyHexLen; idx++) {
|
||||
leaf.keyNibbleHexs[idx] <== leafSelector.out[idx];
|
||||
@@ -1317,11 +1236,11 @@ template MPTInclusionNoBranchTermination(maxDepth, maxKeyHexLen, maxValueHexLen)
|
||||
leaf.valueHexs[idx] <== valueHexs[idx];
|
||||
}
|
||||
leaf.leafRlpLengthHexLen <== leafRlpLengthHexLen;
|
||||
leaf.leafPathRlpHexLen <== leafPathRlpHexLen;
|
||||
leaf.leafPathRlpLengthHexLen <== leafPathRlpLengthHexLen;
|
||||
leaf.leafPathPrefixHexLen <== leafPathPrefixHexLen;
|
||||
leaf.leafPathHexLen <== leafPathHexLen;
|
||||
leaf.leafRlpValueLenHexLen <== leafRlpValueLenHexLen;
|
||||
leaf.leafValueLenHexLen <== leafValueLenHexLen;
|
||||
leaf.leafValueRlpLengthHexLen <== leafValueRlpLengthHexLen;
|
||||
leaf.leafValueHexLen <== leafValueHexLen;
|
||||
for (var idx = 0; idx < maxLeafRlpHexLen; idx++) {
|
||||
leaf.leafRlpHexs[idx] <== leafRlpHexs[idx];
|
||||
}
|
||||
@@ -1366,10 +1285,10 @@ template MPTInclusionNoBranchTermination(maxDepth, maxKeyHexLen, maxValueHexLen)
|
||||
}
|
||||
|
||||
exts[layer].nodeRlpLengthHexLen <== nodeRlpLengthHexLen[layer];
|
||||
exts[layer].nodePathRlpHexLen <== nodePathRlpHexLen[layer];
|
||||
exts[layer].nodePathRlpLengthHexLen <== nodePathRlpLengthHexLen[layer];
|
||||
exts[layer].nodePathPrefixHexLen <== nodePathPrefixHexLen[layer];
|
||||
exts[layer].nodePathHexLen <== nodePathHexLen[layer];
|
||||
exts[layer].nodeRefExtHexLen <== nodeRefHexLen[layer][0];
|
||||
exts[layer].extNodeRefHexLen <== nodeRefHexLen[layer][0];
|
||||
for (var idx = 0; idx < maxExtensionRlpHexLen; idx++) {
|
||||
exts[layer].nodeRlpHexs[idx] <== nodeRlpHexs[layer][idx];
|
||||
}
|
||||
@@ -1379,7 +1298,7 @@ template MPTInclusionNoBranchTermination(maxDepth, maxKeyHexLen, maxValueHexLen)
|
||||
component branches[maxDepth - 1];
|
||||
component nibbleSelector[maxDepth - 1];
|
||||
for (var layer = 0; layer < maxDepth - 1; layer++) {
|
||||
branches[layer] = EmptyTerminalBranchCheck(64, maxValueHexLen);
|
||||
branches[layer] = EmptyVtBranchCheck(64);
|
||||
|
||||
nibbleSelector[layer] = Multiplexer(1, maxKeyHexLen);
|
||||
for (var idx = 0; idx < maxKeyHexLen; idx++) {
|
||||
@@ -1405,7 +1324,7 @@ template MPTInclusionNoBranchTermination(maxDepth, maxKeyHexLen, maxValueHexLen)
|
||||
branches[layer].nodeRlpLengthHexLen <== nodeRlpLengthHexLen[layer];
|
||||
// v0, ..., v15 _or_ node_ref
|
||||
for (var idx = 0; idx < 16; idx++) {
|
||||
branches[layer].nodeValueLenHexLen[idx] <== nodeRefHexLen[layer][idx];
|
||||
branches[layer].nodeValueHexLen[idx] <== nodeRefHexLen[layer][idx];
|
||||
}
|
||||
for (var idx = 0; idx < maxBranchRlpHexLen; idx++) {
|
||||
branches[layer].nodeRlpHexs[idx] <== nodeRlpHexs[layer][idx];
|
||||
|
||||
@@ -6,7 +6,7 @@ TAG_TO_NAME = {
|
||||
111111100001: 'LeafCheck',
|
||||
111111100002: 'ExtensionCheck',
|
||||
111111100003: 'BranchFixedKeyHexLen',
|
||||
111111100004: 'EmptyTerminalBranchCheck',
|
||||
111111100004: 'EmptyVtBranchCheck',
|
||||
111111100005: 'NonTerminalBranchCheck',
|
||||
111111100006: 'TerminalBranchCheck',
|
||||
111111100007: 'MPTInclusionFixedKeyHexLen',
|
||||
@@ -272,13 +272,12 @@ def parse_one(lines, idx):
|
||||
idx = idx + 3
|
||||
elif tag == 111111100004:
|
||||
log["maxNodeRefHexLen"] = int(lines[idx][:-2])
|
||||
log["maxValueHexLen"] = int(lines[idx + 1][:-2])
|
||||
|
||||
log["keyNibble"] = int(lines[idx + 2][:-2])
|
||||
log["nodeRefHexLen"] = int(lines[idx + 3][:-2])
|
||||
log["nodeRlpLengthHexLen"] = int(lines[idx + 4][:-2])
|
||||
log["maxBranchRlpHexLen"] = int(lines[idx + 5][:-2])
|
||||
idx = idx + 6
|
||||
log["keyNibble"] = int(lines[idx + 1][:-2])
|
||||
log["nodeRefHexLen"] = int(lines[idx + 2][:-2])
|
||||
log["nodeRlpLengthHexLen"] = int(lines[idx + 3][:-2])
|
||||
log["maxBranchRlpHexLen"] = int(lines[idx + 4][:-2])
|
||||
idx = idx + 5
|
||||
|
||||
log["nodeRefHexs"] = []
|
||||
log["nodeValueLenHexLenHexs"] = []
|
||||
|
||||
@@ -7,14 +7,14 @@ component main {public [
|
||||
valueHexs,
|
||||
rootHashHexs,
|
||||
leafRlpLengthHexLen,
|
||||
leafPathRlpHexLen,
|
||||
leafPathRlpLengthHexLen,
|
||||
leafPathPrefixHexLen,
|
||||
leafPathHexLen,
|
||||
leafRlpValueLenHexLen,
|
||||
leafValueLenHexLen,
|
||||
leafValueRlpLengthHexLen,
|
||||
leafValueHexLen,
|
||||
leafRlpHexs,
|
||||
nodeRlpLengthHexLen,
|
||||
nodePathRlpHexLen,
|
||||
nodePathRlpLengthHexLen,
|
||||
nodePathPrefixHexLen,
|
||||
nodePathHexLen,
|
||||
nodeRefHexLen,
|
||||
|
||||
File diff suppressed because one or more lines are too long
3
scripts/input_gen/generate_addr_inputs.sh
Executable file
3
scripts/input_gen/generate_addr_inputs.sh
Executable file
@@ -0,0 +1,3 @@
|
||||
#!/bin/bash
|
||||
|
||||
python generate_storage_proof_inputs.py --addr --addr_file_str inputs/input_addr.json --debug
|
||||
@@ -38,16 +38,16 @@ def gen_proof_input(proof, root, key, value, maxValueHexLen, maxDepth=None, debu
|
||||
|
||||
leafRlpLengthHexLen = 0
|
||||
|
||||
leafPathRlpHexLen = 0
|
||||
leafPathRlpLengthHexLen = 0
|
||||
leafPathPrefixHexLen = 2
|
||||
leafPathHexLen = 60
|
||||
|
||||
leafRlpValueLenHexLen = 2
|
||||
leafValueLenHexLen = 4
|
||||
leafValueRlpLengthHexLen = 2
|
||||
leafValueHexLen = 4
|
||||
leafRlpHexs = []
|
||||
|
||||
nodeRlpLengthHexLen = []
|
||||
nodePathRlpHexLen = []
|
||||
nodePathRlpLengthHexLen = []
|
||||
nodePathPrefixHexLen = []
|
||||
nodePathHexLen = []
|
||||
nodeRefHexLen = []
|
||||
@@ -77,12 +77,12 @@ def gen_proof_input(proof, root, key, value, maxValueHexLen, maxDepth=None, debu
|
||||
path_rlp_prefix = node[curr_idx: curr_idx + 2]
|
||||
curr_idx = curr_idx + 2
|
||||
if int(path_rlp_prefix, 16) <= int('b7', 16):
|
||||
leafPathRlpHexLen = 0
|
||||
leafPathRlpLengthHexLen = 0
|
||||
leafPathHexLen = 2 * (int(path_rlp_prefix, 16) - int('80', 16))
|
||||
else:
|
||||
leafPathRlpHexLen = 2 * (int(path_rlp_prefix, 16) - int('b7', 16))
|
||||
len_nibbles = node[curr_idx: curr_idx + leafPathRlpHexLen]
|
||||
curr_idx = curr_idx + leafPathRlpHexLen
|
||||
leafPathRlpLengthHexLen = 2 * (int(path_rlp_prefix, 16) - int('b7', 16))
|
||||
len_nibbles = node[curr_idx: curr_idx + leafPathRlpLengthHexLen]
|
||||
curr_idx = curr_idx + leafPathRlpLengthHexLen
|
||||
leafPathHexLen = 2 * int(len_nibbles, 16)
|
||||
|
||||
path_prefix_nibble = node[curr_idx]
|
||||
@@ -100,21 +100,21 @@ def gen_proof_input(proof, root, key, value, maxValueHexLen, maxDepth=None, debu
|
||||
curr_idx = curr_idx + 2
|
||||
|
||||
if int(value_rlp_prefix, 16) <= int('b7', 16):
|
||||
leafRlpValueLenHexLen = 0
|
||||
leafValueLenHexLen = 2 * (int(value_rlp_prefix, 16) - int('80', 16))
|
||||
leafValueRlpLengthHexLen = 0
|
||||
leafValueHexLen = 2 * (int(value_rlp_prefix, 16) - int('80', 16))
|
||||
elif int(value_rlp_prefix, 16) <= int('bf', 16):
|
||||
leafRlpValueLenHexLen = 2 * (int(value_rlp_prefix, 16) - int('b7', 16))
|
||||
len_nibbles = node[curr_idx: curr_idx + leafRlpValueLenHexLen]
|
||||
curr_idx = curr_idx + leafRlpValueLenHexLen
|
||||
leafValueLenHexLen = 2 * int(len_nibbles, 16)
|
||||
leafValueRlpLengthHexLen = 2 * (int(value_rlp_prefix, 16) - int('b7', 16))
|
||||
len_nibbles = node[curr_idx: curr_idx + leafValueRlpLengthHexLen]
|
||||
curr_idx = curr_idx + leafValueRlpLengthHexLen
|
||||
leafValueHexLen = 2 * int(len_nibbles, 16)
|
||||
elif int(value_rlp_prefix, 16) <= int('f7', 16):
|
||||
leafRlpValueLenHexLen = 0
|
||||
leafValueLenHexLen = 2 * (int(value_rlp_prefix, 16) - int('c0', 16))
|
||||
leafValueRlpLengthHexLen = 0
|
||||
leafValueHexLen = 2 * (int(value_rlp_prefix, 16) - int('c0', 16))
|
||||
elif int(value_rlp_prefix, 16) <= int('ff', 16):
|
||||
leafRlpValueLenHexLen = 2 * (int(value_rlp_prefix, 16) - int('f7', 16))
|
||||
len_nibbles = node[curr_idx: curr_idx + leafRlpValueLenHexLen]
|
||||
curr_idx = curr_idx + leafRlpValueLenHexLen
|
||||
leafValueLenHexLen = 2 * int(len_nibbles, 16)
|
||||
leafValueRlpLengthHexLen = 2 * (int(value_rlp_prefix, 16) - int('f7', 16))
|
||||
len_nibbles = node[curr_idx: curr_idx + leafValueRlpLengthHexLen]
|
||||
curr_idx = curr_idx + leafValueRlpLengthHexLen
|
||||
leafValueHexLen = 2 * int(len_nibbles, 16)
|
||||
|
||||
leafRlpHexs = serialize_hex(node[2:])
|
||||
leafRlpHexs = leafRlpHexs + [0 for x in range(LEAF_RLP_HEXS_LEN - len(leafRlpHexs))]
|
||||
@@ -131,7 +131,7 @@ def gen_proof_input(proof, root, key, value, maxValueHexLen, maxDepth=None, debu
|
||||
nodeRlpLengthHexLen.append(2 * (int(rlp_prefix, 16) - int('f7', 16)))
|
||||
curr_idx = curr_idx + nodeRlpLengthHexLen[-1]
|
||||
|
||||
nodePathRlpHexLen.append(0)
|
||||
nodePathRlpLengthHexLen.append(0)
|
||||
nodePathPrefixHexLen.append(0)
|
||||
nodePathHexLen.append(0)
|
||||
|
||||
@@ -163,24 +163,24 @@ def gen_proof_input(proof, root, key, value, maxValueHexLen, maxDepth=None, debu
|
||||
curr_idx = curr_idx + 2
|
||||
is_no_prefix = False
|
||||
if int(rlp_prefix, 16) <= int('7f', 16):
|
||||
nodePathRlpHexLen.append(0)
|
||||
nodePathRlpLengthHexLen.append(0)
|
||||
nodePathHexLen.append(0)
|
||||
is_no_prefix = True
|
||||
elif int(rlp_prefix, 16) <= int('b7', 16):
|
||||
nodePathRlpHexLen.append(0)
|
||||
nodePathRlpLengthHexLen.append(0)
|
||||
nodePathHexLen.append(2 * (int(rlp_prefix, 16) - int('80', 16)))
|
||||
elif int(rlp_prefix, 16) <= int('bf', 16):
|
||||
nodePathRlpHexLen.append(2 * (int(rlp_prefix, 16) - int('b7', 16)))
|
||||
str_len = node[curr_idx: curr_idx + nodePathRlpHexLen[-1]]
|
||||
curr_idx = curr_idx + nodePathRlpHexLen[-1]
|
||||
nodePathRlpLengthHexLen.append(2 * (int(rlp_prefix, 16) - int('b7', 16)))
|
||||
str_len = node[curr_idx: curr_idx + nodePathRlpLengthHexLen[-1]]
|
||||
curr_idx = curr_idx + nodePathRlpLengthHexLen[-1]
|
||||
nodePathHexLen.append(2 * int(str_len, 16))
|
||||
elif int(rlp_prefix, 16) <= int('f7', 16):
|
||||
nodePathRlpLenHexLen.append(0)
|
||||
nodePathRlpLengthHexLen.append(0)
|
||||
nodePathHexLen.append(2 * (int(rlp_prefix, 16) - int('c0', 16)))
|
||||
elif int(rlp_prefix, 16) <= int('ff', 16):
|
||||
nodePathRlpHexLen.append(2 * (int(rlp_prefix, 16) - int('f7', 16)))
|
||||
str_len = node[curr_idx: curr_idx + nodePathRlpHexLen[-1]]
|
||||
curr_idx = curr_idx + nodePathRlpHexLen[-1]
|
||||
nodePathRlpLengthHexLen.append(2 * (int(rlp_prefix, 16) - int('f7', 16)))
|
||||
str_len = node[curr_idx: curr_idx + nodePathRlpLengthHexLen[-1]]
|
||||
curr_idx = curr_idx + nodePathRlpLengthHexLen[-1]
|
||||
nodePathHexLen.append(2 * int(str_len, 16))
|
||||
|
||||
if is_no_prefix:
|
||||
@@ -216,7 +216,7 @@ def gen_proof_input(proof, root, key, value, maxValueHexLen, maxDepth=None, debu
|
||||
if maxDepth is not None:
|
||||
for idx in range(maxDepth - len(proof)):
|
||||
nodeRlpLengthHexLen.append(0)
|
||||
nodePathRlpHexLen.append(0)
|
||||
nodePathRlpLengthHexLen.append(0)
|
||||
nodePathPrefixHexLen.append(0)
|
||||
nodePathHexLen.append(0)
|
||||
nodeRefHexLen.append([0 for idx in range(16)])
|
||||
@@ -231,16 +231,16 @@ def gen_proof_input(proof, root, key, value, maxValueHexLen, maxDepth=None, debu
|
||||
|
||||
"leafRlpLengthHexLen": leafRlpLengthHexLen,
|
||||
|
||||
"leafPathRlpHexLen": leafPathRlpHexLen,
|
||||
"leafPathRlpLengthHexLen": leafPathRlpLengthHexLen,
|
||||
"leafPathPrefixHexLen": leafPathPrefixHexLen,
|
||||
"leafPathHexLen": leafPathHexLen,
|
||||
|
||||
"leafRlpValueLenHexLen": leafRlpValueLenHexLen,
|
||||
"leafValueLenHexLen": leafValueLenHexLen,
|
||||
"leafValueRlpLengthHexLen": leafValueRlpLengthHexLen,
|
||||
"leafValueHexLen": leafValueHexLen,
|
||||
"leafRlpHexs": leafRlpHexs,
|
||||
|
||||
"nodeRlpLengthHexLen": nodeRlpLengthHexLen,
|
||||
"nodePathRlpHexLen": nodePathRlpHexLen,
|
||||
"nodePathRlpLengthHexLen": nodePathRlpLengthHexLen,
|
||||
"nodePathPrefixHexLen": nodePathPrefixHexLen,
|
||||
"nodePathHexLen": nodePathHexLen,
|
||||
"nodeRefHexLen": nodeRefHexLen,
|
||||
@@ -270,7 +270,7 @@ def get_storage_pf(punk_pfs, slot=None, max_depth=8, debug=False):
|
||||
print('key: {}'.format(key))
|
||||
print('value: {}'.format(value))
|
||||
|
||||
pf = gen_proof_input(proof, root, key, rlp.encode(bytearray.fromhex(value)).hex(), 114, maxDepth=max_depth, debug=debug)
|
||||
pf = gen_proof_input(proof, root, key, rlp.encode(bytearray.fromhex(value)).hex(), 66, maxDepth=max_depth, debug=debug)
|
||||
return pf
|
||||
|
||||
def get_addr_pf(punk_pfs, debug=False):
|
||||
|
||||
@@ -2,5 +2,5 @@
|
||||
|
||||
for TX_IDX in {0..196}
|
||||
do
|
||||
python generate_tx_proof_inputs.py --tx_idx "$TX_IDX" --max_depth 5 --max_key_len 6 --max_val_len 6078 --file_str inputs/input_tx_pf"$TX_IDX".json
|
||||
python generate_tx_proof_inputs.py --tx_idx "$TX_IDX" --max_depth 5 --max_key_len 6 --max_val_len 6080 --file_str inputs/input_tx_pf"$TX_IDX".json
|
||||
done
|
||||
|
||||
@@ -76,27 +76,27 @@ def gen_proof_input(proof, root, key, value, maxDepth, maxKeyHexLen, maxValueHex
|
||||
rootHashHexs = []
|
||||
|
||||
leafRlpLengthHexLen = 0
|
||||
leafPathRlpHexLen = 0
|
||||
leafPathRlpLengthHexLen = 0
|
||||
leafPathPrefixHexLen = 0
|
||||
leafPathHexLen = 0
|
||||
leafRlpValueLenHexLen = 0
|
||||
leafValueLenHexLen = 0
|
||||
leafValueRlpLengthHexLen = 0
|
||||
leafValueHexLen = 0
|
||||
leafRlpHexs = []
|
||||
|
||||
terminalBranchRlpLengthHexLen = 0
|
||||
terminalBranchNodeRefHexLen = []
|
||||
terminalBranchVtRlpLenHexLen = 0
|
||||
terminalBranchVtValueHexLen = 0
|
||||
terminalBranchVtRlpLengthHexLen = 0
|
||||
terminalBranchVtHexLen = 0
|
||||
|
||||
terminalBranchRlpHexs = []
|
||||
|
||||
nodeRlpLengthHexLen = []
|
||||
nodePathRlpHexLen = []
|
||||
nodePathRlpLengthHexLen = []
|
||||
nodePathPrefixHexLen = []
|
||||
nodePathHexLen = []
|
||||
nodeRefHexLen = []
|
||||
nodeVtRlpLenHexLen = []
|
||||
nodeVtValueHexLen = []
|
||||
nodeVtRlpLengthHexLen = []
|
||||
nodeVtHexLen = []
|
||||
|
||||
nodeRlpHexs = []
|
||||
|
||||
@@ -139,21 +139,21 @@ def gen_proof_input(proof, root, key, value, maxDepth, maxKeyHexLen, maxValueHex
|
||||
rlp_prefix = last[curr_idx: curr_idx + 2]
|
||||
curr_idx = curr_idx + 2
|
||||
if int(rlp_prefix, 16) <= int('b7', 16):
|
||||
terminalBranchVtRlpLenHexLen = 0
|
||||
terminalBranchVtValueHexLen = 2 * (int(rlp_prefix, 16) - int('80', 16))
|
||||
terminalBranchVtRlpLengthHexLen = 0
|
||||
terminalBranchVtHexLen = 2 * (int(rlp_prefix, 16) - int('80', 16))
|
||||
elif int(rlp_prefix, 16) <= int('bf', 16):
|
||||
terminalBranchVtRlpLenHexLen = 2 * (int(rlp_prefix, 16) - int('b7', 16))
|
||||
str_len = last[curr_idx: curr_idx + terminalBranchVtRlpLenHexLen]
|
||||
curr_idx = curr_idx + terminalBranchVtRlpLenHexLen
|
||||
terminalBranchVtValueHexLen = 2 * int(str_len, 16)
|
||||
terminalBranchVtRlpLengthHexLen = 2 * (int(rlp_prefix, 16) - int('b7', 16))
|
||||
str_len = last[curr_idx: curr_idx + terminalBranchVtRlpLengthHexLen]
|
||||
curr_idx = curr_idx + terminalBranchVtRlpLengthHexLen
|
||||
terminalBranchVtHexLen = 2 * int(str_len, 16)
|
||||
elif int(rlp_prefix, 16) <= int('f7', 16):
|
||||
terminalBranchVtRlpLenHexLen = 0
|
||||
terminalBranchVtValueHexLen = 2 * (int(rlp_prefix, 16) - int('c0', 16))
|
||||
terminalBranchVtRlpLengthHexLen = 0
|
||||
terminalBranchVtHexLen = 2 * (int(rlp_prefix, 16) - int('c0', 16))
|
||||
elif int(rlp_prefix, 16) <= int('ff', 16):
|
||||
terminalBranchVtRlpLenHexLen = 2 * (int(rlp_prefix, 16) - int('f7', 16))
|
||||
str_len = last[curr_idx: curr_idx + terminalBranchVtRlpLenHexLen]
|
||||
curr_idx = curr_idx + terminalBranchVtRlpLenHexLen
|
||||
terminalBranchVtValueHexLen = 2 * int(str_len, 16)
|
||||
terminalBranchVtRlpLengthHexLen = 2 * (int(rlp_prefix, 16) - int('f7', 16))
|
||||
str_len = last[curr_idx: curr_idx + terminalBranchVtRlpLengthHexLen]
|
||||
curr_idx = curr_idx + terminalBranchVtRlpLengthHexLen
|
||||
terminalBranchVtHexLen = 2 * int(str_len, 16)
|
||||
|
||||
node_rlp = serialize_hex(last)
|
||||
if debug:
|
||||
@@ -180,14 +180,14 @@ def gen_proof_input(proof, root, key, value, maxDepth, maxKeyHexLen, maxValueHex
|
||||
curr_idx = curr_idx + 2
|
||||
is_no_prefix = False
|
||||
if int(path_rlp_prefix, 16) <= int('7f', 16):
|
||||
leafPathRlpHexLen = 0
|
||||
leafPathRlpLengthHexLen = 0
|
||||
leafPathHexLen = 0
|
||||
is_no_prefix = True
|
||||
elif int(path_rlp_prefix, 16) <= int('b7', 16):
|
||||
leafPathRlpHexLen = 0
|
||||
leafPathRlpLengthHexLen = 0
|
||||
leafPathHexLen = 2 * (int(path_rlp_prefix, 16) - int('80', 16))
|
||||
else:
|
||||
leafPathRlpHexLen = 2 * (int(path_rlp_prefix, 16) - int('b7', 16))
|
||||
leafPathRlpLengthHexLen = 2 * (int(path_rlp_prefix, 16) - int('b7', 16))
|
||||
len_nibbles = last[curr_idx: curr_idx + leafPathRlpHexLen]
|
||||
curr_idx = curr_idx + leafPathRlpHexLen
|
||||
leafPathHexLen = 2 * int(len_nibbles, 16)
|
||||
@@ -209,21 +209,21 @@ def gen_proof_input(proof, root, key, value, maxDepth, maxKeyHexLen, maxValueHex
|
||||
rlp_prefix = last[curr_idx: curr_idx + 2]
|
||||
curr_idx = curr_idx + 2
|
||||
if int(rlp_prefix, 16) <= int('b7', 16):
|
||||
leafRlpValueLenHexLen = 0
|
||||
leafValueLenHexLen = 2 * (int(rlp_prefix, 16) - int('80', 16))
|
||||
leafValueRlpLengthHexLen = 0
|
||||
leafValueHexLen = 2 * (int(rlp_prefix, 16) - int('80', 16))
|
||||
elif int(rlp_prefix, 16) <= int('bf', 16):
|
||||
leafRlpValueLenHexLen = 2 * (int(rlp_prefix, 16) - int('b7', 16))
|
||||
str_len = last[curr_idx: curr_idx + leafRlpValueLenHexLen]
|
||||
curr_idx = curr_idx + leafRlpValueLenHexLen
|
||||
leafValueLenHexLen = 2 * int(str_len, 16)
|
||||
leafValueRlpLengthHexLen = 2 * (int(rlp_prefix, 16) - int('b7', 16))
|
||||
str_len = last[curr_idx: curr_idx + leafValueRlpLengthHexLen]
|
||||
curr_idx = curr_idx + leafValueRlpLengthHexLen
|
||||
leafValueHexLen = 2 * int(str_len, 16)
|
||||
elif int(rlp_prefix, 16) <= int('f7', 16):
|
||||
leafRlpValueLenHexLen = 0
|
||||
leafValueLenHexLen = 2 * (int(rlp_prefix, 16) - int('c0', 16))
|
||||
leafValueRlpLengthHexLen = 0
|
||||
leafValueHexLen = 2 * (int(rlp_prefix, 16) - int('c0', 16))
|
||||
elif int(rlp_prefix, 16) <= int('ff', 16):
|
||||
leafRlpValueLenHexLen = 2 * (int(rlp_prefix, 16) - int('f7', 16))
|
||||
str_len = last[curr_idx: curr_idx + leafRlpValueLenHexLen]
|
||||
curr_idx = curr_idx + leafRlpValueLenHexLen
|
||||
leafValueLenHexLen = 2 * int(str_len, 16)
|
||||
leafValueRlpLengthHexLen = 2 * (int(rlp_prefix, 16) - int('f7', 16))
|
||||
str_len = last[curr_idx: curr_idx + leafValueRlpLengthHexLen]
|
||||
curr_idx = curr_idx + leafValueRlpLengthHexLen
|
||||
leafValueHexLen = 2 * int(str_len, 16)
|
||||
|
||||
leafRlpHexs = serialize_hex(last)
|
||||
if debug:
|
||||
@@ -249,7 +249,7 @@ def gen_proof_input(proof, root, key, value, maxDepth, maxKeyHexLen, maxValueHex
|
||||
nodeRlpLengthHexLen.append(2 * (int(rlp_prefix, 16) - int('f7', 16)))
|
||||
curr_idx = curr_idx + nodeRlpLengthHexLen[-1]
|
||||
|
||||
nodePathRlpHexLen.append(0)
|
||||
nodePathRlpLengthHexLen.append(0)
|
||||
nodePathPrefixHexLen.append(0)
|
||||
nodePathHexLen.append(0)
|
||||
|
||||
@@ -262,21 +262,21 @@ def gen_proof_input(proof, root, key, value, maxDepth, maxKeyHexLen, maxValueHex
|
||||
rlp_prefix = node[curr_idx: curr_idx + 2]
|
||||
curr_idx = curr_idx + 2
|
||||
if int(rlp_prefix, 16) <= int('b7', 16):
|
||||
nodeVtRlpLenHexLen.append(0)
|
||||
nodeVtValueHexLen.append(2 * (int(rlp_prefix, 16) - int('80', 16)))
|
||||
nodeVtRlpLengthHexLen.append(0)
|
||||
nodeVtHexLen.append(2 * (int(rlp_prefix, 16) - int('80', 16)))
|
||||
elif int(rlp_prefix, 16) <= int('bf', 16):
|
||||
nodeVtRlpLenHexLen.append(2 * (int(rlp_prefix, 16) - int('b7', 16)))
|
||||
str_len = node[curr_idx: curr_idx + nodeVtRlpLenHexLen[-1]]
|
||||
curr_idx = curr_idx + nodeVtRlpLenHexLen[-1]
|
||||
nodeVtValueHexLen.append(2 * int(str_len, 16))
|
||||
nodeVtRlpLengthHexLen.append(2 * (int(rlp_prefix, 16) - int('b7', 16)))
|
||||
str_len = node[curr_idx: curr_idx + nodeVtRlpLengthHexLen[-1]]
|
||||
curr_idx = curr_idx + nodeVtRlpLengthHexLen[-1]
|
||||
nodeVtHexLen.append(2 * int(str_len, 16))
|
||||
elif int(rlp_prefix, 16) <= int('f7', 16):
|
||||
nodeVtRlpLenHexLen.append(0)
|
||||
nodeVtValueHexLen.append(2 * (int(rlp_prefix, 16) - int('c0', 16)))
|
||||
nodeVtRlpLengthHexLen.append(0)
|
||||
nodeVtHexLen.append(2 * (int(rlp_prefix, 16) - int('c0', 16)))
|
||||
elif int(rlp_prefix, 16) <= int('ff', 16):
|
||||
nodeVtRlpLenHexLen.append(2 * (int(rlp_prefix, 16) - int('f7', 16)))
|
||||
str_len = node[curr_idx: curr_idx + nodeVtRlpLenHexLen[-1]]
|
||||
curr_idx = curr_idx + nodeVtRlpLenHexLen[-1]
|
||||
nodeVtValueHexLen.append(2 * int(str_len, 16))
|
||||
nodeVtRlpLengthHexLen.append(2 * (int(rlp_prefix, 16) - int('f7', 16)))
|
||||
str_len = node[curr_idx: curr_idx + nodeVtRlpLengthHexLen[-1]]
|
||||
curr_idx = curr_idx + nodeVtRlpLengthHexLen[-1]
|
||||
nodeVtHexLen.append(2 * int(str_len, 16))
|
||||
|
||||
node_rlp = serialize_hex(node)
|
||||
if debug:
|
||||
@@ -301,12 +301,12 @@ def gen_proof_input(proof, root, key, value, maxDepth, maxKeyHexLen, maxValueHex
|
||||
rlp_prefix = node[curr_idx: curr_idx + 2]
|
||||
curr_idx = curr_idx + 2
|
||||
if int(rlp_prefix, 16) <= int('b7', 16):
|
||||
nodePathRlpHexLen.append(0)
|
||||
nodePathRlpLengthHexLen.append(0)
|
||||
nodePathHexLen.append(2 * (int(rlp_prefix, 16) - int('80', 16)))
|
||||
elif int(rlp_prefix, 16) <= int('bf', 16):
|
||||
nodePathRlpHexLen.append(2 * (int(rlp_prefix, 16) - int('b7', 16)))
|
||||
str_len = node[curr_idx: curr_idx + nodePathRlpHexLen[-1]]
|
||||
curr_idx = curr_idx + nodePathRlpHexLen[-1]
|
||||
nodePathRlpLengthHexLen.append(2 * (int(rlp_prefix, 16) - int('b7', 16)))
|
||||
str_len = node[curr_idx: curr_idx + nodePathRlpLengthHexLen[-1]]
|
||||
curr_idx = curr_idx + nodePathRlpLengthHexLen[-1]
|
||||
nodePathHexLen.append(2 * int(str_len, 16))
|
||||
|
||||
path_prefix_nibble = node[curr_idx]
|
||||
@@ -328,8 +328,8 @@ def gen_proof_input(proof, root, key, value, maxDepth, maxKeyHexLen, maxValueHex
|
||||
temp = temp + [0 for idx in range(15)]
|
||||
nodeRefHexLen.append(temp)
|
||||
|
||||
nodeVtRlpLenHexLen.append(0)
|
||||
nodeVtValueHexLen.append(0)
|
||||
nodeVtRlpLengthHexLen.append(0)
|
||||
nodeVtHexLen.append(0)
|
||||
|
||||
temp = serialize_hex(node)
|
||||
if debug:
|
||||
@@ -340,7 +340,7 @@ def gen_proof_input(proof, root, key, value, maxDepth, maxKeyHexLen, maxValueHex
|
||||
|
||||
for idx in range(maxDepth - len(proof)):
|
||||
nodeRlpLengthHexLen.append(0)
|
||||
nodePathRlpHexLen.append(0)
|
||||
nodePathRlpLengthHexLen.append(0)
|
||||
nodePathPrefixHexLen.append(0)
|
||||
nodePathHexLen.append(0)
|
||||
nodeRefHexLen.append([0 for idx in range(16)])
|
||||
@@ -357,15 +357,15 @@ def gen_proof_input(proof, root, key, value, maxDepth, maxKeyHexLen, maxValueHex
|
||||
"rootHashHexs": rootHashHexs,
|
||||
|
||||
"leafRlpLengthHexLen": leafRlpLengthHexLen,
|
||||
"leafPathRlpHexLen": leafPathRlpHexLen,
|
||||
"leafPathRlpLengthHexLen": leafPathRlpLengthHexLen,
|
||||
"leafPathPrefixHexLen": leafPathPrefixHexLen,
|
||||
"leafPathHexLen": leafPathHexLen,
|
||||
"leafRlpValueLenHexLen": leafRlpValueLenHexLen,
|
||||
"leafValueLenHexLen": leafValueLenHexLen,
|
||||
"leafValueRlpLengthHexLen": leafValueRlpLengthHexLen,
|
||||
"leafValueHexLen": leafValueHexLen,
|
||||
"leafRlpHexs": leafRlpHexs,
|
||||
|
||||
"nodeRlpLengthHexLen": nodeRlpLengthHexLen,
|
||||
"nodePathRlpHexLen": nodePathRlpHexLen,
|
||||
"nodePathRlpLengthHexLen": nodePathRlpLengthHexLen,
|
||||
"nodePathPrefixHexLen": nodePathPrefixHexLen,
|
||||
"nodePathHexLen": nodePathHexLen,
|
||||
"nodeRefHexLen": nodeRefHexLen,
|
||||
|
||||
@@ -7,18 +7,18 @@ component main {public [
|
||||
valueHexs,
|
||||
rootHashHexs,
|
||||
leafRlpLengthHexLen,
|
||||
leafPathRlpHexLen,
|
||||
leafPathRlpLengthHexLen,
|
||||
leafPathPrefixHexLen,
|
||||
leafPathHexLen,
|
||||
leafRlpValueLenHexLen,
|
||||
leafValueLenHexLen,
|
||||
leafValueRlpLengthHexLen,
|
||||
leafValueHexLen,
|
||||
leafRlpHexs,
|
||||
nodeRlpLengthHexLen,
|
||||
nodePathRlpHexLen,
|
||||
nodePathRlpLengthHexLen,
|
||||
nodePathPrefixHexLen,
|
||||
nodePathHexLen,
|
||||
nodeRefHexLen,
|
||||
nodeRlpHexs,
|
||||
nodeTypes,
|
||||
depth
|
||||
]} = MPTInclusionFixedKeyHexLen(8, 64, 114);
|
||||
]} = MPTInclusionFixedKeyHexLen(8, 64, 66);
|
||||
|
||||
@@ -20,7 +20,7 @@ echo $PWD
|
||||
|
||||
echo "****COMPILING CIRCUIT****"
|
||||
start=`date +%s`
|
||||
circom "$CIRCUIT_NAME".circom --r1cs --wasm --sym --c --wat --output "$BUILD_DIR"
|
||||
#circom "$CIRCUIT_NAME".circom --r1cs --wasm --sym --c --wat --output "$BUILD_DIR"
|
||||
end=`date +%s`
|
||||
echo "DONE ($((end-start))s)"
|
||||
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -7,14 +7,14 @@ component main {public [
|
||||
valueHexs,
|
||||
rootHashHexs,
|
||||
leafRlpLengthHexLen,
|
||||
leafPathRlpHexLen,
|
||||
leafPathRlpLengthHexLen,
|
||||
leafPathPrefixHexLen,
|
||||
leafPathHexLen,
|
||||
leafRlpValueLenHexLen,
|
||||
leafValueLenHexLen,
|
||||
leafValueRlpLengthHexLen,
|
||||
leafValueHexLen,
|
||||
leafRlpHexs,
|
||||
nodeRlpLengthHexLen,
|
||||
nodePathRlpHexLen,
|
||||
nodePathRlpLengthHexLen,
|
||||
nodePathPrefixHexLen,
|
||||
nodePathHexLen,
|
||||
nodeRefHexLen,
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
"keyHexs": [5, 11, 0, 0, 0, 0],
|
||||
"leafPathHexLen": 0,
|
||||
"leafPathPrefixHexLen": 0,
|
||||
"leafPathRlpHexLen": 0,
|
||||
"leafPathRlpLengthHexLen": 0,
|
||||
"leafRlpHexs": [15, 9, 0, 11, 14, 4, 2, 0, 11, 9, 0, 11, 14, 0, 0, 2, 15, 9, 0, 11, 13, 12, 0, 1,
|
||||
8, 2, 1, 13, 3, 3, 8, 4, 7, 7, 3, 5, 9, 4, 0, 0, 8, 5, 0, 12, 9, 13, 8, 1, 0, 3, 5,
|
||||
8, 8, 3, 0, 4, 8, 4, 14, 12, 9, 4, 7, 11, 14, 8, 0, 7, 6, 15, 4, 14, 10, 4, 10, 4,
|
||||
@@ -233,11 +233,11 @@
|
||||
7, 2, 0, 14, 4, 15, 10, 7, 3, 11, 5, 4, 13, 15, 7, 3, 8, 4, 1, 7, 8, 13, 6, 5, 3,
|
||||
15],
|
||||
"leafRlpLengthHexLen": 4,
|
||||
"leafRlpValueLenHexLen": 4,
|
||||
"leafValueLenHexLen": 6080,
|
||||
"leafValueRlpLengthHexLen": 4,
|
||||
"leafValueHexLen": 6080,
|
||||
"nodePathHexLen": [0, 0, 0, 0],
|
||||
"nodePathPrefixHexLen": [0, 0, 0, 0],
|
||||
"nodePathRlpHexLen": [0, 0, 0, 0],
|
||||
"nodePathHexLen": [0, 0, 0, 0],
|
||||
"nodeRefHexLen": [[64, 64, 64, 64, 64, 64, 64, 64, 64, 0, 0, 0, 0, 0, 0, 0],
|
||||
[64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64],
|
||||
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
||||
@@ -1842,4 +1842,4 @@
|
||||
12, 14, 6, 15, 2, 1, 0, 2, 10, 6, 15, 1, 14, 10, 0, 7, 5, 0, 10, 7, 11, 10, 12, 3, 5,
|
||||
7, 7, 2, 11, 8, 6, 2, 12, 2, 8, 6, 13, 8, 2, 11, 0, 9, 1, 11, 13, 6, 12, 11, 13, 10,
|
||||
8, 11, 10, 7, 2, 0, 14, 4, 15, 10, 7, 3, 11, 5, 4, 13, 15, 7, 3, 8, 4, 1, 7, 8, 13,
|
||||
6, 5, 3, 15]}
|
||||
6, 5, 3, 15]}
|
||||
|
||||
@@ -9,14 +9,14 @@ component main {public [
|
||||
valueHexs,
|
||||
rootHashHexs,
|
||||
leafRlpLengthHexLen,
|
||||
leafPathRlpHexLen,
|
||||
leafPathRlpLengthHexLen,
|
||||
leafPathPrefixHexLen,
|
||||
leafPathHexLen,
|
||||
leafRlpValueLenHexLen,
|
||||
leafValueLenHexLen,
|
||||
leafValueRlpLengthHexLen,
|
||||
leafValueHexLen,
|
||||
leafRlpHexs,
|
||||
nodeRlpLengthHexLen,
|
||||
nodePathRlpHexLen,
|
||||
nodePathRlpLengthHexLen,
|
||||
nodePathPrefixHexLen,
|
||||
nodePathHexLen,
|
||||
nodeRefHexLen,
|
||||
|
||||
@@ -21,20 +21,20 @@ echo $PWD
|
||||
|
||||
echo "****COMPILING CIRCUIT****"
|
||||
start=`date +%s`
|
||||
#circom "$CIRCUIT_NAME".circom --r1cs --wasm --sym --wat --O1 --output "$BUILD_DIR"
|
||||
circom "$CIRCUIT_NAME".circom --r1cs --wasm --sym --wat --output "$BUILD_DIR"
|
||||
#circom "$CIRCUIT_NAME".circom --r1cs --wasm --wat --O1 --output "$BUILD_DIR"
|
||||
end=`date +%s`
|
||||
echo "DONE ($((end-start))s)"
|
||||
|
||||
echo "****GENERATING ZKEY 0****"
|
||||
start=`date +%s`
|
||||
#NODE_OPTIONS="--max-old-space-size=56000" npx snarkjs groth16 setup "$BUILD_DIR"/"$CIRCUIT_NAME".r1cs "$PHASE1" "$BUILD_DIR"/"$CIRCUIT_NAME"_0.zkey
|
||||
NODE_OPTIONS="--max-old-space-size=56000" npx snarkjs groth16 setup "$BUILD_DIR"/"$CIRCUIT_NAME".r1cs "$PHASE1" "$BUILD_DIR"/"$CIRCUIT_NAME"_0.zkey
|
||||
end=`date +%s`
|
||||
echo "DONE ($((end-start))s)"
|
||||
|
||||
echo "****GENERATING FINAL ZKEY****"
|
||||
start=`date +%s`
|
||||
#NODE_OPTIONS="--max-old-space-size=56000" npx snarkjs zkey beacon "$BUILD_DIR"/"$CIRCUIT_NAME"_0.zkey "$BUILD_DIR"/"$CIRCUIT_NAME".zkey 0102030405060708090a0b0c0d0e0f101112231415161718221a1b1c1d1e1f 10 -n="Final Beacon phase2"
|
||||
NODE_OPTIONS="--max-old-space-size=56000" npx snarkjs zkey beacon "$BUILD_DIR"/"$CIRCUIT_NAME"_0.zkey "$BUILD_DIR"/"$CIRCUIT_NAME".zkey 0102030405060708090a0b0c0d0e0f101112231415161718221a1b1c1d1e1f 10 -n="Final Beacon phase2"
|
||||
end=`date +%s`
|
||||
echo "DONE ($((end-start))s)"
|
||||
|
||||
@@ -46,7 +46,7 @@ echo "DONE ($((end-start))s)"
|
||||
|
||||
echo "****EXPORTING VKEY****"
|
||||
start=`date +%s`
|
||||
#npx snarkjs zkey export verificationkey "$BUILD_DIR"/"$CIRCUIT_NAME".zkey "$BUILD_DIR"/vkey.json
|
||||
npx snarkjs zkey export verificationkey "$BUILD_DIR"/"$CIRCUIT_NAME".zkey "$BUILD_DIR"/vkey.json
|
||||
end=`date +%s`
|
||||
echo "DONE ($((end-start))s)"
|
||||
|
||||
|
||||
@@ -9,18 +9,18 @@ component main {public [
|
||||
valueHexs,
|
||||
rootHashHexs,
|
||||
leafRlpLengthHexLen,
|
||||
leafPathRlpHexLen,
|
||||
leafPathRlpLengthHexLen,
|
||||
leafPathPrefixHexLen,
|
||||
leafPathHexLen,
|
||||
leafRlpValueLenHexLen,
|
||||
leafValueLenHexLen,
|
||||
leafValueRlpLengthHexLen,
|
||||
leafValueHexLen,
|
||||
leafRlpHexs,
|
||||
nodeRlpLengthHexLen,
|
||||
nodePathRlpHexLen,
|
||||
nodePathRlpLengthHexLen,
|
||||
nodePathPrefixHexLen,
|
||||
nodePathHexLen,
|
||||
nodeRefHexLen,
|
||||
nodeRlpHexs,
|
||||
nodeTypes,
|
||||
depth
|
||||
]} = MPTInclusionNoBranchTermination(5, 6, 6078);
|
||||
]} = MPTInclusionNoBranchTermination(5, 6, 6080);
|
||||
|
||||
@@ -7,6 +7,6 @@ component main {public [
|
||||
nodeRefHexLen,
|
||||
nodeRefHexs,
|
||||
nodeRlpLengthHexLen,
|
||||
nodeValueLenHexLen,
|
||||
nodeValueHexLen,
|
||||
nodeRlpHexs
|
||||
]} = BranchFixedKeyHexLen(64);
|
||||
]} = EmptyVtBranchCheck(64);
|
||||
|
||||
@@ -7,10 +7,10 @@ component main {public [
|
||||
keyNibbleHexs,
|
||||
valueHexs,
|
||||
leafRlpLengthHexLen,
|
||||
leafPathRlpHexLen,
|
||||
leafPathRlpLengthHexLen,
|
||||
leafPathPrefixHexLen,
|
||||
leafPathHexLen,
|
||||
leafRlpValueLenHexLen,
|
||||
leafValueLenHexLen,
|
||||
leafValueRlpLengthHexLen,
|
||||
leafValueHexLen,
|
||||
leafRlpHexs
|
||||
]} = LeafCheck(64, 66);
|
||||
|
||||
@@ -7,14 +7,14 @@ component main {public [
|
||||
valueHexs,
|
||||
rootHashHexs,
|
||||
leafRlpLengthHexLen,
|
||||
leafPathRlpHexLen,
|
||||
leafPathRlpLengthHexLen,
|
||||
leafPathPrefixHexLen,
|
||||
leafPathHexLen,
|
||||
leafRlpValueLenHexLen,
|
||||
leafValueLenHexLen,
|
||||
leafValueRlpLengthHexLen,
|
||||
leafValueHexLen,
|
||||
leafRlpHexs,
|
||||
nodeRlpLengthHexLen,
|
||||
nodePathRlpHexLen,
|
||||
nodePathRlpLengthHexLen,
|
||||
nodePathPrefixHexLen,
|
||||
nodePathHexLen,
|
||||
nodeRefHexLen,
|
||||
|
||||
@@ -7,14 +7,14 @@ component main {public [
|
||||
valueHexs,
|
||||
rootHashHexs,
|
||||
leafRlpLengthHexLen,
|
||||
leafPathRlpHexLen,
|
||||
leafPathRlpLengthHexLen,
|
||||
leafPathPrefixHexLen,
|
||||
leafPathHexLen,
|
||||
leafRlpValueLenHexLen,
|
||||
leafValueLenHexLen,
|
||||
leafValueRlpLengthHexLen,
|
||||
leafValueHexLen,
|
||||
leafRlpHexs,
|
||||
nodeRlpLengthHexLen,
|
||||
nodePathRlpHexLen,
|
||||
nodePathRlpLengthHexLen,
|
||||
nodePathPrefixHexLen,
|
||||
nodePathHexLen,
|
||||
nodeRefHexLen,
|
||||
|
||||
@@ -7,14 +7,14 @@ component main {public [
|
||||
valueHexs,
|
||||
rootHashHexs,
|
||||
leafRlpLengthHexLen,
|
||||
leafPathRlpHexLen,
|
||||
leafPathRlpLengthHexLen,
|
||||
leafPathPrefixHexLen,
|
||||
leafPathHexLen,
|
||||
leafRlpValueLenHexLen,
|
||||
leafValueLenHexLen,
|
||||
leafValueRlpLengthHexLen,
|
||||
leafValueHexLen,
|
||||
leafRlpHexs,
|
||||
nodeRlpLengthHexLen,
|
||||
nodePathRlpHexLen,
|
||||
nodePathRlpLengthHexLen,
|
||||
nodePathPrefixHexLen,
|
||||
nodePathHexLen,
|
||||
nodeRefHexLen,
|
||||
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user