Skip to content

Commit

Permalink
use openzeppelin
Browse files Browse the repository at this point in the history
  • Loading branch information
syntrust committed Sep 5, 2024
1 parent 56a883f commit 01c1e47
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 15 deletions.
16 changes: 3 additions & 13 deletions contracts/StorageContract.sol
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
import "./DecentralizedKV.sol";
import "./libraries/MiningLib.sol";
import "./libraries/RandaoLib.sol";

/// @custom:upgradeable
/// @title StorageContract
/// @notice EthStorage L1 Contract with Decentralized KV Interface and Proof of Storage Verification
abstract contract StorageContract is DecentralizedKV {
abstract contract StorageContract is DecentralizedKV, ReentrancyGuard {
/// @notice Represents the configuration of the storage contract.
/// @custom:field maxKvSizeBits Maximum size of a single key-value pair.
/// @custom:field shardSizeBits Storage shard size.
Expand Down Expand Up @@ -81,17 +82,6 @@ abstract contract StorageContract is DecentralizedKV {
/// @notice Prepaid timestamp of last mined
uint256 public prepaidLastMineTime;

/// @notice Locker to prevent from reentrancy
bool private locked;

/// @notice Prevent from reentrancy
modifier noReentrant() {
require(!locked, "StorageContract: No reentrancy allowed!");
locked = true;
_;
locked = false;
}

// TODO: Reserve extra slots (to a total of 50?) in the storage layout for future upgrades

/// @notice Emitted when a block is mined.
Expand Down Expand Up @@ -317,7 +307,7 @@ abstract contract StorageContract is DecentralizedKV {
bytes calldata _randaoProof,
bytes[] calldata _inclusiveProofs,
bytes[] calldata _decodeProof
) public virtual noReentrant {
) public virtual nonReentrant {
_mine(
_blockNum, _shardId, _miner, _nonce, _encodedSamples, _masks, _randaoProof, _inclusiveProofs, _decodeProof
);
Expand Down
4 changes: 2 additions & 2 deletions contracts/test/StorageContractTest.t.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.19;

import "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
import "./TestStorageContract.sol";
import "../StorageContract.sol";
import "forge-std/Test.sol";
Expand Down Expand Up @@ -81,7 +82,7 @@ contract StorageContractTest is Test {
bytes[] memory _inclusiveProofs = new bytes[](0);
bytes[] memory _decodeProof = new bytes[](0);

vm.expectRevert("StorageContract: No reentrancy allowed!");
vm.expectRevert(ReentrancyGuard.ReentrancyGuardReentrantCall.selector);
storageContract.mine(
_blockNum,
_shardId,
Expand Down Expand Up @@ -109,7 +110,6 @@ contract Attacker {
}

fallback() external payable {
vm.pauseGasMetering();
uint256 _shardId = 0;
uint256 _nonce = 0;
bytes32[] memory _encodedSamples = new bytes32[](0);
Expand Down

0 comments on commit 01c1e47

Please sign in to comment.