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 6 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
15 changes: 13 additions & 2 deletions contracts/DecentralizedKV.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@ 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 Upfront storage cost (pre-dcf)
Expand Down Expand Up @@ -172,7 +174,15 @@ 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
// (4*31+3)*1024 - 4 is 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
require(
(paddr.kvSize >= _off + _len) && (_off + _len <= (4 * 31 + 3) * 1024 - 4),
iteyelmp marked this conversation as resolved.
Show resolved Hide resolved
iteyelmp marked this conversation as resolved.
Show resolved Hide resolved
"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 +192,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