From 45a5bdffeac7f532aa15ffc04de76a9375045814 Mon Sep 17 00:00:00 2001 From: Qiang Zhu Date: Mon, 29 Jan 2024 19:11:14 +0800 Subject: [PATCH 1/5] using blobhash() --- contracts/EthStorageContract.sol | 30 +----------------------------- hardhat.config.js | 3 ++- 2 files changed, 3 insertions(+), 30 deletions(-) diff --git a/contracts/EthStorageContract.sol b/contracts/EthStorageContract.sol index 9411322..9863aa8 100644 --- a/contracts/EthStorageContract.sol +++ b/contracts/EthStorageContract.sol @@ -5,31 +5,6 @@ import "./StorageContract.sol"; import "./Decoder.sol"; import "./BinaryRelated.sol"; -contract BlobHashGetterFactory { - constructor() payable { - bytes memory code = hex"6000354960005260206000F3"; - uint256 size = code.length; - assembly { - return(add(code, 0x020), size) - } - } -} - -// TODO: remove the library if solidity has direct support the new opcode -library BlobHashGetter { - function getBlobHash(address getter, uint256 idx) internal view returns (bytes32) { - bool success; - bytes32 blobHash; - assembly { - mstore(0x0, idx) - success := staticcall(gas(), getter, 0x0, 0x20, 0x0, 0x20) - blobHash := mload(0x0) - } - require(success, "failed to get blob hash"); - return blobHash; - } -} - contract EthStorageContract is StorageContract, Decoder { uint256 constant modulusBls = 0x73eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001; uint256 constant ruBls = 0x564c0a11a0f704f4fc3e8acfe0f8245f0ad1347b378fbf96e206da11a5d36306; @@ -37,8 +12,6 @@ contract EthStorageContract is StorageContract, Decoder { uint256 constant modulusBn254 = 0x30644e72e131a029b85045b68181585d2833e84879b9709143e1f593f0000001; uint256 constant fieldElementsPerBlob = 0x1000; - address public hashGetter; - event PutBlob(uint256 indexed kvIdx, uint256 indexed kvSize, bytes32 indexed dataHash); function initialize( @@ -51,7 +24,6 @@ contract EthStorageContract is StorageContract, Decoder { uint256 _prepaidAmount ) public payable initializer { __init_storage(_config, _startTime, _storageCost, _dcfFactor, _nonceLimit, _treasury, _prepaidAmount); - hashGetter = address(new BlobHashGetterFactory()); } function modExp(uint256 _b, uint256 _e, uint256 _m) internal view returns (uint256 result) { @@ -205,7 +177,7 @@ contract EthStorageContract is StorageContract, Decoder { // Write a large value to KV store. If the KV pair exists, overrides it. Otherwise, will append the KV to the KV array. function putBlob(bytes32 key, uint256 blobIdx, uint256 length) public payable virtual { - bytes32 dataHash = BlobHashGetter.getBlobHash(hashGetter, blobIdx); + bytes32 dataHash = blobhash(blobIdx); uint256 kvIdx = _putInternal(key, dataHash, length); emit PutBlob(kvIdx, length, dataHash); diff --git a/hardhat.config.js b/hardhat.config.js index 2479a47..ceb4674 100644 --- a/hardhat.config.js +++ b/hardhat.config.js @@ -75,12 +75,13 @@ module.exports = { timeout: 120000, }, solidity: { - version: "0.8.20", + version: "0.8.24", settings: { optimizer: { enabled: true, runs: 200, }, + evmVersion: "cancun", }, }, }; From 576e619d8e2d0db337cfac716846ba12c3b7166c Mon Sep 17 00:00:00 2001 From: Qiang Zhu Date: Mon, 29 Jan 2024 19:24:42 +0800 Subject: [PATCH 2/5] workflow --- .github/workflows/ut.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ut.yml b/.github/workflows/ut.yml index 2bc629f..be31896 100644 --- a/.github/workflows/ut.yml +++ b/.github/workflows/ut.yml @@ -14,7 +14,7 @@ jobs: - name: Use Node.js uses: actions/setup-node@v3 with: - node-version: '18.x' - + node-version: "18.x" + - run: npm install - name: Test run: npm run test From 453f34159838ce12a3994a675817269242545c1f Mon Sep 17 00:00:00 2001 From: Qiang Zhu Date: Mon, 29 Jan 2024 19:32:47 +0800 Subject: [PATCH 3/5] workflow --- .github/workflows/ut.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ut.yml b/.github/workflows/ut.yml index be31896..0b70bff 100644 --- a/.github/workflows/ut.yml +++ b/.github/workflows/ut.yml @@ -15,6 +15,7 @@ jobs: uses: actions/setup-node@v3 with: node-version: "18.x" - - run: npm install + - name: Install + run: npm install - name: Test run: npm run test From 05bd3f93e674df3afff06e38b134244157e0b3d3 Mon Sep 17 00:00:00 2001 From: Qiang Zhu Date: Mon, 29 Jan 2024 19:34:12 +0800 Subject: [PATCH 4/5] workflow --- .github/workflows/ut.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/ut.yml b/.github/workflows/ut.yml index 0b70bff..6c1755f 100644 --- a/.github/workflows/ut.yml +++ b/.github/workflows/ut.yml @@ -15,7 +15,6 @@ jobs: uses: actions/setup-node@v3 with: node-version: "18.x" - - name: Install - run: npm install + - name: Test run: npm run test From f00af02356a764de24c5b7fcc24153bd91a4d20f Mon Sep 17 00:00:00 2001 From: Qiang Zhu Date: Mon, 29 Jan 2024 19:36:49 +0800 Subject: [PATCH 5/5] format --- .github/workflows/ut.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ut.yml b/.github/workflows/ut.yml index 6c1755f..2bc629f 100644 --- a/.github/workflows/ut.yml +++ b/.github/workflows/ut.yml @@ -14,7 +14,7 @@ jobs: - name: Use Node.js uses: actions/setup-node@v3 with: - node-version: "18.x" - + node-version: '18.x' + - name: Test run: npm run test