diff --git a/packages/protocol/contracts/libs/LibZKP.sol b/packages/protocol/contracts/libs/LibZKP.sol index 24d8f36758a..c035613dc52 100644 --- a/packages/protocol/contracts/libs/LibZKP.sol +++ b/packages/protocol/contracts/libs/LibZKP.sol @@ -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 @@ -25,5 +25,7 @@ library LibZKP { zkproof ) ); + + return isCallSuccess && bytes32(response) == keccak256("taiko"); } } diff --git a/packages/protocol/contracts/libs/yul/PlonkVerifier_10_txs.yulp b/packages/protocol/contracts/libs/yul/PlonkVerifier_10_txs.yulp index edb031b0c52..14371324e4b 100644 --- a/packages/protocol/contracts/libs/yul/PlonkVerifier_10_txs.yulp +++ b/packages/protocol/contracts/libs/yul/PlonkVerifier_10_txs.yulp @@ -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) } } } diff --git a/packages/protocol/contracts/libs/yul/PlonkVerifier_80_txs.yulp b/packages/protocol/contracts/libs/yul/PlonkVerifier_80_txs.yulp index db9ab392d12..cd2bda5ebb9 100644 --- a/packages/protocol/contracts/libs/yul/PlonkVerifier_80_txs.yulp +++ b/packages/protocol/contracts/libs/yul/PlonkVerifier_80_txs.yulp @@ -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) } } } diff --git a/packages/protocol/test/libs/LibZKP.test.ts b/packages/protocol/test/libs/LibZKP.test.ts index 71b7fe49f5a..00faddf299a 100644 --- a/packages/protocol/test/libs/LibZKP.test.ts +++ b/packages/protocol/test/libs/LibZKP.test.ts @@ -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; + }); });