Skip to content
Open
Show file tree
Hide file tree
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
40 changes: 20 additions & 20 deletions contracts/DecentralizedKV.sol
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.28;

import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import "./libraries/BinaryRelated.sol";
import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import {BinaryRelated} from "./libraries/BinaryRelated.sol";

/// @custom:upgradeable
/// @title DecentralizedKV
Expand Down Expand Up @@ -72,7 +72,7 @@ contract DecentralizedKV is Initializable {
}

/// @custom:storage-location erc7201:openzeppelin.storage.DecentralizedKV
struct DecentralizedKVStorage {
struct DecentralizedKvStorage {
/// @notice The number of entries in the store
uint40 _kvEntryCount;
/// @notice skey and PhyAddr mapping
Expand All @@ -82,12 +82,12 @@ contract DecentralizedKV is Initializable {
}

// keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.DecentralizedKV")) - 1)) & ~bytes32(uint256(0xff))
bytes32 private constant DecentralizedKVStorageLocation =
bytes32 private constant DECENTRALIZED_KV_STORAGE_LOCATION =
0xdddbcfdf01968304fa73e5ba952efaf0203fd233c51e4f58b8a185ceb1c2a300;

function _getDecentralizedKVStorage() private pure returns (DecentralizedKVStorage storage $) {
function _getDecentralizedKvStorage() private pure returns (DecentralizedKvStorage storage $) {
assembly {
$.slot := DecentralizedKVStorageLocation
$.slot := DECENTRALIZED_KV_STORAGE_LOCATION
}
}

Expand All @@ -106,8 +106,8 @@ contract DecentralizedKV is Initializable {
}

/// @notice Initializer.
function __init_KV() internal onlyInitializing {
DecentralizedKVStorage storage $ = _getDecentralizedKVStorage();
function _initKv() internal onlyInitializing {
DecentralizedKvStorage storage $ = _getDecentralizedKvStorage();
$._kvEntryCount = 0;
}

Expand Down Expand Up @@ -167,7 +167,7 @@ contract DecentralizedKV is Initializable {
}
}

DecentralizedKVStorage storage $ = _getDecentralizedKVStorage();
DecentralizedKvStorage storage $ = _getDecentralizedKvStorage();

uint256[] memory res = new uint256[](keysLength);
uint256 batchPaymentSize = 0;
Expand Down Expand Up @@ -202,21 +202,21 @@ contract DecentralizedKV is Initializable {
/// @notice Return the size of the keyed value.
function size(bytes32 _key) public view returns (uint256) {
bytes32 skey = keccak256(abi.encode(msg.sender, _key));
DecentralizedKVStorage storage $ = _getDecentralizedKVStorage();
DecentralizedKvStorage storage $ = _getDecentralizedKvStorage();
return $._kvMap[skey].kvSize;
}

/// @notice Return the dataHash of the keyed value.
function hash(bytes32 _key) public view returns (bytes24) {
bytes32 skey = keccak256(abi.encode(msg.sender, _key));
DecentralizedKVStorage storage $ = _getDecentralizedKVStorage();
DecentralizedKvStorage storage $ = _getDecentralizedKvStorage();
return $._kvMap[skey].hash;
}

/// @notice Check if the key-value exists.
function exist(bytes32 _key) public view returns (bool) {
bytes32 skey = keccak256(abi.encode(msg.sender, _key));
DecentralizedKVStorage storage $ = _getDecentralizedKVStorage();
DecentralizedKvStorage storage $ = _getDecentralizedKvStorage();
return $._kvMap[skey].hash != 0;
}

Expand All @@ -237,7 +237,7 @@ contract DecentralizedKV is Initializable {
}

bytes32 skey = keccak256(abi.encode(msg.sender, _key));
DecentralizedKVStorage storage $ = _getDecentralizedKVStorage();
DecentralizedKvStorage storage $ = _getDecentralizedKvStorage();
PhyAddr memory paddr = $._kvMap[skey];

if (paddr.hash == 0) {
Expand Down Expand Up @@ -298,7 +298,7 @@ contract DecentralizedKV is Initializable {
uint256 kvIndicesLength = _kvIndices.length;

bytes32[] memory res = new bytes32[](kvIndicesLength);
DecentralizedKVStorage storage $ = _getDecentralizedKVStorage();
DecentralizedKvStorage storage $ = _getDecentralizedKvStorage();
for (uint256 i = 0; i < kvIndicesLength; i++) {
PhyAddr memory paddr = $._kvMap[$._idxMap[_kvIndices[i]]];

Expand All @@ -311,37 +311,37 @@ contract DecentralizedKV is Initializable {

/// @notice Getter for kvEntryCount
function kvEntryCount() public view returns (uint40) {
DecentralizedKVStorage storage $ = _getDecentralizedKVStorage();
DecentralizedKvStorage storage $ = _getDecentralizedKvStorage();
return $._kvEntryCount;
}

/// @notice Setter for kvEntryCount
function _setKvEntryCount(uint40 _value) internal {
DecentralizedKVStorage storage $ = _getDecentralizedKVStorage();
DecentralizedKvStorage storage $ = _getDecentralizedKvStorage();
$._kvEntryCount = _value;
}

/// @notice Getter for kvMap
function _kvMap(bytes32 _key) internal view returns (PhyAddr memory) {
DecentralizedKVStorage storage $ = _getDecentralizedKVStorage();
DecentralizedKvStorage storage $ = _getDecentralizedKvStorage();
return $._kvMap[_key];
}

/// @notice Setter for kvMap
function _setKvMap(bytes32 _key, PhyAddr memory _value) internal {
DecentralizedKVStorage storage $ = _getDecentralizedKVStorage();
DecentralizedKvStorage storage $ = _getDecentralizedKvStorage();
$._kvMap[_key] = _value;
}

/// @notice Getter for idxMap
function _idxMap(uint256 _kvIdx) internal view returns (bytes32) {
DecentralizedKVStorage storage $ = _getDecentralizedKVStorage();
DecentralizedKvStorage storage $ = _getDecentralizedKvStorage();
return $._idxMap[_kvIdx];
}

/// @notice Setter for idxMap
function _setIdxMap(uint256 _kvIdx, bytes32 _value) internal {
DecentralizedKVStorage storage $ = _getDecentralizedKVStorage();
DecentralizedKvStorage storage $ = _getDecentralizedKvStorage();
$._idxMap[_kvIdx] = _value;
}

Expand Down
11 changes: 6 additions & 5 deletions contracts/EthStorageContract.sol
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.28;

import "./StorageContract.sol";
import "./libraries//BinaryRelated.sol";
import "./Interfaces/ISemver.sol";
import {StorageContract} from "./StorageContract.sol";
import {BinaryRelated} from "./libraries/BinaryRelated.sol";
import {ISemver} from "./Interfaces/ISemver.sol";

/// @custom:proxied
/// @title EthStorageContract
Expand Down Expand Up @@ -31,7 +31,8 @@ abstract contract EthStorageContract is StorageContract, ISemver {
uint256 internal constant FIELD_ELEMENTS_PER_BLOB = 0x1000;

/// @notice Semantic version.
/// @custom:semver 0.2.0
/// @custom:semver 0.2.1
///forge-lint: disable-next-line(screaming-snake-case-const)
string public constant version = "0.2.1";

/// @notice Emitted when a BLOB is appended.
Expand All @@ -56,7 +57,7 @@ abstract contract EthStorageContract is StorageContract, ISemver {
address _treasury,
address _owner
) public payable virtual initializer {
__init_storage(_minimumDiff, _prepaidAmount, _nonceLimit, _treasury, _owner);
_initStorage(_minimumDiff, _prepaidAmount, _nonceLimit, _treasury, _owner);
}

/// @notice Performs modular exponentiation, which is a type of exponentiation performed over a modulus.
Expand Down
5 changes: 3 additions & 2 deletions contracts/EthStorageContractM1.sol
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.28;

import "./EthStorageContract.sol";
import "./zk-verify/Decoder.sol";
import {EthStorageContract} from "./EthStorageContract.sol";
import {StorageContract} from "./StorageContract.sol";
import {Decoder} from "./zk-verify/Decoder.sol";

/// @custom:proxied
/// @title EthStorageContractM1
Expand Down
7 changes: 5 additions & 2 deletions contracts/EthStorageContractM1L2.sol
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.28;

import "./EthStorageContractM1.sol";
import "./L2Base.sol";
import {MiningLib} from "./libraries/MiningLib.sol";
import {EthStorageContractM1} from "./EthStorageContractM1.sol";
import {L2Base, ISoulGasToken} from "./L2Base.sol";
import {DecentralizedKV} from "./DecentralizedKV.sol";
import {StorageContract} from "./StorageContract.sol";

/// @custom:proxied
/// @title EthStorageContractM1L2
Expand Down
5 changes: 3 additions & 2 deletions contracts/EthStorageContractM2.sol
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.28;

import "./EthStorageContract.sol";
import "./zk-verify/Decoder2.sol";
import {StorageContract} from "./StorageContract.sol";
import {EthStorageContract} from "./EthStorageContract.sol";
import {Decoder2} from "./zk-verify/Decoder2.sol";

/// @custom:proxied
/// @title EthStorageContractM2
Expand Down
7 changes: 5 additions & 2 deletions contracts/EthStorageContractM2L2.sol
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.28;

import "./EthStorageContractM2.sol";
import "./L2Base.sol";
import {EthStorageContractM2} from "./EthStorageContractM2.sol";
import {L2Base, ISoulGasToken} from "./L2Base.sol";
import {DecentralizedKV} from "./DecentralizedKV.sol";
import {StorageContract} from "./StorageContract.sol";
import {MiningLib} from "./libraries/MiningLib.sol";

/// @custom:proxied
/// @title EthStorageContractM2L2
Expand Down
7 changes: 4 additions & 3 deletions contracts/L2Base.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.28;

import "./libraries/RandaoLib.sol";
import {RandaoLib} from "./libraries/RandaoLib.sol";

/// @title IL1Block
/// @notice Interface for L1Block contract.
Expand Down Expand Up @@ -55,11 +55,12 @@ abstract contract L2Base {
}

// keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.L2Base")) - 1)) & ~bytes32(uint256(0xff))
bytes32 private constant L2BaseStorageLocation = 0x4f2e75529ec26b25c2fdfe7928382000d9e4289cb7792c1db94ef3c9ffecd900;
bytes32 private constant L2_BASE_STORAGE_LOCATION =
0x4f2e75529ec26b25c2fdfe7928382000d9e4289cb7792c1db94ef3c9ffecd900;

function _getL2BaseStorage() private pure returns (L2BaseStorage storage $) {
assembly {
$.slot := L2BaseStorageLocation
$.slot := L2_BASE_STORAGE_LOCATION
}
}

Expand Down
17 changes: 8 additions & 9 deletions contracts/StorageContract.sol
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.28;

import "@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol";

import "./DecentralizedKV.sol";
import "./libraries/MiningLib.sol";
import "./libraries/RandaoLib.sol";
import {AccessControlUpgradeable} from "@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol";
import {DecentralizedKV} from "./DecentralizedKV.sol";
import {MiningLib} from "./libraries/MiningLib.sol";
import {RandaoLib} from "./libraries/RandaoLib.sol";

/// @custom:upgradeable
/// @title StorageContract
Expand Down Expand Up @@ -131,12 +130,12 @@ abstract contract StorageContract is DecentralizedKV, AccessControlUpgradeable {
}

// keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.StorageContract")) - 1)) & ~bytes32(uint256(0xff))
bytes32 private constant StorageContractStorageLocation =
bytes32 private constant STORAGE_CONTRACT_STORAGE_LOCATION =
0x2e87afa02c4126794624df6162c63cb642521b7bea4fc2331190b8ab7e6a0f00;

function _getStorageContractStorage() private pure returns (StorageContractStorage storage $) {
assembly {
$.slot := StorageContractStorageLocation
$.slot := STORAGE_CONTRACT_STORAGE_LOCATION
}
}

Expand Down Expand Up @@ -204,7 +203,7 @@ abstract contract StorageContract is DecentralizedKV, AccessControlUpgradeable {
/// @param _nonceLimit The maximum nonce per block.
/// @param _treasury The treasury address.
/// @param _owner The contract owner.
function __init_storage(
function _initStorage(
uint256 _minimumDiff,
uint256 _prepaidAmount,
uint256 _nonceLimit,
Expand All @@ -214,7 +213,7 @@ abstract contract StorageContract is DecentralizedKV, AccessControlUpgradeable {
__AccessControl_init();
_grantRole(DEFAULT_ADMIN_ROLE, _owner);

__init_KV();
_initKv();

StorageContractStorage storage $ = _getStorageContractStorage();
$._minimumDiff = _minimumDiff;
Expand Down
2 changes: 1 addition & 1 deletion contracts/libraries/MerkleLib.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.28;

import "./BinaryRelated.sol";
import {BinaryRelated} from "./BinaryRelated.sol";

library MerkleLib {
// Calculate the Merkle root of a given data with chunk size and number of maximum chunks in the data limit.
Expand Down
2 changes: 2 additions & 0 deletions contracts/libraries/RLPReader.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
*/
pragma solidity 0.8.28;

///forge-lint: disable-next-item(pascal-case-struct)

library RLPReader {
uint8 constant STRING_SHORT_START = 0x80;
uint8 constant STRING_LONG_START = 0xb8;
Expand Down
2 changes: 1 addition & 1 deletion contracts/libraries/RandaoLib.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.28;

import "./RLPReader.sol";
import {RLPReader} from "./RLPReader.sol";

/// @title RandaoLib
/// @notice Handles Randao related operations
Expand Down
10 changes: 5 additions & 5 deletions contracts/test/DecentralizedKVTest.t.sol
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.28;

import "./TestDecentralizedKV.sol";
import "forge-std/Test.sol";
import {TestDecentralizedKV} from "./TestDecentralizedKV.sol";
import {Test} from "forge-std/Test.sol";

contract DecentralizedKVTest is Test {
uint256 constant MAX_KV_SIZE = 17;
uint256 constant STORAGE_COST = 10000000;
uint256 constant SHARD_SIZE_BITS = 19;
uint256 constant PREPAID_AMOUNT = 2 * STORAGE_COST;
TestDecentralizedKV decentralizedKV;
TestDecentralizedKV decentralizedKv;

function setUp() public {
decentralizedKV = new TestDecentralizedKV(MAX_KV_SIZE, 0, STORAGE_COST, 340282366367469178095360967382638002176);
decentralizedKV.initialize();
decentralizedKv = new TestDecentralizedKV(MAX_KV_SIZE, 0, STORAGE_COST, 340282366367469178095360967382638002176);
decentralizedKv.initialize();
}
}
9 changes: 6 additions & 3 deletions contracts/test/EthStorageContractL2Test.t.sol
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.28;

import "forge-std/Test.sol";
import "./TestEthStorageContractM2L2.sol";
import "openzeppelin-foundry-upgrades/Upgrades.sol";
import {Test} from "forge-std/Test.sol";
import {StorageContract} from "../StorageContract.sol";
import {L2Base} from "../L2Base.sol";
import {TestEthStorageContractM2L2} from "./TestEthStorageContractM2L2.sol";
import {EthStorageContractM2L2} from "../EthStorageContractM2L2.sol";
import {Upgrades, Options, TransparentUpgradeableProxy} from "openzeppelin-foundry-upgrades/Upgrades.sol";

contract SoulGasToken {
function chargeFromOrigin(uint256 _amount) external pure returns (uint256) {
Expand Down
7 changes: 4 additions & 3 deletions contracts/test/EthStorageContractM1Test.t.sol
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.28;

import "./TestEthStorageContractM1.sol";
import "forge-std/Test.sol";
import "openzeppelin-foundry-upgrades/Upgrades.sol";
import {TestEthStorageContractM1} from "./TestEthStorageContractM1.sol";
import {Test} from "forge-std/Test.sol";
import {Upgrades, Options} from "openzeppelin-foundry-upgrades/Upgrades.sol";
import {StorageContract} from "../StorageContract.sol";

contract EthStorageContractM1Test is Test {
uint256 constant STORAGE_COST = 1000;
Expand Down
6 changes: 3 additions & 3 deletions contracts/test/StorageContractTest.t.sol
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.28;

import "./TestStorageContract.sol";
import "../StorageContract.sol";
import "forge-std/Test.sol";
import {TestStorageContract} from "./TestStorageContract.sol";
import {StorageContract} from "../StorageContract.sol";
import {Test} from "forge-std/Test.sol";

contract StorageContractTest is Test {
uint256 constant STORAGE_COST = 10000000;
Expand Down
Loading