Skip to content

Commit

Permalink
feat(protocol): check 4844 staticcall return values (TKO-22) (#15574)
Browse files Browse the repository at this point in the history
Co-authored-by: David <david@taiko.xyz>
  • Loading branch information
dantaik and davidtaikocha authored Feb 1, 2024
1 parent 8c0750a commit 00a9cd7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
22 changes: 18 additions & 4 deletions packages/protocol/contracts/4844/Lib4844.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ pragma solidity 0.8.24;
/// `solc contracts/libs/Lib4844.sol --ir > contracts/libs/Lib4844.yul`
library Lib4844 {
address public constant POINT_EVALUATION_PRECOMPILE_ADDRESS = address(0x0A);
uint32 public constant FIELD_ELEMENTS_PERBLOB = 4096;
uint32 public constant FIELD_ELEMENTS_PER_BLOB = 4096;
uint256 public constant BLS_MODULUS =
52_435_875_175_126_190_479_447_740_508_185_965_837_690_552_500_527_637_822_603_658_699_938_581_184_513;

error EVAL_FAILED();
error EVAL_FAILED_1();
error EVAL_FAILED_2();
error POINT_X_TOO_LARGE();
error POINT_Y_TOO_LARGE();

Expand All @@ -46,9 +47,22 @@ library Lib4844 {
if (x >= BLS_MODULUS) revert POINT_X_TOO_LARGE();
if (y >= BLS_MODULUS) revert POINT_Y_TOO_LARGE();

(bool ok,) = POINT_EVALUATION_PRECOMPILE_ADDRESS.staticcall(
(bool ok, bytes memory ret) = POINT_EVALUATION_PRECOMPILE_ADDRESS.staticcall(
abi.encodePacked(blobHash, x, y, commitment, pointProof)
);
if (!ok) revert EVAL_FAILED();

if (!ok) revert EVAL_FAILED_1();

if (ret.length != 64) revert EVAL_FAILED_2();

bytes32 first;
bytes32 second;
assembly {
first := mload(add(ret, 32))
second := mload(add(ret, 64))
}
if (uint256(first) != FIELD_ELEMENTS_PER_BLOB || uint256(second) != BLS_MODULUS) {
revert EVAL_FAILED_2();
}
}
}
3 changes: 2 additions & 1 deletion packages/protocol/contracts/L1/verifiers/PlonkVerifier.yulp
Original file line number Diff line number Diff line change
Expand Up @@ -2248,7 +2248,8 @@ contract Halo2Verifier {
// Revert if anything fails
if iszero(success) { revert(0, 0) }

// Return taiko hash bytes on success
// Return taiko hash bytes on success:
// 0x93ac8...0177 = keccak("taiko")
mstore(0x00, 0x93ac8fdbfc0b0608f9195474a0dd6242f019f5abc3c4e26ad51fefb059cc0177)
return(0, 32)
}
Expand Down

0 comments on commit 00a9cd7

Please sign in to comment.