Skip to content

Commit

Permalink
feat(protocol): let PlonkVerifier return keccak256("taiko") (#13277)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidtaikocha committed Mar 9, 2023
1 parent 9cb1740 commit 8ca632c
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 3 deletions.
4 changes: 3 additions & 1 deletion packages/protocol/contracts/libs/LibZKP.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ library LibZKP {
bytes calldata zkproof,
bytes32 instance
) internal view returns (bool verified) {
(verified, ) = plonkVerifier.staticcall(
(bool isCallSuccess, bytes memory response) = plonkVerifier.staticcall(
bytes.concat(
bytes16(0),
bytes16(instance), // left 16 bytes of the given instance
Expand All @@ -25,5 +25,7 @@ library LibZKP {
zkproof
)
);

return isCallSuccess && bytes32(response) == keccak256("taiko");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2143,8 +2143,9 @@ success := and(eq(staticcall(gas(), 0x8, 0xbe60, 0x180, 0xbe60, 0x20), 1), succe
success := and(eq(mload(0xbe60), 1), success)

if not(success) { revert(0, 0) }
return(0, 0)

mstore(0x00, 0x93ac8fdbfc0b0608f9195474a0dd6242f019f5abc3c4e26ad51fefb059cc0177) // keccak256("taiko")
return(0, 32)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2145,8 +2145,9 @@ success := and(eq(staticcall(gas(), 0x8, 0xbea0, 0x180, 0xbea0, 0x20), 1), succe
success := and(eq(mload(0xbea0), 1), success)

if not(success) { revert(0, 0) }
return(0, 0)

mstore(0x00, 0x93ac8fdbfc0b0608f9195474a0dd6242f019f5abc3c4e26ad51fefb059cc0177) // keccak256("taiko")
return(0, 32)
}
}
}
29 changes: 29 additions & 0 deletions packages/protocol/test/libs/LibZKP.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,33 @@ describe("LibZKP", function () {

expect(result).to.be.true;
});

it("should not successfully verifiy the given zkp and instance when the given contract address is not PlonkVerifier", async function () {
// random EOA address
let result = await libZKP.verify(
ethers.Wallet.createRandom().address,
testProof.result.circuit.proof,
ethers.utils.hexConcat([
testProof.result.circuit.instance[0],
testProof.result.circuit.instance[1],
])
);

expect(result).to.be.false;

// another smart contract
const testERC20 = await utils.deployContract(hre, "TestERC20", {}, [
1024,
]);
result = await libZKP.verify(
testERC20.address,
testProof.result.circuit.proof,
ethers.utils.hexConcat([
testProof.result.circuit.instance[0],
testProof.result.circuit.instance[1],
])
);

expect(result).to.be.false;
});
});

0 comments on commit 8ca632c

Please sign in to comment.