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): check 4844 staticcall return values (TKO-22) #15574

Merged
merged 8 commits into from
Feb 1, 2024
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
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
Loading