-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #55 from 0xPolygonHermez/fix/storage-counter-on-de…
…lete Fix/storage counter on delete
- Loading branch information
Showing
6 changed files
with
238 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
; key bits with A,B = 0 C = # | ||
CONST %_0000101 = 8 ; 0000101....1010 #8 | ||
CONST %_0000111 = 4 ; 0000111....0001 #4 | ||
CONST %_0010001 = 13 ; 0010001....0111 #13 | ||
CONST %_0011010 = 1 ; 0011010....1110 #1 | ||
CONST %_0011101 = 5 ; 0011101....0001 #5 | ||
CONST %_0100101 = 7 ; 0100101....0110 #7 | ||
CONST %_0101011 = 10 ; 0101011....1001 #10 | ||
CONST %_0110101 = 3 ; 0110101....0010 #3 | ||
CONST %_0110110 = 9 ; 0110110....0110 #9 | ||
CONST %_0111001 = 6 ; 0111001....0000 #6 | ||
CONST %_1010110 = 15 ; 1010110....0101 #15 | ||
CONST %_1010111 = 14 ; 1010111....1101 #14 | ||
CONST %_1100011 = 12 ; 1100011....1010 #12 | ||
CONST %_1101000 = 0 ; 1101000....0010 #0 | ||
CONST %_1101010 = 2 ; 1101010....1001 #2 | ||
CONST %_1111001 = 11 ; 1111001....0110 #11 | ||
|
||
start: | ||
|
||
STEP => A | ||
0 :ASSERT | ||
|
||
; to verify that there are no correlations between counters | ||
0 => A | ||
CNT_ARITH :ASSERT | ||
CNT_BINARY :ASSERT | ||
CNT_KECCAK_F: ASSERT | ||
CNT_MEM_ALIGN :ASSERT | ||
CNT_POSEIDON_G :ASSERT | ||
CNT_PADDING_PG :ASSERT | ||
|
||
0 => SR | ||
|
||
%_1111001 => A | ||
0x10n => D | ||
$ => SR :SSTORE | ||
|
||
%_1100011 => A | ||
0x20n => D | ||
$ => SR :SSTORE | ||
|
||
%_1101000 => A | ||
0x40n => D | ||
$ => SR :SSTORE | ||
|
||
%_1111001 => A | ||
0n => D | ||
$ => SR :SSTORE | ||
|
||
%_1101000 => A | ||
0n => D | ||
$ => SR :SSTORE | ||
|
||
%_1100011 => A | ||
0n => D | ||
$ => SR :SSTORE | ||
|
||
end: | ||
0 => A,B,C,D,E,CTX, SP, PC, GAS, MAXMEM, SR | ||
|
||
finalWait: | ||
${beforeLast()} : JMPN(finalWait) | ||
|
||
: JMP(start) | ||
opINVALID: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
const fs = require("fs") | ||
const { Scalar } = require('ffjavascript'); | ||
const buildPoseidon = require("@0xpolygonhermez/zkevm-commonjs").getPoseidon; | ||
|
||
const argv = require("yargs") | ||
.usage("node gen_store_keys.js [-c <count>] [-o <output>]") | ||
.help('h') | ||
.alias("o", "output") | ||
.alias("c", "count") | ||
.argv; | ||
|
||
async function main(){ | ||
const output = typeof(argv.output) === "string" ? argv.output.trim() : "-"; | ||
const count = typeof(argv.count) === "number" ? argv.count : 100; | ||
|
||
const poseidon = await buildPoseidon(); | ||
const F = poseidon.F; | ||
|
||
// set A, B = 0 | ||
const A012345B01 = [F.zero, F.zero, F.zero, F.zero, F.zero, F.zero, F.zero, F.zero]; | ||
let hashes = []; | ||
for (let i = 0; i < count; ++i) { | ||
const C = [i, F.zero, F.zero, F.zero, F.zero, F.zero, F.zero, F.zero]; | ||
|
||
const keyI = poseidon(A012345B01); // Kin0 | ||
const key = poseidon(C, keyI); // Kin1 | ||
hashes.push(splitKey(key).join('') + ' #'+i); | ||
} | ||
hashes.sort(); | ||
let maxDepth = 0; | ||
for (let i = 1; i < count; ++i) { | ||
const depth = [...hashes[i]].findIndex((bit, index) => bit !== hashes[i-1][index]); | ||
maxDepth = depth > maxDepth ? depth : maxDepth; | ||
} | ||
const content = hashes.join("\n") + "\n"; | ||
if (output == '-') { | ||
console.log(content); | ||
} else { | ||
fs.writeFileSync(output, content , "utf8"); | ||
} | ||
console.log('max depth:' + maxDepth); | ||
|
||
|
||
function splitKey(k) { | ||
const res = []; | ||
const auxk = [F.toObject(k[0]), F.toObject(k[1]), F.toObject(k[2]), F.toObject(k[3])]; | ||
for (let i = 0; i < 64; i++) { | ||
for (let j = 0; j < 4; j++) { | ||
res.push(Scalar.toNumber(Scalar.band(auxk[j], Scalar.e(1)))); | ||
auxk[j] = Scalar.shr(auxk[j], 1); | ||
} | ||
} | ||
|
||
return res; | ||
} | ||
} | ||
|
||
main().then(()=> { | ||
process.exit(0); | ||
}, (err) => { | ||
console.log(err.message); | ||
console.log(err.stack); | ||
process.exit(1); | ||
}); |