Skip to content

Commit

Permalink
Circuit: Fix balance violation
Browse files Browse the repository at this point in the history
  • Loading branch information
ConstanceBeguier committed Jul 6, 2023
1 parent ff2ac96 commit 5446987
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 18 deletions.
10 changes: 5 additions & 5 deletions src/circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ impl plonk::Circuit<pallas::Base> for Circuit {

// Constrain split_flag to be boolean
// Constrain v_old * (1 - split_flag) - v_new = magnitude * sign (https://p.z.cash/ZKS:action-cv-net-integrity?partial).
// Constrain (v_old = 0 and split_flag = 0) or (calculated root = anchor) (https://p.z.cash/ZKS:action-merkle-path-validity?partial).
// Constrain (v_old = 0 and is_native_asset = 1) or (calculated root = anchor) (https://p.z.cash/ZKS:action-merkle-path-validity?partial).
// Constrain v_old = 0 or enable_spends = 1 (https://p.z.cash/ZKS:action-enable-spend).
// Constrain v_new = 0 or enable_outputs = 1 (https://p.z.cash/ZKS:action-enable-output).
// Constrain is_native_asset to be boolean
Expand Down Expand Up @@ -278,12 +278,12 @@ impl plonk::Circuit<pallas::Base> for Circuit {
- magnitude * sign,
),
// We already checked that
// * split_flag is boolean (just above), and
// * is_native_asset is boolean (just above), and
// * v_old is a 64 bit integer (in the note commitment evaluation).
// So, split_flag + v_old = 0 only when (split_flag = 0 and v_old = 0), no overflow can occur.
// So, 1 - is_native_asset + v_old = 0 only when (is_native_asset = 1 and v_old = 0), no overflow can occur.
(
"(v_old = 0 and split_flag = 0) or (root = anchor)",
(v_old.clone() + split_flag.clone()) * (root - anchor),
"(v_old = 0 and is_native_asset = 1) or (root = anchor)",
(v_old.clone() + one.clone() - is_native_asset.clone()) * (root - anchor),
),
(
"v_old = 0 or enable_spends = 1",
Expand Down
33 changes: 20 additions & 13 deletions src/circuit_description
Original file line number Diff line number Diff line change
Expand Up @@ -261,20 +261,27 @@ PinnedVerificationKey {
),
Product(
Sum(
Advice {
query_index: 0,
column_index: 0,
rotation: Rotation(
0,
),
},
Advice {
query_index: 8,
column_index: 8,
rotation: Rotation(
0,
Sum(
Advice {
query_index: 0,
column_index: 0,
rotation: Rotation(
0,
),
},
Constant(
0x0000000000000000000000000000000000000000000000000000000000000001,
),
},
),
Negated(
Advice {
query_index: 9,
column_index: 9,
rotation: Rotation(
0,
),
},
),
),
Sum(
Advice {
Expand Down
Binary file modified src/circuit_proof_test_case.bin
Binary file not shown.

0 comments on commit 5446987

Please sign in to comment.