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

support op blob decode #76

Merged
merged 8 commits into from
Jul 11, 2024
Merged
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
17 changes: 15 additions & 2 deletions contracts/DecentralizedKV.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,17 @@ contract DecentralizedKV is OwnableUpgradeable {
/// @notice Enum representing different decoding types when getting key-value.
/// @custom:field RawData Don't do any decoding.
/// @custom:field PaddingPer31Bytes Will remove the padding byte every 31 bytes.
/// @custom:field OptimismCompact Use Op blob encoding format.
enum DecodeType {
RawData,
PaddingPer31Bytes
PaddingPer31Bytes,
OptimismCompact
}

/// @notice The maximum value of optimization blob storage content. It can store 3068 bytes more data than standard blob.
/// https://github.com/ethereum-optimism/optimism/blob/develop/op-service/eth/blob.go#L16
uint256 internal constant MAX_OPTIMISM_BLOB_DATA_SIZE = (4 * 31 + 3) * 1024 - 4;

/// @notice Upfront storage cost (pre-dcf)
uint256 internal immutable STORAGE_COST;

Expand Down Expand Up @@ -172,7 +178,13 @@ contract DecentralizedKV is OwnableUpgradeable {
bytes32 skey = keccak256(abi.encode(msg.sender, _key));
PhyAddr memory paddr = kvMap[skey];
require(paddr.hash != 0, "DecentralizedKV: data not exist");
if (_decodeType == DecodeType.PaddingPer31Bytes) {
if (_decodeType == DecodeType.OptimismCompact) {
// kvSize is the actual data size that dApp contract stores
require(
(paddr.kvSize >= _off + _len) && (_off + _len <= MAX_OPTIMISM_BLOB_DATA_SIZE),
"DecentralizedKV: beyond the range of kvSize"
);
} else if (_decodeType == DecodeType.PaddingPer31Bytes) {
// kvSize is the actual data size that dApp contract stores
require(
(paddr.kvSize >= _off + _len) && (_off + _len <= MAX_KV_SIZE - 4096),
Expand All @@ -182,6 +194,7 @@ contract DecentralizedKV is OwnableUpgradeable {
// maxKvSize is blob size
require(MAX_KV_SIZE >= _off + _len, "DecentralizedKV: beyond the range of maxKvSize");
}

bytes memory input = abi.encode(paddr.kvIdx, _decodeType, _off, _len, paddr.hash);
bytes memory output = new bytes(_len);

Expand Down
Loading