Skip to content

Commit

Permalink
Merge pull request #85 from hyperledger-labs/lock-delegate
Browse files Browse the repository at this point in the history
Add delegate to lockProof()
  • Loading branch information
jimthematrix committed Sep 26, 2024
2 parents 713dcce + a203759 commit 82f611a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
12 changes: 10 additions & 2 deletions solidity/contracts/lib/zeto_common.sol
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,17 @@ abstract contract ZetoCommon is OwnableUpgradeable {
// should be called by escrow contracts that will use uploaded proofs
// to execute transactions, in order to prevent the proof from being used
// by parties other than the escrow contract
function lockProof(Commonlib.Proof calldata proof) public {
function lockProof(
Commonlib.Proof calldata proof,
address delegate
) public {
bytes32 proofHash = Commonlib.getProofHash(proof);
lockedProofs[proofHash] = msg.sender;
require(
lockedProofs[proofHash] == address(0) ||
lockedProofs[proofHash] == msg.sender,
"Proof already locked by another party"
);
lockedProofs[proofHash] = delegate;
}

function sortInputsAndOutputs(
Expand Down
2 changes: 2 additions & 0 deletions solidity/contracts/zkDvP.sol
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,10 @@ contract zkDvP {
bytes32 proofHash = getProofHash(proof);
if (trade.paymentProofHash == proofHash) {
trade.paymentProof = proof;
paymentToken.lockProof(proof, address(this));
} else if (trade.assetProofHash == proofHash) {
trade.assetProof = proof;
assetToken.lockProof(proof, address(this));
} else {
revert("Invalid proof");
}
Expand Down
12 changes: 12 additions & 0 deletions solidity/test/zkDvP.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,18 @@ 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, await Alice.signer.getAddress())).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;
await expect(zkPayment.connect(Bob.signer).lockProof(proof.encodedProof, "0x0000000000000000000000000000000000000000")).fulfilled;
});
});

}).timeout(600000);

0 comments on commit 82f611a

Please sign in to comment.