Skip to content

Commit

Permalink
fix: use nonReentrant only on functions interacting with arbitrary co…
Browse files Browse the repository at this point in the history
…ntracts (#395)
  • Loading branch information
skosito authored Oct 23, 2024
1 parent d40d2e2 commit 25a6e0b
Show file tree
Hide file tree
Showing 17 changed files with 56 additions and 64 deletions.
22 changes: 5 additions & 17 deletions v2/contracts/evm/GatewayEVM.sol
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,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 @@ -135,9 +135,9 @@ contract GatewayEVM is
)
external
payable
nonReentrant
onlyRole(TSS_ROLE)
whenNotPaused
nonReentrant
returns (bytes memory)
{
if (destination == address(0)) revert ZeroAddress();
Expand Down Expand Up @@ -172,9 +172,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 @@ -217,9 +217,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 @@ -233,15 +233,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 (msg.value == 0) revert InsufficientETHAmount();
if (receiver == address(0)) revert ZeroAddress();
if (revertOptions.revertMessage.length > MAX_PAYLOAD_SIZE) revert PayloadSizeExceeded();
Expand All @@ -266,7 +258,6 @@ contract GatewayEVM is
)
external
whenNotPaused
nonReentrant
{
if (amount == 0) revert InsufficientERC20Amount();
if (receiver == address(0)) revert ZeroAddress();
Expand All @@ -289,7 +280,6 @@ contract GatewayEVM is
external
payable
whenNotPaused
nonReentrant
{
if (msg.value == 0) revert InsufficientETHAmount();
if (receiver == address(0)) revert ZeroAddress();
Expand Down Expand Up @@ -317,7 +307,6 @@ contract GatewayEVM is
)
external
whenNotPaused
nonReentrant
{
if (amount == 0) revert InsufficientERC20Amount();
if (receiver == address(0)) revert ZeroAddress();
Expand All @@ -339,7 +328,6 @@ contract GatewayEVM is
)
external
whenNotPaused
nonReentrant
{
if (receiver == address(0)) revert ZeroAddress();
if (payload.length + revertOptions.revertMessage.length > MAX_PAYLOAD_SIZE) revert PayloadSizeExceeded();
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 @@ -140,7 +140,6 @@ contract GatewayZEVM is
RevertOptions calldata revertOptions
)
external
nonReentrant
whenNotPaused
{
if (receiver.length == 0) revert ZeroAddress();
Expand Down Expand Up @@ -178,7 +177,6 @@ contract GatewayZEVM is
RevertOptions calldata revertOptions
)
external
nonReentrant
whenNotPaused
{
if (receiver.length == 0) revert ZeroAddress();
Expand Down Expand Up @@ -212,7 +210,6 @@ contract GatewayZEVM is
RevertOptions calldata /*revertOptions*/
)
external
nonReentrant
whenNotPaused
{
// TODO: remove error and comment out code once ZETA supported back
Expand Down Expand Up @@ -255,7 +252,6 @@ contract GatewayZEVM is
RevertOptions calldata /*revertOptions*/
)
external
nonReentrant
whenNotPaused
{
// TODO: remove error and comment out code once ZETA supported back
Expand Down Expand Up @@ -288,7 +284,6 @@ contract GatewayZEVM is
RevertOptions calldata revertOptions
)
external
nonReentrant
whenNotPaused
{
if (callOptions.gasLimit == 0) revert InsufficientGasLimit();
Expand Down Expand Up @@ -343,6 +338,7 @@ contract GatewayZEVM is
bytes calldata message
)
external
nonReentrant
onlyProtocol
whenNotPaused
{
Expand All @@ -365,6 +361,7 @@ contract GatewayZEVM is
bytes calldata message
)
external
nonReentrant
onlyProtocol
whenNotPaused
{
Expand All @@ -388,6 +385,7 @@ contract GatewayZEVM is
bytes calldata message
)
external
nonReentrant
onlyProtocol
whenNotPaused
{
Expand All @@ -402,7 +400,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 onlyProtocol whenNotPaused {
function executeRevert(
address target,
RevertContext calldata revertContext
)
external
nonReentrant
onlyProtocol
whenNotPaused
{
if (target == address(0)) revert ZeroAddress();

Revertable(target).onRevert(revertContext);
Expand All @@ -420,6 +426,7 @@ contract GatewayZEVM is
RevertContext calldata revertContext
)
external
nonReentrant
onlyProtocol
whenNotPaused
{
Expand Down
34 changes: 12 additions & 22 deletions v2/docs/src/contracts/evm/GatewayEVM.sol/contract.GatewayEVM.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,9 @@ function executeRevert(
)
public
payable
nonReentrant
onlyRole(TSS_ROLE)
whenNotPaused
nonReentrant;
whenNotPaused;
```
**Parameters**

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

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

Expand All @@ -281,7 +281,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 @@ -304,8 +304,7 @@ function deposit(
RevertOptions calldata revertOptions
)
external
whenNotPaused
nonReentrant;
whenNotPaused;
```
**Parameters**

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

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

Expand All @@ -376,14 +373,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
19 changes: 13 additions & 6 deletions v2/docs/src/contracts/zevm/GatewayZEVM.sol/contract.GatewayZEVM.md
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,6 @@ function withdraw(
RevertOptions calldata revertOptions
)
external
nonReentrant
whenNotPaused;
```
**Parameters**
Expand Down Expand Up @@ -218,7 +217,6 @@ function withdrawAndCall(
RevertOptions calldata revertOptions
)
external
nonReentrant
whenNotPaused;
```
**Parameters**
Expand All @@ -239,7 +237,7 @@ Withdraw ZETA tokens to an external chain.


```solidity
function withdraw(bytes memory, uint256, uint256, RevertOptions calldata) external nonReentrant whenNotPaused;
function withdraw(bytes memory, uint256, uint256, RevertOptions calldata) external whenNotPaused;
```

### withdrawAndCall
Expand All @@ -257,7 +255,6 @@ function withdrawAndCall(
RevertOptions calldata
)
external
nonReentrant
whenNotPaused;
```

Expand All @@ -275,7 +272,6 @@ function call(
RevertOptions calldata revertOptions
)
external
nonReentrant
whenNotPaused;
```
**Parameters**
Expand Down Expand Up @@ -334,6 +330,7 @@ function execute(
bytes calldata message
)
external
nonReentrant
onlyProtocol
whenNotPaused;
```
Expand Down Expand Up @@ -362,6 +359,7 @@ function depositAndCall(
bytes calldata message
)
external
nonReentrant
onlyProtocol
whenNotPaused;
```
Expand Down Expand Up @@ -389,6 +387,7 @@ function depositAndCall(
bytes calldata message
)
external
nonReentrant
onlyProtocol
whenNotPaused;
```
Expand All @@ -408,7 +407,14 @@ Revert a user-specified contract on ZEVM.


```solidity
function executeRevert(address target, RevertContext calldata revertContext) external onlyProtocol whenNotPaused;
function executeRevert(
address target,
RevertContext calldata revertContext
)
external
nonReentrant
onlyProtocol
whenNotPaused;
```
**Parameters**

Expand All @@ -431,6 +437,7 @@ function depositAndRevert(
RevertContext calldata revertContext
)
external
nonReentrant
onlyProtocol
whenNotPaused;
```
Expand Down
2 changes: 1 addition & 1 deletion v2/pkg/erc20custody.t.sol/erc20custodytest.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion v2/pkg/gatewayevm.sol/gatewayevm.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion v2/pkg/gatewayevm.t.sol/gatewayevminboundtest.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion v2/pkg/gatewayevm.t.sol/gatewayevmtest.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion v2/pkg/gatewayevmzevm.t.sol/gatewayevmzevmtest.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion v2/pkg/gatewayzevm.sol/gatewayzevm.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion v2/pkg/gatewayzevm.t.sol/gatewayzevminboundtest.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion v2/pkg/gatewayzevm.t.sol/gatewayzevmoutboundtest.go

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Loading

0 comments on commit 25a6e0b

Please sign in to comment.