From 07379c30bb6071a893c1d714e47f7f1a82fd3296 Mon Sep 17 00:00:00 2001 From: Jim Zhang Date: Thu, 26 Sep 2024 13:52:00 -0400 Subject: [PATCH] Allow proof lock to be updated Signed-off-by: Jim Zhang --- solidity/contracts/lib/zeto_common.sol | 6 +++++- solidity/test/zkDvP.ts | 11 +++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/solidity/contracts/lib/zeto_common.sol b/solidity/contracts/lib/zeto_common.sol index 83d271d..0b2ea79 100644 --- a/solidity/contracts/lib/zeto_common.sol +++ b/solidity/contracts/lib/zeto_common.sol @@ -48,7 +48,11 @@ abstract contract ZetoCommon is OwnableUpgradeable { address delegate ) public { bytes32 proofHash = Commonlib.getProofHash(proof); - require(lockedProofs[proofHash] == address(0), "Proof already locked"); + require( + lockedProofs[proofHash] == address(0) || + lockedProofs[proofHash] == msg.sender, + "Proof already locked by another party" + ); if (delegate != address(0)) { lockedProofs[proofHash] = delegate; } else { diff --git a/solidity/test/zkDvP.ts b/solidity/test/zkDvP.ts index 9159fe4..4540473 100644 --- a/solidity/test/zkDvP.ts +++ b/solidity/test/zkDvP.ts @@ -219,6 +219,17 @@ describe("DvP flows between fungible and non-fungible tokens based on Zeto with await expect(zkDvP.connect(Bob.signer).acceptTrade(tradeId, [0, 0], [0, 0], mockProofHash, 0, 0, mockProofHash)).rejectedWith("Payment inputs must be provided to accept the trade"); await expect(zkDvP.connect(Bob.signer).acceptTrade(tradeId, [utxo3.hash, utxo4.hash], [0, 0], mockProofHash, 0, 0, mockProofHash)).rejectedWith("Payment outputs must be provided to accept the trade"); }); + + it("test proof locking", async function () { + const circuit1 = await loadCircuit('anon'); + const { provingKeyFile: provingKey1 } = loadProvingKeys('anon'); + const utxo1 = newUTXO(100, Alice); + const proof = await zetoAnonTests.prepareProof(circuit1, provingKey1, Alice, [utxo1, ZERO_UTXO], [utxo1, ZERO_UTXO], [Alice, {}]); + + await expect(zkPayment.connect(Alice.signer).lockProof(proof.encodedProof, "0x0000000000000000000000000000000000000000")).fulfilled; + await expect(zkPayment.connect(Bob.signer).lockProof(proof.encodedProof, await Bob.signer.getAddress())).rejectedWith("Proof already locked by another party"); + await expect(zkPayment.connect(Alice.signer).lockProof(proof.encodedProof, await Bob.signer.getAddress())).fulfilled; + }); }); }).timeout(600000);