Refactor Eth circuits

This commit is contained in:
Yi Sun
2022-01-27 04:11:24 -05:00
parent 2688228fcc
commit 57d9f35254
8 changed files with 145 additions and 48 deletions

View File

@@ -2,7 +2,7 @@
PHASE1=circuits/pot24_final.ptau
BUILD_DIR=build
CIRCUIT_NAME=test_keccak_or_literal_hex
CIRCUIT_NAME=test
if [ -f "$PHASE1" ]; then
echo "Found Phase 1 ptau file"
@@ -28,7 +28,7 @@ echo "DONE ($((end-start))s)"
echo "****GENERATING WITNESS FOR SAMPLE INPUT****"
start=`date +%s`
node "$BUILD_DIR"/"$CIRCUIT_NAME"_js/generate_witness.js "$BUILD_DIR"/"$CIRCUIT_NAME"_js/"$CIRCUIT_NAME".wasm test/input_keccak.json "$BUILD_DIR"/witness.wtns
node "$BUILD_DIR"/"$CIRCUIT_NAME"_js/generate_witness.js "$BUILD_DIR"/"$CIRCUIT_NAME"_js/"$CIRCUIT_NAME".wasm test/input_branch.json "$BUILD_DIR"/witness.wtns
end=`date +%s`
echo "DONE ($((end-start))s)"

View File

@@ -84,3 +84,59 @@ template EthBlockHashHex() {
blockHash[idx] <== keccak.out[idx];
}
}
template EthStorageProof(depth) {
signal input storageRootHexs[64];
// uint256
signal input slotHexLen;
signal input slotHexs[64];
signal input valueRlpHexLen;
signal input valueRlpHexs[66];
signal output out;
}
template EthAddressProof(depth) {
signal input stateRootHexs[64];
signal input addressHexs[40];
signal input addressValueRlpHexLen;
signal input addressValueRlpHexs[228];
signal output out;
}
template EthAddressStorageProof(addressDepth, storageDepth) {
signal input blockHashHexs[64];
signal input rlpPrefixHexs[6];
signal input parentHashRlpHexs[64 + 2];
signal input ommersHashRlpHexs[64 + 2];
signal input beneficiaryRlpHexs[40 + 2];
signal input stateRootRlpHexs[64 + 2];
signal input transactionsRootRlpHexs[64 + 2];
signal input receiptsRootRlpHexs[64 + 2];
signal input logsBloomRlpHexs[64 * 8 + 6];
signal input difficultyRlpHexs[16];
signal input suffixRlpHexLen;
signal input suffixRlpHexs[8 + 10 + 10 + 10 + 64 + 2 + 64 + 2 + 16 + 2 + 12];
// address proof inputs
signal input stateRootHexs[64];
signal input addressHexs[40];
signal input addressValueRlpHexLen;
signal input addressValueRlpHexs[228];
// storage proof inputs
signal input slotHexLen;
signal input slotHexs[64];
signal input valueRlpHexLen;
signal input valueRlpHexs[66];
signal output out;
}

View File

@@ -1,29 +1,7 @@
pragma circom 2.0.1;
pragma circom 2.0.2;
include "./ethblockhash.circom";
include "./mpt.circom";
//component main {public [
// keyNibbleHexLen,
// keyNibbleHexs,
// valueHexs,
// leafRlpLengthHexLen,
// leafPathRlpHexLen,
// leafPathPrefixHexLen,
// leafPathHexLen,
// leafRlpValueLenHexLen,
// leafValueLenHexLen,
// leafRlpHexs
//]} = LeafFixedKeyHexLen(64, 66);
//component main {public [
// keyNibble,
// nodeRefHexLen,
// nodeRefHexs,
// nodeRlpLengthHexLen,
// nodeValueLenHexLen,
// nodeRlpHexs
//]} = BranchFixedKeyHexLen(64);
// component main {public [rlpPrefixHexs,
// parentHashRlpHexs,
@@ -37,24 +15,33 @@ include "./mpt.circom";
// suffixRlpHexs,
// suffixRlpHexLen]} = EthBlockHashHex();
component main {public [
keyHexs,
valueHexs,
rootHashHexs,
leafRlpLengthHexLen,
leafPathRlpHexLen,
leafPathPrefixHexLen,
leafPathHexLen,
leafRlpValueLenHexLen,
leafValueLenHexLen,
leafRlpHexs,
nodeRlpLengthHexLen,
nodePathRlpHexLen,
nodePathPrefixHexLen,
nodePathHexLen,
keyNibble,
nodeRefHexLen,
nodeRlpHexs,
nodeTypes,
depth
]} = MPTInclusionFixedKeyHexLen(5, 64, 114);
nodeRefHexs,
nodeRlpLengthHexLen,
nodeValueLenHexLen,
nodeRlpHexs
]} = BranchFixedKeyHexLen(64);
//component main {public [
// keyHexs,
// valueHexs,
// rootHashHexs,
// leafRlpLengthHexLen,
// leafPathRlpHexLen,
// leafPathPrefixHexLen,
// leafPathHexLen,
// leafRlpValueLenHexLen,
// leafValueLenHexLen,
// leafRlpHexs,
// nodeRlpLengthHexLen,
// nodePathRlpHexLen,
// nodePathPrefixHexLen,
// nodePathHexLen,
// nodeRefHexLen,
// nodeRlpHexs,
// nodeTypes,
// depth
//]} = MPTInclusionFixedKeyHexLen(5, 64, 114);

View File

@@ -5,7 +5,7 @@
"main": "index.js",
"scripts": {
"build": "./build_circuits.sh",
"test": "mocha -r ts-node/register 'test/**/*.ts'"
"test": "NODE_OPTIONS='--max-old-space-size=56000' mocha -r ts-node/register 'test/**/*.ts'"
},
"repository": "git@github.com:yi-sun/eth-attestor.git",
"author": "Yi Sun <yi-sun@users.noreply.github.com>",

View File

@@ -1,7 +1,7 @@
{"keyNibble": 2,
"nodeRefHexs": [5, 4, 12, 9, 6, 11, 1, 4, 12, 10, 14, 11, 0, 15, 2, 13, 7, 13, 5, 11, 7, 6, 9, 8, 10, 14, 0, 14, 13, 3, 14, 8, 6, 13, 10, 5, 1, 3, 14, 10, 5, 10, 15, 5, 6, 5, 12, 13, 2, 5, 12, 6, 5, 13, 4, 6, 1, 3, 12, 11, 0, 5, 1, 13],
"nodeValueLenHexLen": [64, 0, 64, 0, 0, 0, 0, 64, 0, 64, 0, 0, 0, 64, 0, 0],
"nodeRlpHexs": [15, 8, 11, 1, 10, 0, 10, 2, 11, 13, 9, 9, 13, 14, 7, 2, 11, 12, 6, 14, 9, 12, 0, 9, 9, 6, 6, 15, 3, 5, 3, 15, 11, 12, 7, 4, 3, 6, 10, 6, 8, 12, 1, 2, 4, 8, 9, 9, 15, 15, 3, 10, 12, 11, 10, 8, 2, 13, 12, 2, 12, 3, 9, 1, 11, 5, 14, 8, 6, 14, 8, 0, 10, 0, 5, 4, 12, 9, 6, 11, 1, 4, 12, 10, 14, 11, 0, 15, 2, 13, 7, 13, 5, 11, 7, 6, 9, 8, 10, 14, 0, 14, 13, 3, 14, 8, 6, 13, 10, 5, 1, 3, 14, 10, 5, 10, 15, 5, 6, 5, 12, 13, 2, 5, 12, 6, 5, 13, 4, 6, 1, 3, 12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 1, 5, 12, 1, 6, 12, 0, 4, 15, 3, 14, 15, 12, 8, 2, 10, 10, 14, 13, 12, 9, 7, 11, 14, 5, 9, 15, 3, 15, 3, 7, 7, 12, 0, 13, 3, 15, 0, 0, 0, 0],
"keyNibbleHexs": [2, 2, 2, 3, 1, 3, 14, 2, 8, 4, 5, 9, 5, 2, 8, 13, 9, 2, 0, 11, 6, 5, 1, 1, 5, 12, 1, 6, 12, 0, 4, 15, 3, 14, 15, 12, 8, 2, 10, 10, 14, 13, 12, 9, 7, 11, 14, 5, 9, 15, 3, 15, 3, 7, 7, 12, 0, 13, 3, 15, 0, 0, 0, 0],
"valueHexs": [2, 7, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
"leafRlpLengthHexLen": 0,
"leafPathRlpHexLen": 0,

View File

@@ -74,7 +74,6 @@ describe("keccak256orliteralhex 550 hash", function() {
hexString = hexString + input[i].toString(16);
}
let hash: any = keccak256(hexString);
console.log(hash);
for (var i = 2; i < 66; i++) {
output.push(BigInt(parseInt(hash.charAt(i), 16)));
}

File diff suppressed because one or more lines are too long