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

Add circuits for KYC enforcement with anonymity #25

Merged
merged 12 commits into from
Aug 7, 2024
Merged

Add circuits for KYC enforcement with anonymity #25

merged 12 commits into from
Aug 7, 2024

Conversation

jimthematrix
Copy link
Contributor

@jimthematrix jimthematrix commented Jul 30, 2024

Dependent on #26

A sample solution that enforces KYC on the sender and receiver Babyjubjub keys, by using a merkle tree in the smart contract to capture the registered identities, so that the transactions can prove against the current merkle tree root.

Note that the merkle tree implementation in Solidity currently only supports appending.

Copy link

codecov bot commented Jul 31, 2024

Welcome to Codecov 🎉

Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests.

Thanks for integrating Codecov - We've got you covered ☂️

@jimthematrix jimthematrix marked this pull request as draft July 31, 2024 20:59
@jimthematrix jimthematrix marked this pull request as ready for review August 5, 2024 18:04
/// @dev returns whether the given public key is registered
/// @param publicKey The Babyjubjub public key to check
/// @return bool whether the given public key is included in the registry
function isRegistered(
Copy link
Contributor

@Chengxuan Chengxuan Aug 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure where this gets used.

Copy link
Contributor

@Chengxuan Chengxuan Aug 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I answered my own question: it doesn't need to be used directly. as the circuit does the check with the identitiesRoot https://github.com/hyperledger-labs/zeto/pull/25/files#diff-9383275728425055b13bcbc860ce1ca0d4885b23049fa3ecf52fa71f1f144e65R105

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah it's a convenient method for client apps. not essential for the circuit verifier to work.

import { UTXO, User, newUser, newUTXO, newNullifier, doMint, ZERO_UTXO, parseUTXOEvents } from './lib/utils';
import { loadProvingKeys, prepareDepositProof, prepareNullifierWithdrawProof } from './utils';

describe("Zeto based fungible token with anonymity, KYC, using nullifiers without encryption", function () {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should there be a test for unregistered user checks?

Copy link
Contributor

@Chengxuan Chengxuan Aug 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ZKP part covered in https://github.com/hyperledger-labs/zeto/pull/25/files#diff-16c442cf7ed2d5adf832bff0e695df6a69fd1d71081cb25cad880fc93cd9ca79R146

I think it's worth having one at the contract level to capture regressions that are outside circuits.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added two new tests for the above suggested cases

error = e;
}
expect(error).to.match(/Error in template Zeto_254 line: 126/);
expect(error).to.match(/Error in template CheckSMTProof_253 line: 42/);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
expect(error).to.match(/Error in template CheckSMTProof_253 line: 42/);
expect(error).to.match(/Error in template CheckSMTProof_253 line: 46/);

Comment on lines +113 to +133
function deposit(
uint256 amount,
uint256 utxo,
Commonlib.Proof calldata proof
) public {
_deposit(amount, utxo, proof);
uint256[] memory utxos = new uint256[](1);
utxos[0] = utxo;
_mint(utxos);
}

function withdraw(
uint256 amount,
uint256[2] memory nullifiers,
uint256 output,
uint256 root,
Commonlib.Proof calldata proof
) public {
_withdrawWithNullifiers(amount, nullifiers, output, root, proof);
processInputsAndOutputs(nullifiers, [output, 0]);
}
Copy link
Contributor

@Chengxuan Chengxuan Aug 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should these 2 functions be allowed if the sender is not in the registry?

-- my understanding is because of "nullifiers", UTXO created by un-registered users will not be able to circulate, so that might be the reason these two functions do not check against the registry.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

correct, even if an unregistered user did a deposit, the only thing that user can do is return it back out via withdraw because the UTXOs are not allowed to be transferred.

Copy link
Contributor

@Chengxuan Chengxuan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @jimthematrix I left a few comments.

I love the refactor of the circuit code, they are awesome!!! 🚀 make the code so much easier to read. However, I didn't check the difference line by line as I'm assuming no modification was required while you broke them into small pieces for reusability.

@Chengxuan
Copy link
Contributor

@jimthematrix #25 (comment) needs addressing before merging the PR, otherwise, the circuit tests will fail.

Maybe the circuit tests should be part of the pipeline now as we've got automation in place?

@jimthematrix
Copy link
Contributor Author

jimthematrix commented Aug 7, 2024

thanks @Chengxuan. sorry about missing that. just pushed another commit to update the error checking. and yes #30 adds github actions that runs all the tests

@jimthematrix jimthematrix merged commit b1be3ba into main Aug 7, 2024
5 checks passed
@jimthematrix jimthematrix deleted the kyc branch August 7, 2024 16:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants