Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: backport non reentrant fixes #409

Merged
merged 1 commit into from
Oct 23, 2024
Merged
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
22 changes: 5 additions & 17 deletions v2/contracts/evm/GatewayEVM.sol
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,9 @@ contract GatewayEVM is
)
public
payable
nonReentrant
onlyRole(TSS_ROLE)
whenNotPaused
nonReentrant
{
if (destination == address(0)) revert ZeroAddress();
(bool success,) = destination.call{ value: msg.value }("");
Expand All @@ -144,9 +144,9 @@ contract GatewayEVM is
)
external
payable
nonReentrant
onlyRole(TSS_ROLE)
whenNotPaused
nonReentrant
returns (bytes memory)
{
if (destination == address(0)) revert ZeroAddress();
Expand All @@ -171,9 +171,9 @@ contract GatewayEVM is
bytes calldata data
)
public
nonReentrant
onlyRole(ASSET_HANDLER_ROLE)
whenNotPaused
nonReentrant
{
if (amount == 0) revert InsufficientERC20Amount();
if (to == address(0)) revert ZeroAddress();
Expand Down Expand Up @@ -210,9 +210,9 @@ contract GatewayEVM is
RevertContext calldata revertContext
)
external
nonReentrant
onlyRole(ASSET_HANDLER_ROLE)
whenNotPaused
nonReentrant
{
if (amount == 0) revert InsufficientERC20Amount();
if (to == address(0)) revert ZeroAddress();
Expand All @@ -226,15 +226,7 @@ contract GatewayEVM is
/// @notice Deposits ETH to the TSS address.
/// @param receiver Address of the receiver.
/// @param revertOptions Revert options.
function deposit(
address receiver,
RevertOptions calldata revertOptions
)
external
payable
whenNotPaused
nonReentrant
{
function deposit(address receiver, RevertOptions calldata revertOptions) external payable whenNotPaused {
if (revertOptions.callOnRevert) revert CallOnRevertNotSupported();
if (msg.value == 0) revert InsufficientETHAmount();
if (receiver == address(0)) revert ZeroAddress();
Expand All @@ -260,7 +252,6 @@ contract GatewayEVM is
)
external
whenNotPaused
nonReentrant
{
if (revertOptions.callOnRevert) revert CallOnRevertNotSupported();
if (amount == 0) revert InsufficientERC20Amount();
Expand All @@ -284,7 +275,6 @@ contract GatewayEVM is
external
payable
whenNotPaused
nonReentrant
{
if (revertOptions.callOnRevert) revert CallOnRevertNotSupported();
if (msg.value == 0) revert InsufficientETHAmount();
Expand Down Expand Up @@ -313,7 +303,6 @@ contract GatewayEVM is
)
external
whenNotPaused
nonReentrant
{
if (revertOptions.callOnRevert) revert CallOnRevertNotSupported();
if (amount == 0) revert InsufficientERC20Amount();
Expand All @@ -336,7 +325,6 @@ contract GatewayEVM is
)
external
whenNotPaused
nonReentrant
{
if (revertOptions.callOnRevert) revert CallOnRevertNotSupported();
if (receiver == address(0)) revert ZeroAddress();
Expand Down
19 changes: 13 additions & 6 deletions v2/contracts/zevm/GatewayZEVM.sol
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ contract GatewayZEVM is
RevertOptions calldata revertOptions
)
external
nonReentrant
whenNotPaused
{
if (revertOptions.callOnRevert) revert CallOnRevertNotSupported();
Expand Down Expand Up @@ -178,7 +177,6 @@ contract GatewayZEVM is
RevertOptions calldata revertOptions
)
external
nonReentrant
whenNotPaused
{
if (revertOptions.callOnRevert) revert CallOnRevertNotSupported();
Expand Down Expand Up @@ -213,7 +211,6 @@ contract GatewayZEVM is
RevertOptions calldata revertOptions
)
external
nonReentrant
whenNotPaused
{
revert ZETANotSupported();
Expand All @@ -240,7 +237,6 @@ contract GatewayZEVM is
RevertOptions calldata revertOptions
)
external
nonReentrant
whenNotPaused
{
revert ZETANotSupported();
Expand All @@ -267,7 +263,6 @@ contract GatewayZEVM is
RevertOptions calldata revertOptions
)
external
nonReentrant
whenNotPaused
{
if (revertOptions.callOnRevert) revert CallOnRevertNotSupported();
Expand Down Expand Up @@ -310,6 +305,7 @@ contract GatewayZEVM is
bytes calldata message
)
external
nonReentrant
onlyFungible
whenNotPaused
{
Expand All @@ -332,6 +328,7 @@ contract GatewayZEVM is
bytes calldata message
)
external
nonReentrant
onlyFungible
whenNotPaused
{
Expand All @@ -355,6 +352,7 @@ contract GatewayZEVM is
bytes calldata message
)
external
nonReentrant
onlyFungible
whenNotPaused
{
Expand All @@ -369,7 +367,15 @@ contract GatewayZEVM is
/// @notice Revert a user-specified contract on ZEVM.
/// @param target The target contract to call.
/// @param revertContext Revert context to pass to onRevert.
function executeRevert(address target, RevertContext calldata revertContext) external onlyFungible whenNotPaused {
function executeRevert(
address target,
RevertContext calldata revertContext
)
external
nonReentrant
onlyFungible
whenNotPaused
{
if (target == address(0)) revert ZeroAddress();

UniversalContract(target).onRevert(revertContext);
Expand All @@ -387,6 +393,7 @@ contract GatewayZEVM is
RevertContext calldata revertContext
)
external
nonReentrant
onlyFungible
whenNotPaused
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# INotSupportedMethods
[Git Source](https://github.com/zeta-chain/protocol-contracts/blob/aef054e72dc168bc0642efb673261c9477c170ae/contracts/Revert.sol)
[Git Source](https://github.com/zeta-chain/protocol-contracts/blob/03043003e2b510828e96289d740026d785c81bde/contracts/Revert.sol)


## Errors
Expand Down
2 changes: 1 addition & 1 deletion v2/docs/src/contracts/Revert.sol/interface.Revertable.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Revertable
[Git Source](https://github.com/zeta-chain/protocol-contracts/blob/aef054e72dc168bc0642efb673261c9477c170ae/contracts/Revert.sol)
[Git Source](https://github.com/zeta-chain/protocol-contracts/blob/03043003e2b510828e96289d740026d785c81bde/contracts/Revert.sol)

Interface for contracts that support revertable calls.

Expand Down
2 changes: 1 addition & 1 deletion v2/docs/src/contracts/Revert.sol/struct.RevertContext.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# RevertContext
[Git Source](https://github.com/zeta-chain/protocol-contracts/blob/aef054e72dc168bc0642efb673261c9477c170ae/contracts/Revert.sol)
[Git Source](https://github.com/zeta-chain/protocol-contracts/blob/03043003e2b510828e96289d740026d785c81bde/contracts/Revert.sol)

Struct containing revert context passed to onRevert.

Expand Down
2 changes: 1 addition & 1 deletion v2/docs/src/contracts/Revert.sol/struct.RevertOptions.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# RevertOptions
[Git Source](https://github.com/zeta-chain/protocol-contracts/blob/aef054e72dc168bc0642efb673261c9477c170ae/contracts/Revert.sol)
[Git Source](https://github.com/zeta-chain/protocol-contracts/blob/03043003e2b510828e96289d740026d785c81bde/contracts/Revert.sol)

Struct containing revert options

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# ERC20Custody
[Git Source](https://github.com/zeta-chain/protocol-contracts/blob/aef054e72dc168bc0642efb673261c9477c170ae/contracts/evm/ERC20Custody.sol)
[Git Source](https://github.com/zeta-chain/protocol-contracts/blob/03043003e2b510828e96289d740026d785c81bde/contracts/evm/ERC20Custody.sol)

**Inherits:**
Initializable, UUPSUpgradeable, [IERC20Custody](/contracts/evm/interfaces/IERC20Custody.sol/interface.IERC20Custody.md), ReentrancyGuardUpgradeable, AccessControlUpgradeable, PausableUpgradeable
Expand Down Expand Up @@ -264,9 +264,6 @@ function withdrawAndRevert(

Deposits asset to custody and pay fee in zeta erc20.

**Note:**
This method is deprecated.


```solidity
function deposit(
Expand Down
39 changes: 13 additions & 26 deletions v2/docs/src/contracts/evm/GatewayEVM.sol/contract.GatewayEVM.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# GatewayEVM
[Git Source](https://github.com/zeta-chain/protocol-contracts/blob/aef054e72dc168bc0642efb673261c9477c170ae/contracts/evm/GatewayEVM.sol)
[Git Source](https://github.com/zeta-chain/protocol-contracts/blob/03043003e2b510828e96289d740026d785c81bde/contracts/evm/GatewayEVM.sol)

**Inherits:**
Initializable, AccessControlUpgradeable, UUPSUpgradeable, [IGatewayEVM](/contracts/evm/interfaces/IGatewayEVM.sol/interface.IGatewayEVM.md), ReentrancyGuardUpgradeable, PausableUpgradeable, [INotSupportedMethods](/contracts/Revert.sol/interface.INotSupportedMethods.md)
Expand Down Expand Up @@ -85,9 +85,6 @@ uint256 public constant MAX_PAYLOAD_SIZE = 1024;
## Functions
### constructor

**Note:**
constructor


```solidity
constructor();
Expand Down Expand Up @@ -189,9 +186,9 @@ function executeRevert(
)
public
payable
nonReentrant
onlyRole(TSS_ROLE)
whenNotPaused
nonReentrant;
whenNotPaused;
```
**Parameters**

Expand All @@ -216,9 +213,9 @@ function execute(
)
external
payable
nonReentrant
onlyRole(TSS_ROLE)
whenNotPaused
nonReentrant
returns (bytes memory);
```
**Parameters**
Expand Down Expand Up @@ -251,9 +248,9 @@ function executeWithERC20(
bytes calldata data
)
public
nonReentrant
onlyRole(ASSET_HANDLER_ROLE)
whenNotPaused
nonReentrant;
whenNotPaused;
```
**Parameters**

Expand Down Expand Up @@ -281,9 +278,9 @@ function revertWithERC20(
RevertContext calldata revertContext
)
external
nonReentrant
onlyRole(ASSET_HANDLER_ROLE)
whenNotPaused
nonReentrant;
whenNotPaused;
```
**Parameters**

Expand All @@ -302,7 +299,7 @@ Deposits ETH to the TSS address.


```solidity
function deposit(address receiver, RevertOptions calldata revertOptions) external payable whenNotPaused nonReentrant;
function deposit(address receiver, RevertOptions calldata revertOptions) external payable whenNotPaused;
```
**Parameters**

Expand All @@ -325,8 +322,7 @@ function deposit(
RevertOptions calldata revertOptions
)
external
whenNotPaused
nonReentrant;
whenNotPaused;
```
**Parameters**

Expand All @@ -351,8 +347,7 @@ function depositAndCall(
)
external
payable
whenNotPaused
nonReentrant;
whenNotPaused;
```
**Parameters**

Expand All @@ -377,8 +372,7 @@ function depositAndCall(
RevertOptions calldata revertOptions
)
external
whenNotPaused
nonReentrant;
whenNotPaused;
```
**Parameters**

Expand All @@ -397,14 +391,7 @@ Calls an omnichain smart contract without asset transfer.


```solidity
function call(
address receiver,
bytes calldata payload,
RevertOptions calldata revertOptions
)
external
whenNotPaused
nonReentrant;
function call(address receiver, bytes calldata payload, RevertOptions calldata revertOptions) external whenNotPaused;
```
**Parameters**

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# ZetaConnectorBase
[Git Source](https://github.com/zeta-chain/protocol-contracts/blob/aef054e72dc168bc0642efb673261c9477c170ae/contracts/evm/ZetaConnectorBase.sol)
[Git Source](https://github.com/zeta-chain/protocol-contracts/blob/03043003e2b510828e96289d740026d785c81bde/contracts/evm/ZetaConnectorBase.sol)

**Inherits:**
Initializable, UUPSUpgradeable, [IZetaConnectorEvents](/contracts/evm/interfaces/IZetaConnector.sol/interface.IZetaConnectorEvents.md), ReentrancyGuardUpgradeable, PausableUpgradeable, AccessControlUpgradeable
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# ZetaConnectorNative
[Git Source](https://github.com/zeta-chain/protocol-contracts/blob/aef054e72dc168bc0642efb673261c9477c170ae/contracts/evm/ZetaConnectorNative.sol)
[Git Source](https://github.com/zeta-chain/protocol-contracts/blob/03043003e2b510828e96289d740026d785c81bde/contracts/evm/ZetaConnectorNative.sol)

**Inherits:**
[ZetaConnectorBase](/contracts/evm/ZetaConnectorBase.sol/abstract.ZetaConnectorBase.md)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# ZetaConnectorNonNative
[Git Source](https://github.com/zeta-chain/protocol-contracts/blob/aef054e72dc168bc0642efb673261c9477c170ae/contracts/evm/ZetaConnectorNonNative.sol)
[Git Source](https://github.com/zeta-chain/protocol-contracts/blob/03043003e2b510828e96289d740026d785c81bde/contracts/evm/ZetaConnectorNonNative.sol)

**Inherits:**
[ZetaConnectorBase](/contracts/evm/ZetaConnectorBase.sol/abstract.ZetaConnectorBase.md)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# IERC20Custody
[Git Source](https://github.com/zeta-chain/protocol-contracts/blob/aef054e72dc168bc0642efb673261c9477c170ae/contracts/evm/interfaces/IERC20Custody.sol)
[Git Source](https://github.com/zeta-chain/protocol-contracts/blob/03043003e2b510828e96289d740026d785c81bde/contracts/evm/interfaces/IERC20Custody.sol)

**Inherits:**
[IERC20CustodyEvents](/contracts/evm/interfaces/IERC20Custody.sol/interface.IERC20CustodyEvents.md), [IERC20CustodyErrors](/contracts/evm/interfaces/IERC20Custody.sol/interface.IERC20CustodyErrors.md)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# IERC20CustodyErrors
[Git Source](https://github.com/zeta-chain/protocol-contracts/blob/aef054e72dc168bc0642efb673261c9477c170ae/contracts/evm/interfaces/IERC20Custody.sol)
[Git Source](https://github.com/zeta-chain/protocol-contracts/blob/03043003e2b510828e96289d740026d785c81bde/contracts/evm/interfaces/IERC20Custody.sol)

Interface for the errors used in the ERC20 custody contract.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# IERC20CustodyEvents
[Git Source](https://github.com/zeta-chain/protocol-contracts/blob/aef054e72dc168bc0642efb673261c9477c170ae/contracts/evm/interfaces/IERC20Custody.sol)
[Git Source](https://github.com/zeta-chain/protocol-contracts/blob/03043003e2b510828e96289d740026d785c81bde/contracts/evm/interfaces/IERC20Custody.sol)

Interface for the events emitted by the ERC20 custody contract.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# IGatewayEVM
[Git Source](https://github.com/zeta-chain/protocol-contracts/blob/aef054e72dc168bc0642efb673261c9477c170ae/contracts/evm/interfaces/IGatewayEVM.sol)
[Git Source](https://github.com/zeta-chain/protocol-contracts/blob/03043003e2b510828e96289d740026d785c81bde/contracts/evm/interfaces/IGatewayEVM.sol)

**Inherits:**
[IGatewayEVMErrors](/contracts/evm/interfaces/IGatewayEVM.sol/interface.IGatewayEVMErrors.md), [IGatewayEVMEvents](/contracts/evm/interfaces/IGatewayEVM.sol/interface.IGatewayEVMEvents.md)
Expand Down
Loading
Loading