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 msg size and uint64 fixes #378

Merged
merged 3 commits into from
Oct 7, 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
2 changes: 1 addition & 1 deletion v2/contracts/Revert.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ struct RevertOptions {
/// @param revertMessage Arbitrary data sent back in onRevert.
struct RevertContext {
address asset;
uint64 amount;
uint256 amount;
bytes revertMessage;
}

Expand Down
6 changes: 6 additions & 0 deletions v2/contracts/evm/GatewayEVM.sol
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ contract GatewayEVM is
bytes32 public constant ASSET_HANDLER_ROLE = keccak256("ASSET_HANDLER_ROLE");
/// @notice New role identifier for pauser role.
bytes32 public constant PAUSER_ROLE = keccak256("PAUSER_ROLE");
/// @notice Max size of payload + revertOptions revert message.
uint256 public constant MAX_PAYLOAD_SIZE = 1024;

/// @custom:oz-upgrades-unsafe-allow constructor
constructor() {
Expand Down Expand Up @@ -280,6 +282,7 @@ contract GatewayEVM is
{
if (msg.value == 0) revert InsufficientETHAmount();
if (receiver == address(0)) revert ZeroAddress();
if (payload.length + revertOptions.revertMessage.length >= MAX_PAYLOAD_SIZE) revert PayloadSizeExceeded();

(bool deposited,) = tssAddress.call{ value: msg.value }("");

Expand Down Expand Up @@ -307,6 +310,7 @@ contract GatewayEVM is
{
if (amount == 0) revert InsufficientERC20Amount();
if (receiver == address(0)) revert ZeroAddress();
if (payload.length + revertOptions.revertMessage.length >= MAX_PAYLOAD_SIZE) revert PayloadSizeExceeded();

transferFromToAssetHandler(msg.sender, asset, amount);

Expand All @@ -327,6 +331,8 @@ contract GatewayEVM is
nonReentrant
{
if (receiver == address(0)) revert ZeroAddress();
if (payload.length + revertOptions.revertMessage.length >= MAX_PAYLOAD_SIZE) revert PayloadSizeExceeded();

emit Called(msg.sender, receiver, payload, revertOptions);
}

Expand Down
3 changes: 3 additions & 0 deletions v2/contracts/evm/interfaces/IGatewayEVM.sol
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ interface IGatewayEVMErrors {

/// @notice Error when trying to call onRevert method using arbitrary call.
error NotAllowedToCallOnRevert();

/// @notice Error indicating payload size exceeded in external functions.
error PayloadSizeExceeded();
}

/// @title IGatewayEVM
Expand Down
7 changes: 6 additions & 1 deletion v2/contracts/zevm/GatewayZEVM.sol
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ contract GatewayZEVM is
/// @notice New role identifier for pauser role.
bytes32 public constant PAUSER_ROLE = keccak256("PAUSER_ROLE");

/// @notice Max size of message + revertOptions revert message.
uint256 public constant MAX_MESSAGE_SIZE = 1024;

/// @dev Only Fungible module address allowed modifier.
modifier onlyFungible() {
if (msg.sender != FUNGIBLE_MODULE_ADDRESS) {
Expand Down Expand Up @@ -178,6 +181,7 @@ contract GatewayZEVM is
if (receiver.length == 0) revert ZeroAddress();
if (amount == 0) revert InsufficientZRC20Amount();
if (gasLimit == 0) revert InsufficientGasLimit();
if (message.length + revertOptions.revertMessage.length >= MAX_MESSAGE_SIZE) revert MessageSizeExceeded();

uint256 gasFee = _withdrawZRC20WithGasLimit(amount, zrc20, gasLimit);
emit Withdrawn(
Expand Down Expand Up @@ -234,6 +238,7 @@ contract GatewayZEVM is
{
if (receiver.length == 0) revert ZeroAddress();
if (amount == 0) revert InsufficientZetaAmount();
if (message.length + revertOptions.revertMessage.length >= MAX_MESSAGE_SIZE) revert MessageSizeExceeded();

_transferZETA(amount, FUNGIBLE_MODULE_ADDRESS);
emit Withdrawn(msg.sender, chainId, receiver, address(zetaToken), amount, 0, 0, message, 0, revertOptions);
Expand All @@ -257,8 +262,8 @@ contract GatewayZEVM is
whenNotPaused
{
if (receiver.length == 0) revert ZeroAddress();
if (message.length == 0) revert EmptyMessage();
if (gasLimit == 0) revert InsufficientGasLimit();
if (message.length + revertOptions.revertMessage.length >= MAX_MESSAGE_SIZE) revert MessageSizeExceeded();

(address gasZRC20, uint256 gasFee) = IZRC20(zrc20).withdrawGasFeeWithGasLimit(gasLimit);
if (!IZRC20(gasZRC20).transferFrom(msg.sender, FUNGIBLE_MODULE_ADDRESS, gasFee)) {
Expand Down
6 changes: 3 additions & 3 deletions v2/contracts/zevm/interfaces/IGatewayZEVM.sol
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,11 @@ interface IGatewayZEVMErrors {
/// @notice Error indicating that only WZETA or the Fungible module can call the function.
error OnlyWZETAOrFungible();

/// @notice Error indicating call method received empty message as argument.
error EmptyMessage();

/// @notice Error indicating an insufficient gas limit.
error InsufficientGasLimit();

/// @notice Error indicating message size exceeded in external functions.
error MessageSizeExceeded();
}

/// @title IGatewayZEVM
Expand Down
30 changes: 15 additions & 15 deletions v2/pkg/erc20custody.sol/erc20custody.go

Large diffs are not rendered by default.

42 changes: 21 additions & 21 deletions v2/pkg/erc20custody.t.sol/erc20custodytest.go

Large diffs are not rendered by default.

30 changes: 15 additions & 15 deletions v2/pkg/erc20custodyechidnatest.sol/erc20custodyechidnatest.go

Large diffs are not rendered by default.

73 changes: 52 additions & 21 deletions v2/pkg/gatewayevm.sol/gatewayevm.go

Large diffs are not rendered by default.

93 changes: 78 additions & 15 deletions v2/pkg/gatewayevm.t.sol/gatewayevminboundtest.go

Large diffs are not rendered by default.

42 changes: 21 additions & 21 deletions v2/pkg/gatewayevm.t.sol/gatewayevmtest.go

Large diffs are not rendered by default.

73 changes: 52 additions & 21 deletions v2/pkg/gatewayevmechidnatest.sol/gatewayevmechidnatest.go

Large diffs are not rendered by default.

30 changes: 15 additions & 15 deletions v2/pkg/gatewayevmupgrade.t.sol/gatewayevmuupsupgradetest.go

Large diffs are not rendered by default.

42 changes: 21 additions & 21 deletions v2/pkg/gatewayevmupgradetest.sol/gatewayevmupgradetest.go

Large diffs are not rendered by default.

30 changes: 15 additions & 15 deletions v2/pkg/gatewayevmzevm.t.sol/gatewayevmzevmtest.go

Large diffs are not rendered by default.

61 changes: 46 additions & 15 deletions v2/pkg/gatewayzevm.sol/gatewayzevm.go

Large diffs are not rendered by default.

67 changes: 65 additions & 2 deletions v2/pkg/gatewayzevm.t.sol/gatewayzevminboundtest.go

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions v2/pkg/gatewayzevm.t.sol/gatewayzevmoutboundtest.go

Large diffs are not rendered by default.

28 changes: 14 additions & 14 deletions v2/pkg/ierc20custody.sol/ierc20custody.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading