Skip to content

Commit

Permalink
fix comments
Browse files Browse the repository at this point in the history
  • Loading branch information
syntrust committed Oct 9, 2024
1 parent 1200a5a commit 6322c96
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
4 changes: 3 additions & 1 deletion contracts/DecentralizedKV.sol
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,9 @@ contract DecentralizedKV is OwnableUpgradeable {
}

_checkAppend(batchPaymentSize);
_checkUpdateLimit(_keys.length - batchPaymentSize);
if (_keys.length > batchPaymentSize) {
_checkUpdateLimit(_keys.length - batchPaymentSize);
}

return res;
}
Expand Down
7 changes: 5 additions & 2 deletions contracts/EthStorageContractL2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ interface IL1Block {
contract EthStorageContractL2 is EthStorageContract2 {
/// @notice The precompile contract address for L1Block.
IL1Block internal constant L1_BLOCK = IL1Block(0x4200000000000000000000000000000000000015);

/// @notice The mask to extract `blockLastUpdate`
uint256 internal constant MASK = ~uint256(0) ^ type(uint32).max;

/// @notice The rate limit to update blobs per block
uint256 internal immutable UPDATE_LIMIT;

Expand Down Expand Up @@ -67,8 +71,7 @@ contract EthStorageContractL2 is EthStorageContract2 {

/// @notice Check the update rate limit of blobs put.
function _checkUpdateLimit(uint256 _blobs) internal override {
uint256 blockLastUpdate = updateState >> 32;
uint256 blobsUpdated = blockLastUpdate == block.number ? updateState & type(uint32).max : 0;
uint256 blobsUpdated = updateState & MASK == block.number << 32 ? updateState & type(uint32).max : 0;
require(blobsUpdated + _blobs <= UPDATE_LIMIT, "EthStorageContractL2: exceeds update rate limit");
updateState = block.number << 32 | (blobsUpdated + _blobs);
}
Expand Down
2 changes: 1 addition & 1 deletion contracts/test/EthStorageContractL2Test.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ contract EthStorageContractL2Test is Test {
// No updates
storageContract.putBlobs(keys, blobIdxs, lengths);
assertEq(storageContract.getBlobsUpdated(), 0);
assertEq(storageContract.getBlockLastUpdate(), 10000);
assertEq(storageContract.getBlockLastUpdate(), 0);

// Append 1 new key-values, leaving 5 as updating
keys[0] = bytes32(uint256(10));
Expand Down

0 comments on commit 6322c96

Please sign in to comment.