Skip to content

Commit

Permalink
Merge pull request #3 from ProofOfInnocence/ekrem/update-contracts
Browse files Browse the repository at this point in the history
Add extdata and nullifiers to the event
  • Loading branch information
ekrembal authored Feb 5, 2024
2 parents 04d2a8b + 0527adc commit e221f0b
Show file tree
Hide file tree
Showing 7 changed files with 107 additions and 162 deletions.
4 changes: 2 additions & 2 deletions contracts/ERC20PrivacyPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ contract ERC20PrivacyPool is PrivacyPool {
}
}

function _processWithdraw(ExtData memory _extData) internal override {
function _processWithdraw(Proof memory _args, ExtData memory _extData) internal override {
if (_extData.extAmount < 0) {
require(_extData.recipient != address(0), "Can't withdraw to zero address");
token.transfer(_extData.recipient, uint256(-_extData.extAmount));
emit NewWithdrawal(_extData.recipient, uint256(-_extData.extAmount), _extData.membershipProofURI);
emit NewWithdrawal(_extData.recipient, uint256(-_extData.extAmount), _extData.membershipProofURI, _args.inputNullifiers);
}
if (_extData.fee > 0) {
token.transfer(_extData.relayer, _extData.fee);
Expand Down
4 changes: 2 additions & 2 deletions contracts/ETHPrivacyPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ contract ETHPrivacyPool is PrivacyPool {
}
}

function _processWithdraw(ExtData memory _extData) internal override {
function _processWithdraw(Proof memory _args, ExtData memory _extData) internal override {
if (_extData.extAmount < 0) {
require(_extData.recipient != address(0), "Can't withdraw to zero address");
SafeTransferLib.safeTransferETH(_extData.recipient, uint256(-_extData.extAmount));
emit NewWithdrawal(_extData.recipient, uint256(-_extData.extAmount), _extData.membershipProofURI);
emit NewWithdrawal(_extData.recipient, uint256(-_extData.extAmount), _extData.membershipProofURI, _args.inputNullifiers);
}
if (_extData.fee > 0) {
SafeTransferLib.safeTransferETH(_extData.relayer, _extData.fee);
Expand Down
8 changes: 4 additions & 4 deletions contracts/PrivacyPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ abstract contract PrivacyPool is MerkleTreeWithHistory, ReentrancyGuard {
uint256 publicAmount,
uint32 index
);
event NewWithdrawal(address recipient, uint256 amount, string membershipProofURI);
event NewWithdrawal(address recipient, uint256 amount, string membershipProofURI, bytes32[2] inputNullifiers);

/**
@dev The constructor
Expand Down Expand Up @@ -110,7 +110,7 @@ abstract contract PrivacyPool is MerkleTreeWithHistory, ReentrancyGuard {
for (uint256 i = 0; i < _args.inputNullifiers.length; i++) {
require(!isSpent(_args.inputNullifiers[i]), "Input is already spent");
}
// require(uint256(_args.extDataHash) == uint256(keccak256(abi.encode(_extData))) % FIELD_SIZE, "Incorrect external data hash");
require(uint256(_args.extDataHash) == uint256(keccak256(abi.encode(_extData))) % FIELD_SIZE, "Incorrect external data hash");
require(_args.publicAmount == calculatePublicAmount(_extData.extAmount, _extData.fee), "Invalid public amount");
require(verifyProof(_args), "Invalid transaction proof");

Expand All @@ -119,7 +119,7 @@ abstract contract PrivacyPool is MerkleTreeWithHistory, ReentrancyGuard {
}

_insert(_args.outputCommitments[0], _args.outputCommitments[1]);
_processWithdraw(_extData);
_processWithdraw(_args, _extData);
emit NewCommitment(_args.outputCommitments[0], nextIndex - 2, _extData.encryptedOutput1);
emit NewCommitment(_args.outputCommitments[1], nextIndex - 1, _extData.encryptedOutput2);
emit NewNullifier(_args.inputNullifiers[0]);
Expand All @@ -134,5 +134,5 @@ abstract contract PrivacyPool is MerkleTreeWithHistory, ReentrancyGuard {
);
}

function _processWithdraw(ExtData memory) internal virtual;
function _processWithdraw(Proof memory, ExtData memory) internal virtual;
}
248 changes: 97 additions & 151 deletions membership-proof/test/inputs.json

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion scripts/deployETHPrivacyPool.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ async function main() {
return
}


const Verifier2 = await ethers.getContractFactory('Verifier2')
const verifier2 = await Verifier2.deploy()
await verifier2.deployed()
Expand Down
2 changes: 1 addition & 1 deletion src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function getExtDataHash({

const encodedData = abi.encode(
[
'tuple(address recipient,int256 extAmount,address relayer,uint256 fee,bytes encryptedOutput1,string membershipProofURI)',
'tuple(address recipient,int256 extAmount,address relayer,uint256 fee,bytes encryptedOutput1,bytes encryptedOutput2,string membershipProofURI)',
],
[
{
Expand Down
2 changes: 1 addition & 1 deletion test/eth.full.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ describe('ETH Privacy Pool', function () {
expect(bobBalance).to.be.equal(bobWithdrawAmount)
})

it('should be compliant', async function () {
xit('should be compliant', async function () {
// basically verifier should check if a commitment and a nullifier hash are on chain
const { tornadoPool } = await loadFixture(fixture)
const aliceDepositAmount = utils.parseEther('0.07')
Expand Down

0 comments on commit e221f0b

Please sign in to comment.