-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add the function insert_commitments in cyKlone tree. * Add the new test vectors generator * Add a new withdrawal test item generation * Complete review of the tests * Esthetic improvement of the readme --------- Co-authored-by: CryptoPascal31 <[email protected]>
- Loading branch information
1 parent
410264c
commit 2489486
Showing
17 changed files
with
1,567 additions
and
100 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
all: install test-vectors.pact | ||
|
||
install: | ||
yarn install | ||
|
||
copy: test-vectors.pact | ||
cp test-vectors.pact ../pact/tests | ||
|
||
test-vectors.pact: index.js | ||
yarn run gen-tests | ||
|
||
clean: | ||
rm -rf node_modules | ||
rm -f merkle_tree.json | ||
rm -r test-vectors.pact |
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,17 @@ | ||
# cyKlone | ||
|
||
## Test suite Generator | ||
|
||
This directory contains a tool necessary to generate test vectors for the Pact REPL test files | ||
located in `pact/tests/` | ||
|
||
|
||
To install the dependencies: | ||
```shell | ||
make install | ||
``` | ||
|
||
To generate and install the test vectors: | ||
```shell | ||
make copy | ||
``` |
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,129 @@ | ||
// SPDX-License-Identifier: MIT | ||
import {CyKlone, CyKloneTree, CyKloneTransactionBuilder} from 'cyklone_js'; | ||
import { promises} from 'fs' | ||
import {hash} from '@kadena/cryptography-utils' | ||
|
||
const MNEMONIC = "obscure vivid ill elite sister evoke faculty accident slide alter kiwi captain" | ||
|
||
const RELAY_MODULE = "free.cyKlone-relay-v0" | ||
|
||
const MAIN_WITHDRAWER = "bob" | ||
|
||
const compute_cap_guard_principal = (account) => "c:" + hash(`${RELAY_MODULE}.RELAY"${account}"`) | ||
|
||
|
||
|
||
const PROOFS_TO_GENERATE = { | ||
'0': [0, 1, 19], | ||
'1': [1, 2, 3, 10, 19], | ||
'2': [2, 3, 19], | ||
'3': [3,], | ||
'4': [4,40], | ||
'10':[10, 18], | ||
'19':[19,], | ||
'36':[36,], | ||
'40':[40,], | ||
'41':[41,], | ||
} | ||
|
||
const nothing = () => undefined | ||
const reject = async () => {throw new Error("")} | ||
const local_read = (x) => promises.readFile("./"+x); | ||
|
||
class CyKloneTreeTest extends CyKloneTree | ||
{ | ||
constructor() | ||
{ | ||
super(nothing, reject) | ||
} | ||
|
||
update() | ||
{ | ||
return | ||
} | ||
|
||
} | ||
|
||
const cyKlone = new CyKlone(nothing, local_read, false); | ||
var deposit_data; | ||
|
||
|
||
|
||
async function gen_proof(withdrawer, deposit_index, tree_size) | ||
{ | ||
console.log(` ${deposit_index} => ${tree_size}`) | ||
const testTree = new CyKloneTreeTest() | ||
await testTree.load() | ||
testTree.insert_commitments(deposit_data.slice(0, tree_size+1).map( (x) => x.commitment_str)) | ||
cyKlone.tree = testTree | ||
return await cyKlone.compute_withdrawal_data(withdrawer, MNEMONIC, deposit_index.toString()) | ||
} | ||
|
||
|
||
|
||
function gen_pact_proof(deposit_index, tree_size) | ||
{ | ||
return gen_proof(MAIN_WITHDRAWER, deposit_index, tree_size) | ||
.then( (x) =>[`(defconst WITHDRAW_${deposit_index}_${tree_size}_NULL:string "${x.nullifier_hash}")`, | ||
`(defconst WITHDRAW_${deposit_index}_${tree_size}_ROOT:string "${x.root}")`, | ||
`(defconst WITHDRAW_${deposit_index}_${tree_size}_PROOF:string "${x.proof}")`]) | ||
} | ||
|
||
function gen_pact_proof_relay(deposit_index, tree_size) | ||
{ | ||
const relayer = compute_cap_guard_principal(MAIN_WITHDRAWER) | ||
|
||
console.log(relayer) | ||
return gen_proof(relayer, deposit_index, tree_size) | ||
.then( (x) =>[`(defconst WITHDRAW_RELAY_${deposit_index}_${tree_size}_NULL:string "${x.nullifier_hash}")`, | ||
`(defconst WITHDRAW_RELAY_${deposit_index}_${tree_size}_ROOT:string "${x.root}")`, | ||
`(defconst WITHDRAW_RELAY_${deposit_index}_${tree_size}_PROOF:string "${x.proof}")`]) | ||
} | ||
|
||
|
||
|
||
async function main() | ||
{ | ||
|
||
await cyKlone.init() | ||
|
||
console.log("Generate deposits") | ||
deposit_data = Array.from({length: 50}, (x, i) => i) | ||
.map( (x)=> cyKlone.compute_deposit_data(MNEMONIC, x.toString())) | ||
|
||
const pact_deposits_list = deposit_data.map( (x,i) => `(defconst DEPOSIT_${i}:string "${x.commitment_str}")`) | ||
|
||
console.log("Generate stndard proofs") | ||
const pact_withd_list = [] | ||
for (const k of Object.keys(PROOFS_TO_GENERATE)) | ||
{ | ||
for(const tree_idx of PROOFS_TO_GENERATE[k]) | ||
{ | ||
let x = await gen_pact_proof(parseInt(k), tree_idx); | ||
pact_withd_list.push(...x) | ||
} | ||
} | ||
|
||
console.log("Generate relay proofs") | ||
const pact_withd_relay_list = [ | ||
...(await gen_pact_proof_relay(0,0)), | ||
...(await gen_pact_proof_relay(1,1)), | ||
] | ||
|
||
const pact_code = ` | ||
; Generated test vectors | ||
; Do not modifiy by hand | ||
(module test-vectors G | ||
(defcap G() true) | ||
; --------------------------- DEPOSITS ----------------------------------------- | ||
${pact_deposits_list.join('\n ')} | ||
; ------------------------- STANDARD WITHDRAWALS ------------------------------- | ||
${pact_withd_list.join('\n ')} | ||
; -------------------------- RELAY WITHDRAWAL ---------------------------------- | ||
${pact_withd_relay_list.join('\n ')} | ||
) | ||
` | ||
await promises.writeFile("test-vectors.pact", pact_code) | ||
} | ||
|
||
main() |
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,13 @@ | ||
{ | ||
"name": "gen_test_vectors", | ||
"version": "1.0.0", | ||
"main": "index.js", | ||
"license": "MIT", | ||
"type": "module", | ||
"scripts": { | ||
"gen-tests": "node index.js" | ||
}, | ||
"dependencies": { | ||
"cyklone_js": "file:../cyklone_js" | ||
} | ||
} |
Oops, something went wrong.