Skip to content

Commit 08e4508

Browse files
committed
.
1 parent e806742 commit 08e4508

File tree

5 files changed

+81
-0
lines changed

5 files changed

+81
-0
lines changed

app/proof_of_reserve/Nargo.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[package]
2+
name = "proof_of_reserve"
3+
type = "bin"
4+
5+
[dependencies]
6+
trees = { git = "https://github.com/privacy-scaling-explorations/zk-kit.noir", tag = "merkle-trees-v0.0.1", directory = "packages/merkle-trees" }
7+
sha256 = { tag = "v0.1.0", git = "https://github.com/noir-lang/sha256" }

app/proof_of_reserve/Prover.toml

Whitespace-only changes.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
pub global CONST_STRING_LEN: u32 = 20;
2+
pub global COINS_DATABASE_AMOUNT: u32 = 100;
3+
pub global MAX_USER_UTXOS_AMOUNT: u32 = 20;

app/proof_of_reserve/src/main.nr

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
mod constants;
2+
3+
use trees::merkle::{MerkleTree, MT_Creator, Modifier, MembershipProver};
4+
5+
use constants::{CONST_STRING_LEN, COINS_DATABASE_AMOUNT, MAX_USER_UTXOS_AMOUNT};
6+
7+
// p2pkh
8+
struct COINS_DATABASE_ELEMENT {
9+
script_pub_key: [u8; 25],
10+
amount: u64,
11+
}
12+
13+
struct UTXO {
14+
index: u64,
15+
script_sig: [u8; 140],
16+
}
17+
18+
fn main(
19+
// merkle_root: pub [u8; 32],
20+
// const_string: pub str<CONST_STRING_LEN>,
21+
// coins_database: [COINS_DATABASE_ELEMENT; COINS_DATABASE_AMOUNT],
22+
// own_utxo: [UTXO; MAX_USER_UTXOS_AMOUNT],
23+
) -> pub Field {
24+
//println(merkle_root([[0; 32], [1; 32], [2; 32]]));
25+
let mut mt = MerkleTree::new(hasher);
26+
let paths= [];
27+
28+
mt.add([0; 32], 0, paths);
29+
let mut paths = paths.concat([mt.root]);
30+
mt.add([1; 32], 1, paths);
31+
paths[0] = mt.root;
32+
mt.add([3; 32], 0, []);
33+
mt.add([4; 32], 1, paths);
34+
35+
36+
mt.membership([0; 32], 0, [[1; 32], [3; 32]]);
37+
println(mt.root);
38+
0
39+
}
40+
41+
fn hasher(leaves: [[u8; 32]; 2]) -> [u8; 32] {
42+
sha256::digest(leaves[0].as_slice().append(leaves[1]).as_array::<64>())
43+
}
44+
45+
fn merkle_root<let N: u32>(leafs: [[u8; 32]; N]) -> [u8; 32] {
46+
let mut mt = MerkleTree::new(hasher);
47+
let paths= [];
48+
49+
let mut level_change = 0;
50+
let mut to_level = 2;
51+
52+
for i in 0..N {
53+
mt.add(leafs[i], i as Field, paths);
54+
let paths = paths.concat([mt.root]);
55+
}
56+
57+
mt.root
58+
}
59+
60+
// fn hash(leaf1: [u8; 32], leaf2: [u8; 32]) -> [u8; 32] {
61+
// sha256::digest(leaf1.as_slice().append(leaf2).as_array::<64>())
62+
// }
63+
64+
// fn merkle_root<let N: u32>(mut leafs: [[u8; 32]; N]) -> [u8; 32] {
65+
// for i in 0..(N/2) {
66+
// leafs[i] = hash(leafs[2*i], leafs[2*i+1]);
67+
// }
68+
69+
// leafs[0]
70+
// }

circuits/Nargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,5 @@ members = [
1717
"app/p2sh_p2wsh",
1818
"app/blocks_recursive/recursive_base",
1919
"app/blocks_recursive/recursive",
20+
"app/proof_of_reserve",
2021
]

0 commit comments

Comments
 (0)