Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated the nullifier non-membership path #205

Closed
wants to merge 23 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 16 additions & 25 deletions circuits/common/joinCommitments.zok
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ from "./common/hashes/poseidon/poseidon.zok" import main as poseidon
from "./common/casts/u32_array_to_field.zok" import main as u32_array_to_field
from "utils/pack/bool/pack256.zok" import main as bool_256_to_field
from "./common/merkle-tree/mimc/altbn254/verify-membership/height32.zok" import main as checkRoot
from "./common/merkle-tree/sparse-merkle-tree/checkproof.zok" import checkUpdatedPath as checkUpdatedPath
from "./common/merkle-tree/sparse-merkle-tree/checkproof.zok" import main as checkproof
from "./common/merkle-tree/sparse-merkle-tree/checkproof.zok" import main as updateNullifierRoot

def main(\
private field fromId,\
Expand All @@ -20,13 +19,10 @@ def main(\
private field oldCommitment_0_owner_secretKey_field,\
private field oldCommitment_1_owner_secretKey_field,\
public field nullifierRoot,\
public field newNullifierRoot,\
public field oldCommitment_0_nullifier,\
public field[32] oldCommitment_0_nullifier_nonmembershipWitness_siblingPath,\
private field[32] oldCommitment_0_nullifier_nonmembershipWitness_newsiblingPath,\
private field[32] oldCommitment_0_nullifier_nonmembershipWitness_siblingPath,\
public field oldCommitment_1_nullifier,\
private field[32] oldCommitment_1_nullifier_nonmembershipWitness_siblingPath,\
private field[32] oldCommitment_1_nullifier_nonmembershipWitness_newsiblingPath,\
private field oldCommitment_0_value,\
private field oldCommitment_0_salt_field,\
private field oldCommitment_1_value,\
Expand All @@ -39,7 +35,7 @@ def main(\
private field newCommitment_owner_publicKey_field,\
private field newCommitment_salt_field,\
public field newCommitment_commitment\
) -> (bool) :
) -> (field) :

// check if state is mapping or not

Expand Down Expand Up @@ -94,18 +90,14 @@ def main(\
field_to_bool_256(oldCommitment_0_nullifier)[8..256] == field_to_bool_256(oldCommitment_0_nullifier_check_field)[8..256]\
)

assert(\
nullifierRoot == checkproof(\
oldCommitment_0_nullifier_nonmembershipWitness_siblingPath,\
oldCommitment_0_nullifier\
) )

assert( newNullifierRoot == checkUpdatedPath(oldCommitment_0_nullifier_nonmembershipWitness_newsiblingPath,\
oldCommitment_0_nullifier) )



nullifierRoot = updateNullifierRoot(\
oldCommitment_0_nullifier_nonmembershipWitness_siblingPath,\
oldCommitment_0_nullifier,\
nullifierRoot\
)


// Nullify oldCommitment_1:

field oldCommitment_1_nullifier_check_field = poseidon([\
Expand All @@ -118,15 +110,14 @@ def main(\
field_to_bool_256(oldCommitment_1_nullifier)[8..256] == field_to_bool_256(oldCommitment_1_nullifier_check_field)[8..256]\
)

assert(\
nullifierRoot == checkproof(\

nullifierRoot = updateNullifierRoot(\
oldCommitment_1_nullifier_nonmembershipWitness_siblingPath,\
oldCommitment_1_nullifier\
) )
oldCommitment_1_nullifier,\
nullifierRoot\
)


assert( newNullifierRoot == checkUpdatedPath(oldCommitment_1_nullifier_nonmembershipWitness_newsiblingPath,\
oldCommitment_1_nullifier) )

// oldCommitment_0_commitment: preimage check

field oldCommitment_0_commitment_field = poseidon([\
Expand Down Expand Up @@ -190,4 +181,4 @@ def main(\
field_to_bool_256(newCommitment_commitment)[8..256] == field_to_bool_256(newCommitment_commitment_check_field)[8..256]\
)

return true
return nullifierRoot
15 changes: 9 additions & 6 deletions circuits/common/merkle-tree/sparse-merkle-tree/checkproof.zok
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ from "hashes/poseidon/poseidon.zok" import main as poseidon
from "../../concatenate/order-left-right-1x1.zok" import main as orderLeftRight
from "utils/pack/bool/nonStrictUnpack256.zok" import main as field_to_bool_256

def main(field[32] siblingPath, field value) -> (field):

def checkRoot(field[32] siblingPath, field value, field root) -> (field):

field accValue = 0 // checking against zero element
field[2] preimage = [0, 0]
Expand All @@ -20,17 +19,22 @@ for u32 i in 0..32 do
])
endfor

assert(root == accValue)

return accValue


def checkUpdatedPath(field[32] siblingPath, field value) -> (field):

def main(field[32] siblingPath, field value, field root) -> (field):

assert(root == checkRoot(siblingPath, value, root))

field accValue = value // checking against zero element
// Calculate the new Root

field accValue = value // Inserting the element
field[2] preimage = [0, 0]
bool[32] valueIndex = field_to_bool_256(value)[2..34]


for u32 i in 0..32 do
u32 j = i // iterator for the siblingPath
u32 k = 31 - i // iterator for the leafIndexBits
Expand All @@ -41,5 +45,4 @@ for u32 i in 0..32 do
])
endfor


return accValue
Loading
Loading