From 1e0b23e80a43db4376360eea2652d006fd0f0ff0 Mon Sep 17 00:00:00 2001 From: Daniel Wang Date: Thu, 25 Jan 2024 21:32:52 +0800 Subject: [PATCH 1/3] check POINT_EVALUATION_PRECOMPILE_ADDRESS.staticcall return value --- packages/protocol/contracts/4844/Lib4844.sol | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/packages/protocol/contracts/4844/Lib4844.sol b/packages/protocol/contracts/4844/Lib4844.sol index a070f55858e..bef649b793e 100644 --- a/packages/protocol/contracts/4844/Lib4844.sol +++ b/packages/protocol/contracts/4844/Lib4844.sol @@ -19,11 +19,12 @@ pragma solidity 0.8.20; /// `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(); @@ -46,9 +47,20 @@ 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(); + + 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(); + } } } From 6b61f6a8359a83de4290b4616e5574b1ee3b85aa Mon Sep 17 00:00:00 2001 From: Daniel Wang Date: Thu, 25 Jan 2024 21:35:42 +0800 Subject: [PATCH 2/3] Update Lib4844.sol --- packages/protocol/contracts/4844/Lib4844.sol | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/protocol/contracts/4844/Lib4844.sol b/packages/protocol/contracts/4844/Lib4844.sol index bef649b793e..30db7b663f5 100644 --- a/packages/protocol/contracts/4844/Lib4844.sol +++ b/packages/protocol/contracts/4844/Lib4844.sol @@ -53,6 +53,8 @@ library Lib4844 { if (!ok) revert EVAL_FAILED_1(); + if (ret.length != 64) revert EVAL_FAILED_2(); + bytes32 first; bytes32 second; assembly { From 9b236188375cbd14d7abcb6d85f83ddf2b5ca20f Mon Sep 17 00:00:00 2001 From: Daniel Wang Date: Tue, 30 Jan 2024 19:47:29 +0800 Subject: [PATCH 3/3] Update PlonkVerifier.yulp --- packages/protocol/contracts/L1/verifiers/PlonkVerifier.yulp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/protocol/contracts/L1/verifiers/PlonkVerifier.yulp b/packages/protocol/contracts/L1/verifiers/PlonkVerifier.yulp index a34940f3f3a..53e1fe5f934 100644 --- a/packages/protocol/contracts/L1/verifiers/PlonkVerifier.yulp +++ b/packages/protocol/contracts/L1/verifiers/PlonkVerifier.yulp @@ -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) }