From 8a405c9fc39f986b1396efed98385840094e474b Mon Sep 17 00:00:00 2001 From: syntrust Date: Thu, 31 Aug 2023 10:57:09 +0800 Subject: [PATCH 1/3] precompile rename --- contracts/EthStorageContract.sol | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/contracts/EthStorageContract.sol b/contracts/EthStorageContract.sol index 3907ca9..b250e33 100644 --- a/contracts/EthStorageContract.sol +++ b/contracts/EthStorageContract.sol @@ -51,8 +51,8 @@ contract EthStorageContract is StorageContract, Decoder { x := mload(add(input, 0x40)) y := mload(add(input, 0x60)) - // Call the precompiled contract 0x14 = point evaluation, reuse scratch to get the results - if iszero(staticcall(not(0), 0x14, add(input, 0x20), 0xc0, 0x0, 0x40)) { + // Call the precompiled contract 0x0a = point evaluation, reuse scratch to get the results + if iszero(staticcall(not(0), 0x0a, add(input, 0x20), 0xc0, 0x0, 0x40)) { revert(0, 0) } From 6342f247b1e76c69c0a4a46b5352b84c3105a9c6 Mon Sep 17 00:00:00 2001 From: syntrust Date: Thu, 31 Aug 2023 16:24:10 +0800 Subject: [PATCH 2/3] check return value of pe precompile --- contracts/EthStorageContract.sol | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/contracts/EthStorageContract.sol b/contracts/EthStorageContract.sol index b250e33..1a064ec 100644 --- a/contracts/EthStorageContract.sol +++ b/contracts/EthStorageContract.sol @@ -6,6 +6,12 @@ import "./Decoder.sol"; import "./BinaryRelated.sol"; contract EthStorageContract is StorageContract, Decoder { + uint256 public constant modulusBls = 0x73eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001; + uint256 public constant ruBls = 0x564c0a11a0f704f4fc3e8acfe0f8245f0ad1347b378fbf96e206da11a5d36306; + uint256 constant ruBn254 = 0x931d596de2fd10f01ddd073fd5a90a976f169c76f039bb91c4775720042d43a; + uint256 constant modulusBn254 = 0x30644e72e131a029b85045b68181585d2833e84879b9709143e1f593f0000001; + uint256 constant fieldElementsPerBlob = 0x1000; + event PutBlob(uint256 indexed kvIdx, uint256 indexed kvSize, bytes32 indexed dataHash); constructor( @@ -55,8 +61,13 @@ contract EthStorageContract is StorageContract, Decoder { if iszero(staticcall(not(0), 0x0a, add(input, 0x20), 0xc0, 0x0, 0x40)) { revert(0, 0) } - - // TODO: Check the results + // Check the results + if iszero(eq(mload(0x0), fieldElementsPerBlob)) { + revert(0, 0) + } + if iszero(eq(mload(0x20), modulusBls)) { + revert(0, 0) + } } } @@ -66,8 +77,6 @@ contract EthStorageContract is StorageContract, Decoder { uint256 sampleIdxInKv, uint256 mask ) public view returns (bool) { - uint256 ruBn254 = 0x931d596de2fd10f01ddd073fd5a90a976f169c76f039bb91c4775720042d43a; - uint256 modulusBn254 = 0x30644e72e131a029b85045b68181585d2833e84879b9709143e1f593f0000001; uint256 xBn254 = modExp(ruBn254, sampleIdxInKv, modulusBn254); uint256[] memory input = new uint256[](3); @@ -84,8 +93,6 @@ contract EthStorageContract is StorageContract, Decoder { uint256 decodedData, bytes memory peInput ) public view returns (bool) { - uint256 ruBls = 0x564c0a11a0f704f4fc3e8acfe0f8245f0ad1347b378fbf96e206da11a5d36306; - uint256 modulusBls = 0x73eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001; // peInput includes an input point that comes from bit reversed sampleIdxInKv uint256 sampleIdxInKvRev = BinaryRelated.reverseBits(12, sampleIdxInKv); uint256 xBls = modExp(ruBls, sampleIdxInKvRev, modulusBls); From 6f7e0fdd74c0b8874d4cdb3d4c8a05c07a27f677 Mon Sep 17 00:00:00 2001 From: syntrust Date: Thu, 31 Aug 2023 16:31:34 +0800 Subject: [PATCH 3/3] minor --- contracts/EthStorageContract.sol | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/contracts/EthStorageContract.sol b/contracts/EthStorageContract.sol index 1a064ec..14a3c2f 100644 --- a/contracts/EthStorageContract.sol +++ b/contracts/EthStorageContract.sol @@ -6,8 +6,8 @@ import "./Decoder.sol"; import "./BinaryRelated.sol"; contract EthStorageContract is StorageContract, Decoder { - uint256 public constant modulusBls = 0x73eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001; - uint256 public constant ruBls = 0x564c0a11a0f704f4fc3e8acfe0f8245f0ad1347b378fbf96e206da11a5d36306; + uint256 constant modulusBls = 0x73eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001; + uint256 constant ruBls = 0x564c0a11a0f704f4fc3e8acfe0f8245f0ad1347b378fbf96e206da11a5d36306; uint256 constant ruBn254 = 0x931d596de2fd10f01ddd073fd5a90a976f169c76f039bb91c4775720042d43a; uint256 constant modulusBn254 = 0x30644e72e131a029b85045b68181585d2833e84879b9709143e1f593f0000001; uint256 constant fieldElementsPerBlob = 0x1000;