Skip to content

Commit

Permalink
Merge pull request #68 from ethstorage/blobhash
Browse files Browse the repository at this point in the history
Using blobhash()
  • Loading branch information
qizhou authored Jan 30, 2024
2 parents eedafc6 + f00af02 commit 456f185
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 30 deletions.
30 changes: 1 addition & 29 deletions contracts/EthStorageContract.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,40 +5,13 @@ 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;
uint256 constant ruBn254 = 0x931d596de2fd10f01ddd073fd5a90a976f169c76f039bb91c4775720042d43a;
uint256 constant modulusBn254 = 0x30644e72e131a029b85045b68181585d2833e84879b9709143e1f593f0000001;
uint256 constant fieldElementsPerBlob = 0x1000;

address public hashGetter;

event PutBlob(uint256 indexed kvIdx, uint256 indexed kvSize, bytes32 indexed dataHash);

function initialize(
Expand All @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion hardhat.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
},
};

0 comments on commit 456f185

Please sign in to comment.