Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(protocol): let PlonkVerifier return keccak256("taiko") #13277

Merged
merged 1 commit into from
Mar 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
});
});