Skip to content

Commit 0a09df0

Browse files
authored
release: v0.10.0
1 parent f911db6 commit 0a09df0

34 files changed

+1562
-661
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ params:
3232
@for target_dir in $(TARGET_DIRS); do \
3333
size=$$(basename "$$target_dir" | sed 's/target_//' | sed 's/b//'); \
3434
echo "Generating parameters for $${size}b with ROM length 100..."; \
35-
cargo +nightly run --release -- "$$target_dir/artifacts" "$${size}b" "100" || exit 1; \
35+
cargo +nightly run --release -p create-pp -- "$$target_dir/artifacts" "$${size}b" "100" || exit 1; \
3636
done
3737

3838
.PHONY: check

builds/target_256b/json_extraction_256b.circom

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ pragma circom 2.1.9;
22

33
include "../../circuits/json/extraction.circom";
44

5-
component main { public [step_in] } = JSONExtraction(256, 10, 11);
5+
component main { public [step_in] } = JSONExtraction(256, 12, 11);

builds/target_512b/json_extraction_512b.circom

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ pragma circom 2.1.9;
22

33
include "../../circuits/json/extraction.circom";
44

5-
component main { public [step_in] } = JSONExtraction(512, 10, 11);
5+
component main { public [step_in] } = JSONExtraction(512, 12, 11);

circuits/chacha20/authentication.circom

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ template PlaintextAuthentication(DATA_BYTES, PUBLIC_IO_LENGTH) {
174174

175175
// reset HTTP Verification inputs
176176
step_out[2] <== step_in[2]; // Ciphertext digest POW accumulator
177-
step_out[3] <== 1; // Machine state hash digest
177+
step_out[3] <== PolynomialDigest(8)([1, 0, 0, 0, 0, 0, 0, 1], ciphertext_digest); // default Machine state digest
178178
for (var i = 4 ; i < PUBLIC_IO_LENGTH - 1 ; i++) {
179179
if (i == 6) {
180180
step_out[i] <== 0; // Body ciphertext digest pow counter

circuits/http/verification.circom

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ template HTTPVerification(DATA_BYTES, MAX_NUMBER_OF_HEADERS, PUBLIC_IO_LENGTH) {
88
signal input step_in[PUBLIC_IO_LENGTH];
99
signal output step_out[PUBLIC_IO_LENGTH];
1010

11-
// next_parsing_start, next_parsing_header, next_parsing_field_name, next_parsing_field_value, next_parsing_body, next_line_status, inner_main_digest
12-
signal input machine_state[7];
11+
// next_parsing_start, next_parsing_header, next_parsing_field_name, next_parsing_field_value, next_parsing_body, next_line_status, line_digest, main_monomial
12+
signal input machine_state[8];
1313

1414
signal input ciphertext_digest;
1515

@@ -39,11 +39,7 @@ template HTTPVerification(DATA_BYTES, MAX_NUMBER_OF_HEADERS, PUBLIC_IO_LENGTH) {
3939

4040
// assertions:
4141
// - check step_in[3] = machine state hash digest
42-
// for (var i = 0 ; i < 7 ; i++) {
43-
// log("machine_state[",i,"] = ", machine_state[i]);
44-
// }
45-
signal machine_state_digest <== PolynomialDigest(7)(machine_state, ciphertext_digest);
46-
// log("machine_state_digest: ", machine_state_digest);
42+
signal machine_state_digest <== PolynomialDigest(8)(machine_state, ciphertext_digest);
4743
step_in[3] === machine_state_digest;
4844
// - check step_in[4] = start line hash digest + all header hash digests
4945
// TODO: I don't like this `MAX_NUMBER_OF_HEADERS + 1` now. It should just be `NUMBER_OF_STATEMENTS_TO_LOCK` or something
@@ -80,7 +76,7 @@ template HTTPVerification(DATA_BYTES, MAX_NUMBER_OF_HEADERS, PUBLIC_IO_LENGTH) {
8076

8177

8278
signal main_monomials[DATA_BYTES];
83-
main_monomials[0] <== 1;
79+
main_monomials[0] <== machine_state[7];
8480

8581
signal is_line_change[DATA_BYTES-1];
8682
signal was_cleared[DATA_BYTES-1];
@@ -107,7 +103,7 @@ template HTTPVerification(DATA_BYTES, MAX_NUMBER_OF_HEADERS, PUBLIC_IO_LENGTH) {
107103
for(var i = 0 ; i < DATA_BYTES ; i++) {
108104
monomial_is_zero[i] <== IsZero()(main_monomials[i]);
109105
accum_prev[i] <== (1 - monomial_is_zero[i]) * line_digest[i];
110-
line_digest[i+1] <== accum_prev[i] + data[i] * main_monomials[i];
106+
line_digest[i+1] <== accum_prev[i] + data[i] * main_monomials[i];
111107
is_zero[i] <== IsZero()(line_digest[i+1]);
112108
contains[i] <== Contains(MAX_NUMBER_OF_HEADERS + 1)(line_digest[i+1], main_digests);
113109
is_match[i] <== (1 - is_zero[i]) * contains[i];
@@ -147,22 +143,25 @@ template HTTPVerification(DATA_BYTES, MAX_NUMBER_OF_HEADERS, PUBLIC_IO_LENGTH) {
147143
step_out[1] <== step_in[1];
148144
step_out[2] <== ciphertext_digest_pow[DATA_BYTES];
149145
// pass machine state to next iteration
150-
step_out[3] <== PolynomialDigest(7)(
146+
step_out[3] <== PolynomialDigest(8)(
151147
[State[DATA_BYTES - 1].next_parsing_start,
152148
State[DATA_BYTES - 1].next_parsing_header,
153149
State[DATA_BYTES - 1].next_parsing_field_name,
154150
State[DATA_BYTES - 1].next_parsing_field_value,
155151
State[DATA_BYTES - 1].next_parsing_body,
156152
State[DATA_BYTES - 1].next_line_status,
157-
line_digest[DATA_BYTES]
153+
line_digest[DATA_BYTES],
154+
main_monomials[DATA_BYTES - 1] * ciphertext_digest
158155
],
159156
ciphertext_digest
160157
);
161158
step_out[4] <== step_in[4];
162159
step_out[5] <== step_in[5] - num_matched; // No longer check above, subtract here so circuits later check
163160
step_out[6] <== body_monomials[DATA_BYTES - 1];
164161

165-
for (var i = 7 ; i < PUBLIC_IO_LENGTH ; i++) {
162+
step_out[7] <== 1; // TODO: can i continue this counter?
163+
step_out[8] <== 0; // TODO: This is a hack to make the circuit work. We should remove this in the future
164+
for (var i = 9 ; i < PUBLIC_IO_LENGTH ; i++) {
166165
step_out[i] <== step_in[i];
167166
}
168167

@@ -173,10 +172,11 @@ template HTTPVerification(DATA_BYTES, MAX_NUMBER_OF_HEADERS, PUBLIC_IO_LENGTH) {
173172
// log("next_parsing_body: ", State[DATA_BYTES - 1].next_parsing_body);
174173
// log("next_line_status: ", State[DATA_BYTES - 1].next_line_status);
175174
// log("line_digest: ", line_digest[DATA_BYTES]);
175+
// log("main_monomial: ", main_monomials[DATA_BYTES - 1] * ciphertext_digest);
176176
// log("body_digest: ", body_digest[DATA_BYTES - 1]);
177177

178-
// for (var i = 0 ; i < PUBLIC_IO_LENGTH ; i++) {
179-
// log("step_out[",i,"] = ", step_out[i]);
180-
// }
181-
// log("xxxxx HTTP Verification Done xxxxx");
178+
// for (var i = 0 ; i < PUBLIC_IO_LENGTH ; i++) {
179+
// log("step_out[",i,"] = ", step_out[i]);
180+
// }
181+
// log("xxxxx HTTP Verification Done xxxxx");
182182
}

circuits/json/extraction.circom

Lines changed: 21 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,18 @@ include "hash_machine.circom";
66
template JSONExtraction(DATA_BYTES, MAX_STACK_HEIGHT, PUBLIC_IO_LENGTH) {
77
signal input data[DATA_BYTES];
88
signal input ciphertext_digest;
9-
signal input sequence_digest;
9+
signal input sequence_digest; // todo(sambhav): should sequence digest be 0 for first json circuit?
1010
signal input value_digest;
11-
signal input state[MAX_STACK_HEIGHT * 4 + 3];
11+
signal input state[MAX_STACK_HEIGHT * 4 + 4];
1212

1313
signal input step_in[PUBLIC_IO_LENGTH];
1414
signal output step_out[PUBLIC_IO_LENGTH];
1515

1616
//--------------------------------------------------------------------------------------------//
1717

1818
// assertions:
19-
step_in[5] === 0; // HTTP statements matched
20-
signal input_state_digest <== PolynomialDigest(MAX_STACK_HEIGHT * 4 + 3)(state, ciphertext_digest);
19+
// step_in[5] === 0; // HTTP statements matched // TODO: either remove this or send a public io var
20+
signal input_state_digest <== PolynomialDigest(MAX_STACK_HEIGHT * 4 + 4)(state, ciphertext_digest);
2121
step_in[8] === input_state_digest;
2222
signal sequence_digest_hashed <== Poseidon(1)([sequence_digest]);
2323
step_in[9] === sequence_digest_hashed;
@@ -34,18 +34,6 @@ template JSONExtraction(DATA_BYTES, MAX_STACK_HEIGHT, PUBLIC_IO_LENGTH) {
3434
signal intermediate_digest[DATA_BYTES][3 * MAX_STACK_HEIGHT];
3535
signal state_digest[DATA_BYTES];
3636

37-
// Debugging
38-
// for(var i = 0; i<MAX_STACK_HEIGHT; i++) {
39-
// log("State[", 0, "].next_stack[", i,"] = [",State[0].next_stack[i][0], "][", State[0].next_stack[i][1],"]" );
40-
// }
41-
// for(var i = 0; i<MAX_STACK_HEIGHT; i++) {
42-
// log("State[", 0, "].next_tree_hash[", i,"] = [",State[0].next_tree_hash[i][0], "][", State[0].next_tree_hash[i][1],"]" );
43-
// }
44-
// log("State[", 0, "].next_monomial =", State[0].next_monomial);
45-
// log("State[", 0, "].next_parsing_string =", State[0].next_parsing_string);
46-
// log("State[", 0, "].next_parsing_number =", State[0].next_parsing_number);
47-
// log("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
48-
4937
var total_matches = 0;
5038
signal sequence_is_matched[DATA_BYTES];
5139
signal value_is_matched[DATA_BYTES];
@@ -61,7 +49,8 @@ template JSONExtraction(DATA_BYTES, MAX_STACK_HEIGHT, PUBLIC_IO_LENGTH) {
6149
State[0].polynomial_input <== ciphertext_digest;
6250
State[0].monomial <== state[MAX_STACK_HEIGHT*4];
6351
State[0].parsing_string <== state[MAX_STACK_HEIGHT*4 + 1];
64-
State[0].parsing_number <== state[MAX_STACK_HEIGHT*4 + 2];
52+
State[0].parsing_primitive <== state[MAX_STACK_HEIGHT*4 + 2];
53+
State[0].escaped <== state[MAX_STACK_HEIGHT*4 + 3];
6554
} else {
6655
State[data_idx] = StateUpdateHasher(MAX_STACK_HEIGHT);
6756
State[data_idx].byte <== data[data_idx];
@@ -70,7 +59,8 @@ template JSONExtraction(DATA_BYTES, MAX_STACK_HEIGHT, PUBLIC_IO_LENGTH) {
7059
State[data_idx].tree_hash <== State[data_idx - 1].next_tree_hash;
7160
State[data_idx].monomial <== State[data_idx - 1].next_monomial;
7261
State[data_idx].parsing_string <== State[data_idx - 1].next_parsing_string;
73-
State[data_idx].parsing_number <== State[data_idx - 1].next_parsing_number;
62+
State[data_idx].parsing_primitive <== State[data_idx - 1].next_parsing_primitive;
63+
State[data_idx].escaped <== State[data_idx - 1].next_escaped;
7464
}
7565

7666
// Digest the whole stack and key tree hash
@@ -104,14 +94,15 @@ template JSONExtraction(DATA_BYTES, MAX_STACK_HEIGHT, PUBLIC_IO_LENGTH) {
10494
// }
10595
// log("State[", data_idx, "].next_monomial =", State[data_idx].next_monomial);
10696
// log("State[", data_idx, "].next_parsing_string =", State[data_idx].next_parsing_string);
107-
// log("State[", data_idx, "].next_parsing_number =", State[data_idx].next_parsing_number);
97+
// log("State[", data_idx, "].next_parsing_primitive =", State[data_idx].next_parsing_primitive);
98+
// log("State[", data_idx, "].next_escaped =", State[data_idx].next_escaped);
10899
// log("++++++++++++++++++++++++++++++++++++++++++++++++");
109100
// log("state_digest[", data_idx,"] = ", state_digest[data_idx]);
110101
// log("total_matches = ", total_matches);
111102
// log("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
112103
}
113104

114-
signal new_state[MAX_STACK_HEIGHT*4 + 3];
105+
signal new_state[MAX_STACK_HEIGHT*4 + 4];
115106
for(var i = 0; i < MAX_STACK_HEIGHT; i++) {
116107
new_state[i*2] <== State[DATA_BYTES - 1].next_stack[i][0];
117108
new_state[i*2+1] <== State[DATA_BYTES - 1].next_stack[i][1];
@@ -120,11 +111,12 @@ template JSONExtraction(DATA_BYTES, MAX_STACK_HEIGHT, PUBLIC_IO_LENGTH) {
120111
}
121112
new_state[MAX_STACK_HEIGHT*4] <== State[DATA_BYTES - 1].next_monomial;
122113
new_state[MAX_STACK_HEIGHT*4 + 1] <== State[DATA_BYTES - 1].next_parsing_string;
123-
new_state[MAX_STACK_HEIGHT*4 + 2] <== State[DATA_BYTES - 1].next_parsing_number;
124-
signal new_state_digest <== PolynomialDigest(MAX_STACK_HEIGHT * 4 + 3)(new_state, ciphertext_digest);
114+
new_state[MAX_STACK_HEIGHT*4 + 2] <== State[DATA_BYTES - 1].next_parsing_primitive;
115+
new_state[MAX_STACK_HEIGHT*4 + 3] <== State[DATA_BYTES - 1].next_escaped;
116+
signal new_state_digest <== PolynomialDigest(MAX_STACK_HEIGHT * 4 + 4)(new_state, ciphertext_digest);
125117

126-
// for (var i = 0 ; i < MAX_STACK_HEIGHT * 4 + 3 ; i++) {
127-
// log("new_state[", i, "] = ", new_state[i]);
118+
// for (var i = 0 ; i < MAX_STACK_HEIGHT * 2 + 2 ; i++) {
119+
// log("new_state[", i, "] = ", new_state[i*2], new_state[i*2 + 1]);
128120
// }
129121

130122
// Verify we have now processed all the data properly
@@ -145,10 +137,12 @@ template JSONExtraction(DATA_BYTES, MAX_STACK_HEIGHT, PUBLIC_IO_LENGTH) {
145137
// Set the output to the digest of the intended value
146138
step_out[0] <== step_in[0] - data_digest + value_digest * total_matches;
147139

140+
// value_digest should be non-zero
141+
signal is_value_digest_zero <== IsEqual()([value_digest, 0]);
148142
// both should be 0 or 1 together
149143
signal is_new_state_digest_zero <== IsEqual()([new_state_digest, 0]);
150144
signal is_step_out_zero_matched <== IsEqual()([step_out[0], value_digest]);
151-
0 === is_new_state_digest_zero - is_step_out_zero_matched; // verify final value matches
145+
0 === (1 - is_value_digest_zero) * (is_new_state_digest_zero - is_step_out_zero_matched); // verify final value matches
152146

153147
step_out[1] <== step_in[1];
154148
step_out[2] <== step_in[2];
@@ -160,9 +154,8 @@ template JSONExtraction(DATA_BYTES, MAX_STACK_HEIGHT, PUBLIC_IO_LENGTH) {
160154
step_out[8] <== new_state_digest;
161155
step_out[9] <== step_in[9];
162156
step_out[10] <== step_in[10];
163-
for (var i = 11 ; i < PUBLIC_IO_LENGTH ; i++) {
164-
step_out[i] <== step_in[i];
165-
}
157+
158+
step_out[1] === step_out[2]; // assert http and plaintext parsed same amount
166159

167160
// for (var i = 0 ; i < PUBLIC_IO_LENGTH ; i++) {
168161
// log("step_out[", i, "] = ", step_out[i]);

0 commit comments

Comments
 (0)