Skip to content

Commit

Permalink
[FEA-1063] remediate Slowmist audit suggestion [N4] (#69)
Browse files Browse the repository at this point in the history
  • Loading branch information
ungaro authored Oct 24, 2024
1 parent 591e0e6 commit d21f7b8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
10 changes: 6 additions & 4 deletions staking/src/RWAStaking.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ pragma solidity ^0.8.25;

import { AccessControlUpgradeable } from "@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol";
import { UUPSUpgradeable } from "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
import { ReentrancyGuardUpgradeable } from "@openzeppelin/contracts-upgradeable/utils/ReentrancyGuardUpgradeable.sol";
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";

Expand All @@ -11,7 +12,7 @@ import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.s
* @author Eugene Y. Q. Shen
* @notice Pre-staking contract for RWA Staking on Plume
*/
contract RWAStaking is AccessControlUpgradeable, UUPSUpgradeable {
contract RWAStaking is AccessControlUpgradeable, UUPSUpgradeable, ReentrancyGuardUpgradeable {

// Types

Expand Down Expand Up @@ -136,6 +137,7 @@ contract RWAStaking is AccessControlUpgradeable, UUPSUpgradeable {
) public initializer {
__AccessControl_init();
__UUPSUpgradeable_init();
__ReentrancyGuard_init();

_grantRole(DEFAULT_ADMIN_ROLE, owner);
_grantRole(ADMIN_ROLE, owner);
Expand Down Expand Up @@ -174,7 +176,7 @@ contract RWAStaking is AccessControlUpgradeable, UUPSUpgradeable {
* @notice Stop the RWAStaking contract by withdrawing all stablecoins
* @dev Only the admin can withdraw stablecoins from the RWAStaking contract
*/
function adminWithdraw() external onlyRole(ADMIN_ROLE) {
function adminWithdraw() external nonReentrant onlyRole(ADMIN_ROLE) {
RWAStakingStorage storage $ = _getRWAStakingStorage();
if ($.endTime != 0) {
revert StakingEnded();
Expand All @@ -198,7 +200,7 @@ contract RWAStaking is AccessControlUpgradeable, UUPSUpgradeable {
* @param amount Amount of stablecoins to stake
* @param stablecoin Stablecoin token contract address
*/
function stake(uint256 amount, IERC20 stablecoin) external {
function stake(uint256 amount, IERC20 stablecoin) external nonReentrant {
RWAStakingStorage storage $ = _getRWAStakingStorage();
if ($.endTime != 0) {
revert StakingEnded();
Expand Down Expand Up @@ -232,7 +234,7 @@ contract RWAStaking is AccessControlUpgradeable, UUPSUpgradeable {
* @param amount Amount of stablecoins to withdraw
* @param stablecoin Stablecoin token contract address
*/
function withdraw(uint256 amount, IERC20 stablecoin) external {
function withdraw(uint256 amount, IERC20 stablecoin) external nonReentrant {
RWAStakingStorage storage $ = _getRWAStakingStorage();
if ($.endTime != 0) {
revert StakingEnded();
Expand Down
11 changes: 7 additions & 4 deletions staking/src/ReserveStaking.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ pragma solidity ^0.8.25;

import { AccessControlUpgradeable } from "@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol";
import { UUPSUpgradeable } from "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";

import { ReentrancyGuardUpgradeable } from "@openzeppelin/contracts-upgradeable/utils/ReentrancyGuardUpgradeable.sol";
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";

Expand All @@ -11,7 +13,7 @@ import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.s
* @author Eugene Y. Q. Shen
* @notice Pre-staking contract into the Plume Mainnet Reserve Fund
*/
contract ReserveStaking is AccessControlUpgradeable, UUPSUpgradeable {
contract ReserveStaking is AccessControlUpgradeable, UUPSUpgradeable, ReentrancyGuardUpgradeable {

// Types

Expand Down Expand Up @@ -136,6 +138,7 @@ contract ReserveStaking is AccessControlUpgradeable, UUPSUpgradeable {
function initialize(address owner, IERC20 sbtc, IERC20 stone) public initializer {
__AccessControl_init();
__UUPSUpgradeable_init();
__ReentrancyGuard_init();

_grantRole(DEFAULT_ADMIN_ROLE, owner);
_grantRole(ADMIN_ROLE, owner);
Expand All @@ -161,7 +164,7 @@ contract ReserveStaking is AccessControlUpgradeable, UUPSUpgradeable {
* @notice Stop the ReserveStaking contract by withdrawing all SBTC and STONE
* @dev Only the admin can withdraw SBTC and STONE from the ReserveStaking contract
*/
function adminWithdraw() external onlyRole(ADMIN_ROLE) {
function adminWithdraw() external nonReentrant onlyRole(ADMIN_ROLE) {
ReserveStakingStorage storage $ = _getReserveStakingStorage();
if ($.endTime != 0) {
revert StakingEnded();
Expand All @@ -184,7 +187,7 @@ contract ReserveStaking is AccessControlUpgradeable, UUPSUpgradeable {
* @param sbtcAmount Amount of SBTC to stake
* @param stoneAmount Amount of STONE to stake
*/
function stake(uint256 sbtcAmount, uint256 stoneAmount) external {
function stake(uint256 sbtcAmount, uint256 stoneAmount) external nonReentrant {
ReserveStakingStorage storage $ = _getReserveStakingStorage();
if ($.endTime != 0) {
revert StakingEnded();
Expand Down Expand Up @@ -231,7 +234,7 @@ contract ReserveStaking is AccessControlUpgradeable, UUPSUpgradeable {
* @param sbtcAmount Amount of SBTC to withdraw
* @param stoneAmount Amount of STONE to withdraw
*/
function withdraw(uint256 sbtcAmount, uint256 stoneAmount) external {
function withdraw(uint256 sbtcAmount, uint256 stoneAmount) external nonReentrant {
ReserveStakingStorage storage $ = _getReserveStakingStorage();
if ($.endTime != 0) {
revert StakingEnded();
Expand Down

0 comments on commit d21f7b8

Please sign in to comment.