From f9bb505ab656814e04f808d239ae6b52cd630d0b Mon Sep 17 00:00:00 2001 From: Alexander Date: Wed, 10 Jan 2024 09:03:10 +0100 Subject: [PATCH] feat: refund gas to should never be set to address(0) --- src/IncentivizedMessageEscrow.sol | 1 + src/interfaces/IMessageEscrowErrors.sol | 1 + .../escrowMessage/refundGasTo.t.sol | 20 +++++++++++++++++++ 3 files changed, 22 insertions(+) create mode 100644 test/IncentivizedMessageEscrow/escrowMessage/refundGasTo.t.sol diff --git a/src/IncentivizedMessageEscrow.sol b/src/IncentivizedMessageEscrow.sol index 752ef61..fd9178c 100644 --- a/src/IncentivizedMessageEscrow.sol +++ b/src/IncentivizedMessageEscrow.sol @@ -156,6 +156,7 @@ abstract contract IncentivizedMessageEscrow is IIncentivizedMessageEscrow, Bytes bytes calldata message, IncentiveDescription calldata incentive ) checkBytes65Address(destinationAddress) external payable returns(uint256 gasRefund, bytes32 messageIdentifier) { + if (incentive.refundGasTo == address(0)) revert RefundGasToIsZero(); // Check that the application has set a destination implementation bytes memory destinationImplementation = implementationAddress[msg.sender][destinationIdentifier]; // Check that the length is not 0. diff --git a/src/interfaces/IMessageEscrowErrors.sol b/src/interfaces/IMessageEscrowErrors.sol index 1949a04..1c403d1 100644 --- a/src/interfaces/IMessageEscrowErrors.sol +++ b/src/interfaces/IMessageEscrowErrors.sol @@ -18,4 +18,5 @@ interface IMessageEscrowErrors { error InvalidImplementationAddress(); // c970156c error IncorrectValueProvided(uint128 expected, uint128 actual); // 0b52a60b error ImplementationAddressAlreadySet(bytes currentImplementation); // dba47850 + error RefundGasToIsZero(); // 6a1a6afe } \ No newline at end of file diff --git a/test/IncentivizedMessageEscrow/escrowMessage/refundGasTo.t.sol b/test/IncentivizedMessageEscrow/escrowMessage/refundGasTo.t.sol new file mode 100644 index 0000000..7b30308 --- /dev/null +++ b/test/IncentivizedMessageEscrow/escrowMessage/refundGasTo.t.sol @@ -0,0 +1,20 @@ +// SPDX-License-Identifier: UNLICENSED +pragma solidity ^0.8.13; + +import "forge-std/Test.sol"; +import { TestCommon } from "../../TestCommon.t.sol"; + +contract EscrowInformationTest is TestCommon { + function test_error_refund_gas_to_0() public { + IncentiveDescription storage incentive = _INCENTIVE; + incentive.refundGasTo = address(0); + vm.expectRevert(); + (, bytes32 messageIdentifier) = escrow.submitMessage{value: _getTotalIncentive(_INCENTIVE)}( + bytes32(uint256(0x123123) + uint256(2**255)), + _DESTINATION_ADDRESS_THIS, + _MESSAGE, + incentive + ); + } + +}