Skip to content

Commit

Permalink
receiver reentrancy checks
Browse files Browse the repository at this point in the history
  • Loading branch information
skosito committed Jul 23, 2024
1 parent d2826bf commit b3485b9
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
7 changes: 4 additions & 3 deletions contracts/prototypes/evm/ReceiverEVM.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ pragma solidity ^0.8.0;

import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
import "./IReceiverEVM.sol";

// @notice This contract is used just for testing
contract ReceiverEVM is IReceiverEVMEvents {
contract ReceiverEVM is IReceiverEVMEvents, ReentrancyGuard {
using SafeERC20 for IERC20;
error ZeroAmount();

Expand All @@ -21,15 +22,15 @@ contract ReceiverEVM is IReceiverEVMEvents {
}

// Function using IERC20
function receiveERC20(uint256 amount, address token, address destination) external {
function receiveERC20(uint256 amount, address token, address destination) external nonReentrant {
// Transfer tokens from the Gateway contract to the destination address
IERC20(token).safeTransferFrom(msg.sender, destination, amount);

emit ReceivedERC20(msg.sender, amount, token, destination);
}

// Function using IERC20 to partially transfer tokens
function receiveERC20Partial(uint256 amount, address token, address destination) external {
function receiveERC20Partial(uint256 amount, address token, address destination) external nonReentrant {
uint256 amountToSend = amount / 2;
if (amountToSend == 0) revert ZeroAmount();

Expand Down
Loading

0 comments on commit b3485b9

Please sign in to comment.