Skip to content

Commit a2e5151

Browse files
committed
prove 1 chunk
1 parent e91bc61 commit a2e5151

File tree

8 files changed

+236
-28
lines changed

8 files changed

+236
-28
lines changed
Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,41 @@
1-
const_message_hash = ["0x2c","0xf2","0x4d","0xba","0x5f","0xb0","0xa3","0x0e","0x26","0xe8","0x3b","0x2a","0xc5","0xb9","0xe2","0x9e","0x1b","0x16","0x1e","0x5c","0x1f","0xa7","0x42","0x5e","0x73","0x04","0x33","0x62","0x93","0x8b","0x98","0x24"]
1+
const_message_hash = [49, 95, 91, 219, 118, 208, 120, 196, 59, 138, 192, 6, 78, 74, 1, 100, 97, 43, 31, 206, 119, 200, 105, 52, 91, 252, 148, 199, 88, 148, 237, 211]
22

33
[[coins_database]]
4-
amount = "6094154"
5-
script_pub_key = ["0x76","0xa9","0x14","0xa7","0x93","0x36","0xda","0x4a","0xda","0x61","0x5f","0x0d","0x20","0x3f","0xc4","0xf0","0x95","0x6b","0x8e","0x6e","0xd7","0xf7","0x8b","0x88","0xac"]
4+
script_pub_key = [118, 169, 20, 121, 176, 0, 136, 118, 38, 178, 148, 169, 20, 80, 26, 76, 210, 38, 181, 139, 35, 89, 131, 136, 172]
5+
amount = 2627669
66

77
[[coins_database]]
8-
amount = "2238282"
9-
script_pub_key = ["0x76","0xa9","0x14","0xa7","0x93","0x36","0xda","0x4a","0xda","0x61","0x5f","0x0d","0x20","0x3f","0xc4","0xf0","0x95","0x6b","0x8e","0x6e","0xd7","0xf7","0x8b","0x88","0xac"]
8+
script_pub_key = [118, 169, 20, 121, 176, 0, 136, 118, 38, 178, 148, 169, 20, 80, 26, 76, 210, 38, 181, 139, 35, 89, 131, 136, 172]
9+
amount = 3111962
1010

1111
[[coins_database]]
12-
amount = "1103741"
13-
script_pub_key = ["0x76","0xa9","0x14","0xa7","0x93","0x36","0xda","0x4a","0xda","0x61","0x5f","0x0d","0x20","0x3f","0xc4","0xf0","0x95","0x6b","0x8e","0x6e","0xd7","0xf7","0x8b","0x88","0xac"]
12+
script_pub_key = [118, 169, 20, 121, 176, 0, 136, 118, 38, 178, 148, 169, 20, 80, 26, 76, 210, 38, 181, 139, 35, 89, 131, 136, 172]
13+
amount = 3060838
14+
15+
[[coins_database]]
16+
script_pub_key = [118, 169, 20, 121, 176, 0, 136, 118, 38, 178, 148, 169, 20, 80, 26, 76, 210, 38, 181, 139, 35, 89, 131, 136, 172]
17+
amount = 9993668
18+
19+
[[coins_database]]
20+
script_pub_key = [118, 169, 20, 121, 176, 0, 136, 118, 38, 178, 148, 169, 20, 80, 26, 76, 210, 38, 181, 139, 35, 89, 131, 136, 172]
21+
amount = 7353970
1422

1523
[[own_utxos]]
16-
pub_key = ["0x03","0xfa","0x81","0x48","0x41","0xe2","0x55","0x0b","0x88","0x24","0xa9","0x82","0xe9","0xfc","0x76","0xb6","0xd6","0x7f","0x7d","0x60","0x6f","0x03","0xd5","0x79","0xfe","0xa3","0x42","0x6b","0x1b","0x33","0x3b","0x07","0xd8","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00"]
17-
witness = [
18-
"0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00",
19-
"0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00",
20-
"0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00",
21-
"0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00",
22-
"0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00",
23-
"0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00",
24-
"0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00",
25-
"0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00",
26-
"0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00"
27-
]
24+
witness = [48, 69, 2, 33, 0, 176, 13, 195, 19, 255, 73, 45, 45, 108, 64, 66, 69, 250, 68, 134, 160, 179, 250, 237, 127, 30, 197, 101, 2, 107, 209, 142, 13, 184, 235, 138, 56, 2, 32, 120, 103, 36, 158, 33, 198, 151, 26, 30, 56, 250, 37, 73, 202, 33, 166, 26, 253, 114, 192, 163, 252, 223, 56, 48, 150, 15, 48, 27, 224, 6, 63, 0]
25+
pub_key = [3, 27, 132, 197, 86, 123, 18, 100, 64, 153, 93, 62, 213, 170, 186, 5, 101, 215, 30, 24, 52, 96, 72, 25, 255, 156, 23, 245, 233, 213, 221, 7, 143, 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]
2826

2927
[[own_utxos]]
30-
pub_key = ["0x03","0xfa","0x81","0x48","0x41","0xe2","0x55","0x0b","0x88","0x24","0xa9","0x82","0xe9","0xfc","0x76","0xb6","0xd6","0x7f","0x7d","0x60","0x6f","0x03","0xd5","0x79","0xfe","0xa3","0x42","0x6b","0x1b","0x33","0x3b","0x07","0xd8","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00"]
31-
witness = ["0x30","0x45","0x02","0x21","0x00","0xba","0x29","0x7c","0xea","0x0d","0x9c","0xf8","0xc1","0xcd","0xd3","0xb3","0x4a","0xe1","0xec","0x95","0x9c","0x9b","0x8d","0x46","0x7b","0x41","0xdb","0x0a","0x39","0x54","0x3e","0x32","0x9a","0xe9","0x3a","0x59","0x4e","0x02","0x20","0x0a","0xb1","0xea","0xed","0x72","0x13","0xa9","0x58","0xba","0xe5","0x0e","0x7f","0x4e","0x7a","0xca","0xd5","0x51","0xd6","0x9d","0x7b","0xcb","0x9a","0xec","0xaf","0x36","0xc0","0xa7","0x0f","0xca","0x41","0x7c","0xf9","0x00"]
28+
witness = [48, 69, 2, 33, 0, 176, 13, 195, 19, 255, 73, 45, 45, 108, 64, 66, 69, 250, 68, 134, 160, 179, 250, 237, 127, 30, 197, 101, 2, 107, 209, 142, 13, 184, 235, 138, 56, 2, 32, 120, 103, 36, 158, 33, 198, 151, 26, 30, 56, 250, 37, 73, 202, 33, 166, 26, 253, 114, 192, 163, 252, 223, 56, 48, 150, 15, 48, 27, 224, 6, 63, 0]
29+
pub_key = [3, 27, 132, 197, 86, 123, 18, 100, 64, 153, 93, 62, 213, 170, 186, 5, 101, 215, 30, 24, 52, 96, 72, 25, 255, 156, 23, 245, 233, 213, 221, 7, 143, 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]
3230

3331
[[own_utxos]]
34-
pub_key = ["0x03","0xfa","0x81","0x48","0x41","0xe2","0x55","0x0b","0x88","0x24","0xa9","0x82","0xe9","0xfc","0x76","0xb6","0xd6","0x7f","0x7d","0x60","0x6f","0x03","0xd5","0x79","0xfe","0xa3","0x42","0x6b","0x1b","0x33","0x3b","0x07","0xd8","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00"]
35-
witness = ["0x30","0x45","0x02","0x21","0x00","0xba","0x29","0x7c","0xea","0x0d","0x9c","0xf8","0xc1","0xcd","0xd3","0xb3","0x4a","0xe1","0xec","0x95","0x9c","0x9b","0x8d","0x46","0x7b","0x41","0xdb","0x0a","0x39","0x54","0x3e","0x32","0x9a","0xe9","0x3a","0x59","0x4e","0x02","0x20","0x0a","0xb1","0xea","0xed","0x72","0x13","0xa9","0x58","0xba","0xe5","0x0e","0x7f","0x4e","0x7a","0xca","0xd5","0x51","0xd6","0x9d","0x7b","0xcb","0x9a","0xec","0xaf","0x36","0xc0","0xa7","0x0f","0xca","0x41","0x7c","0xf9","0x00"]
32+
witness = [48, 69, 2, 33, 0, 176, 13, 195, 19, 255, 73, 45, 45, 108, 64, 66, 69, 250, 68, 134, 160, 179, 250, 237, 127, 30, 197, 101, 2, 107, 209, 142, 13, 184, 235, 138, 56, 2, 32, 120, 103, 36, 158, 33, 198, 151, 26, 30, 56, 250, 37, 73, 202, 33, 166, 26, 253, 114, 192, 163, 252, 223, 56, 48, 150, 15, 48, 27, 224, 6, 63, 0]
33+
pub_key = [3, 27, 132, 197, 86, 123, 18, 100, 64, 153, 93, 62, 213, 170, 186, 5, 101, 215, 30, 24, 52, 96, 72, 25, 255, 156, 23, 245, 233, 213, 221, 7, 143, 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]
3634

35+
[[own_utxos]]
36+
witness = [48, 69, 2, 33, 0, 176, 13, 195, 19, 255, 73, 45, 45, 108, 64, 66, 69, 250, 68, 134, 160, 179, 250, 237, 127, 30, 197, 101, 2, 107, 209, 142, 13, 184, 235, 138, 56, 2, 32, 120, 103, 36, 158, 33, 198, 151, 26, 30, 56, 250, 37, 73, 202, 33, 166, 26, 253, 114, 192, 163, 252, 223, 56, 48, 150, 15, 48, 27, 224, 6, 63, 0]
37+
pub_key = [3, 27, 132, 197, 86, 123, 18, 100, 64, 153, 93, 62, 213, 170, 186, 5, 101, 215, 30, 24, 52, 96, 72, 25, 255, 156, 23, 245, 233, 213, 221, 7, 143, 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]
38+
39+
[[own_utxos]]
40+
witness = [48, 69, 2, 33, 0, 176, 13, 195, 19, 255, 73, 45, 45, 108, 64, 66, 69, 250, 68, 134, 160, 179, 250, 237, 127, 30, 197, 101, 2, 107, 209, 142, 13, 184, 235, 138, 56, 2, 32, 120, 103, 36, 158, 33, 198, 151, 26, 30, 56, 250, 37, 73, 202, 33, 166, 26, 253, 114, 192, 163, 252, 223, 56, 48, 150, 15, 48, 27, 224, 6, 63, 0]
41+
pub_key = [3, 27, 132, 197, 86, 123, 18, 100, 64, 153, 93, 62, 213, 170, 186, 5, 101, 215, 30, 24, 52, 96, 72, 25, 255, 156, 23, 245, 233, 213, 221, 7, 143, 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]
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
pub global MAX_COINS_DATABASE_AMOUNT: u32 = 3;
2-
pub global MAX_MERKLE_TREE_LEVELS: u32 = 3;
1+
pub global MAX_COINS_DATABASE_AMOUNT: u32 = 5;
2+
pub global MAX_MERKLE_TREE_LEVELS: u32 = 4;
33

44
pub global SHA256_HASH_SIZE: u32 = 32;
55
pub global RIPEMD160_HASH_SIZE: u32 = 20;

circuits/app/proof_of_reserve/utxos_tree/Prover.toml

Lines changed: 5 additions & 0 deletions
Large diffs are not rendered by default.

circuits/app/proof_of_reserve/utxos_tree/src/constants.nr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
pub global MAX_MERKLE_TREE_LEVELS: u32 = 3;
2-
pub global MAX_NODES_AMOUNT: u32 = 3;
2+
pub global MAX_NODES_AMOUNT: u32 = 1;
33

44
pub global HONK_VK_SIZE: u32 = 128;
55
pub global HONK_PROOF_SIZE: u32 = 456;

utxo_indexer/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[workspace]
22
resolver = "3"
3-
members = ["indexer", "utxo_test_data_generator"]
3+
members = ["indexer", "proof_of_reserve", "utxo_test_data_generator"]
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[package]
2+
name = "proof_of_reserve"
3+
version = "0.1.0"
4+
edition = "2024"
5+
6+
[dependencies]
7+
utxo_test_data_generator = { path = "../utxo_test_data_generator" }
8+
anyhow = "1.0.99"
9+
toml = "0.9.8"
10+
serde = { version = "1.0", features = ["derive"] }
11+
serde_json = "1.0.145"
12+
hex = "0.4"
13+
sha2 = "0.10.9"
14+
k256 = { version = "0.11", features = ["ecdsa"] }
Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
use k256::{ecdsa::SigningKey, elliptic_curve::sec1::ToEncodedPoint};
2+
use serde::{Deserialize, Serialize};
3+
use sha2::{Digest, Sha256};
4+
use utxo_test_data_generator::test_data_gen::{TestUtxo, generate_test_utxos};
5+
use std::fs::{self, File};
6+
use std::io::Write;
7+
use anyhow::{Ok, Result};
8+
use std::process::Command;
9+
10+
const MAX_COINS_DATABASE_AMOUNT: usize = 5;
11+
const MAX_NODES_AMOUNT: usize = 8;
12+
13+
#[derive(Serialize, Deserialize)]
14+
struct CoinsDatabaseElement {
15+
script_pub_key: Vec<u8>,
16+
amount: u64,
17+
}
18+
19+
#[derive(Serialize, Deserialize)]
20+
struct Spending {
21+
witness: Vec<u8>, // 72 bytes
22+
pub_key: Vec<u8>, // 65 bytes
23+
}
24+
25+
#[derive(Serialize, Deserialize)]
26+
struct LeafsToml {
27+
const_message_hash: Vec<u8>,
28+
coins_database: Vec<CoinsDatabaseElement>,
29+
own_utxos: Vec<Spending>,
30+
}
31+
32+
#[derive(Serialize, Deserialize)]
33+
struct NodeProof {
34+
proof: Vec<String>,
35+
public_inputs: Vec<String>,
36+
}
37+
38+
#[derive(Serialize, Deserialize)]
39+
struct NodeToml {
40+
verification_key: Vec<String>,
41+
node_proofs: Vec<NodeProof>
42+
}
43+
44+
fn main() {
45+
let message = "Hello, world!";
46+
let priv_key = [1; 32];
47+
let utxos = generate_test_utxos(5, message.as_ref(), &priv_key).unwrap();
48+
49+
let sk = SigningKey::from_bytes(&priv_key).unwrap();
50+
let pk = sk.verifying_key();
51+
52+
let message_hash = Sha256::digest(message);
53+
let pub_key = pk.to_encoded_point(true);
54+
55+
// run first proof
56+
57+
leafs_toml(utxos, message_hash.as_ref(), pub_key.as_bytes()).unwrap();
58+
59+
let status = Command::new("bash")
60+
.arg("-c")
61+
.arg("nargo execute")
62+
.current_dir("../circuits/app/proof_of_reserve/coins")
63+
.status()
64+
.expect("failed to execute command");
65+
66+
assert!(status.success(), "Command return non-zero status");
67+
68+
fs::create_dir_all("../circuits/target/vk/leafs").unwrap();
69+
fs::create_dir_all("../circuits/target/vk/tree").unwrap();
70+
71+
let status = Command::new("bash")
72+
.arg("-c")
73+
.arg("bb write_vk -b ../../../target/coins.json -o ../../../target/vk/leafs --output_format bytes_and_fields --honk_recursion 1 --init_kzg_accumulator")
74+
.current_dir("../circuits/app/proof_of_reserve/coins")
75+
.status()
76+
.expect("failed to execute command");
77+
78+
assert!(status.success(), "Command return non-zero status");
79+
80+
fs::create_dir_all("../circuits/target/proof/leafs").unwrap();
81+
82+
let status = Command::new("bash")
83+
.arg("-c")
84+
.arg("bb prove -b ../../../target/coins.json -w ../../../target/coins.gz -o ../../../target/proof/leafs --output_format bytes_and_fields --honk_recursion 1 --recursive --init_kzg_accumulator")
85+
.current_dir("../circuits/app/proof_of_reserve/coins")
86+
.status()
87+
.expect("failed to execute command");
88+
89+
assert!(status.success(), "Command return non-zero status");
90+
91+
// run second proof
92+
93+
tree_toml().unwrap();
94+
95+
let status = Command::new("bash")
96+
.arg("-c")
97+
.arg("nargo execute")
98+
.current_dir("../circuits/app/proof_of_reserve/utxos_tree")
99+
.status()
100+
.expect("failed to execute command");
101+
102+
assert!(status.success(), "Command return non-zero status");
103+
104+
let status = Command::new("bash")
105+
.arg("-c")
106+
.arg("bb prove -b ../../../target/utxos_tree.json -w ../../../target/utxos_tree.gz -o ../../../target/proof/leafs --output_format bytes_and_fields --honk_recursion 1 --recursive --init_kzg_accumulator")
107+
.current_dir("../circuits/app/proof_of_reserve/utxos_tree")
108+
.status()
109+
.expect("failed to execute command");
110+
111+
assert!(status.success(), "Command return non-zero status");
112+
113+
}
114+
115+
fn leafs_toml(utxos: Vec<TestUtxo>, message_hash: &[u8; 32], public_key: &[u8]) -> Result<()> {
116+
let mut coins_database: Vec<CoinsDatabaseElement> = utxos.iter().map(|e| CoinsDatabaseElement { script_pub_key: hex::decode(&e.script_pub_key).unwrap(), amount: e.amount } ).collect();
117+
118+
let append_from = coins_database.len();
119+
let append_to = ((coins_database.len() + MAX_COINS_DATABASE_AMOUNT - 1) / MAX_COINS_DATABASE_AMOUNT) * MAX_COINS_DATABASE_AMOUNT;
120+
121+
for _ in append_from..append_to {
122+
coins_database.push(CoinsDatabaseElement { script_pub_key: Vec::from([0; 25]), amount: 0 });
123+
}
124+
125+
let mut own_utxos: Vec<Spending> = utxos
126+
.iter()
127+
.map(|e| {
128+
let mut witness = hex::decode(&e.witness).unwrap();
129+
if witness.len() < 72 {
130+
witness.resize(72, 0);
131+
}
132+
133+
let mut pub_key = Vec::from(public_key);
134+
if pub_key.len() < 65 {
135+
pub_key.resize(65, 0);
136+
}
137+
138+
Spending { witness, pub_key }
139+
})
140+
.collect();
141+
142+
let append_from = own_utxos.len();
143+
let append_to = ((own_utxos.len() + MAX_COINS_DATABASE_AMOUNT - 1) / MAX_COINS_DATABASE_AMOUNT) * MAX_COINS_DATABASE_AMOUNT;
144+
145+
for _ in append_from..append_to {
146+
own_utxos.push(Spending { witness: Vec::from([0; 72]), pub_key: Vec::from([0; 65]) });
147+
}
148+
149+
let toml_struct = LeafsToml {
150+
const_message_hash: Vec::from(message_hash),
151+
coins_database,
152+
own_utxos,
153+
};
154+
155+
let mut file = File::create("../circuits/app/proof_of_reserve/coins/Prover.toml")?;
156+
file.write(toml::to_string(&toml_struct)?.as_bytes())?;
157+
158+
Ok(())
159+
}
160+
161+
fn tree_toml() -> Result<()> {
162+
let proof_string = fs::read_to_string("../circuits/target/proof/leafs/proof_fields.json")?;
163+
let pi_string = fs::read_to_string("../circuits/target/proof/leafs/public_inputs_fields.json")?;
164+
let vk_string = fs::read_to_string("../circuits/target/vk/leafs/vk_fields.json")?;
165+
166+
let proof_fields: Vec<String> = serde_json::from_str(&proof_string)?;
167+
let pi_fields: Vec<String> = serde_json::from_str(&pi_string)?;
168+
let vk_fields: Vec<String> = serde_json::from_str(&vk_string)?;
169+
170+
let node_toml = NodeToml {
171+
verification_key: vk_fields,
172+
node_proofs: vec![
173+
NodeProof {
174+
proof: proof_fields,
175+
public_inputs: pi_fields
176+
}
177+
]
178+
};
179+
180+
let mut file = File::create("../circuits/app/proof_of_reserve/utxos_tree/Prover.toml")?;
181+
file.write(toml::to_string(&node_toml)?.as_bytes())?;
182+
183+
Ok(())
184+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
mod test_data_gen;
1+
pub mod test_data_gen;

0 commit comments

Comments
 (0)