From 31ac06d6c357cdd6263451947ad79f0dcb2c3b22 Mon Sep 17 00:00:00 2001 From: Alexander Date: Mon, 23 Oct 2023 18:03:54 +0200 Subject: [PATCH 01/11] feat: renamings --- .gas-snapshot | 82 +++++++++---------- src/IncentivizedMessageEscrow.sol | 29 ++++--- src/MessagePayload.sol | 16 ++-- src/interfaces/IMessageEscrowErrors.sol | 1 + .../increaseBounty/IncreaseBounty.t.sol | 4 +- .../processMessage/GasSpendControl.sol | 6 +- .../processMessage/NoReceive.t.sol | 2 +- test/TestCommon.t.sol | 4 +- 8 files changed, 72 insertions(+), 72 deletions(-) diff --git a/.gas-snapshot b/.gas-snapshot index 2df6057..90b7d65 100644 --- a/.gas-snapshot +++ b/.gas-snapshot @@ -1,43 +1,43 @@ -AckReentryTest:test_reentry_on_ack_message() (gas: 531465) -CallReentryTest:test_reentry_on_call_message() (gas: 560516) -EscrowInformationTest:test_check_escrow_events() (gas: 100189) -EscrowInformationTest:test_check_escrow_state() (gas: 97583) -EscrowInformationTest:test_gas_refund(uint256) (runs: 256, μ: 148866, ~: 153744) -EscrowWrongGasPaymentTest:test_fail_not_enough_gas_sent() (gas: 94126) -EscrowWrongGasPaymentTest:test_place_incentive() (gas: 90028) -GasSpendControlTest:test_fail_relayer_has_to_provide_enough_gas() (gas: 605769) -GasSpendControlTest:test_process_ack_gas() (gas: 621372) -GasSpendControlTest:test_process_delivery_gas() (gas: 361159) +AckReentryTest:test_reentry_on_ack_message() (gas: 531427) +CallReentryTest:test_reentry_on_call_message() (gas: 560468) +EscrowInformationTest:test_check_escrow_events() (gas: 100141) +EscrowInformationTest:test_check_escrow_state() (gas: 97535) +EscrowInformationTest:test_gas_refund(uint256) (runs: 256, μ: 148818, ~: 153696) +EscrowWrongGasPaymentTest:test_fail_not_enough_gas_sent() (gas: 94078) +EscrowWrongGasPaymentTest:test_place_incentive() (gas: 89980) +GasSpendControlTest:test_fail_relayer_has_to_provide_enough_gas() (gas: 605647) +GasSpendControlTest:test_process_ack_gas() (gas: 621329) +GasSpendControlTest:test_process_delivery_gas() (gas: 361074) IncreaseBountyTest:test_fail_bounty_does_not_exist() (gas: 18092) -IncreaseBountyTest:test_fail_overpay() (gas: 128551) -IncreaseBountyTest:test_fail_under_and_overpay(int256) (runs: 256, μ: 130637, ~: 130637) -IncreaseBountyTest:test_increase_escrow() (gas: 130317) -IncreaseBountyTest:test_no_increase_escrow() (gas: 123046) -MessageIdentifierTest:test_destination_identifier_impacts_message_identifier() (gas: 301697) -MessageIdentifierTest:test_non_unique_bounty(bytes) (runs: 256, μ: 105179, ~: 105073) -MessageIdentifierTest:test_unique_identifier_block_10() (gas: 97356) -MessageIdentifierTest:test_unique_identifier_block_11() (gas: 97312) -NoImplementationAddressSetTest:test_error_no_implementation_address_set() (gas: 343809) -OnRecvAckTest:test_on_ack() (gas: 231489) -OnRecvCallTest:test_on_call() (gas: 163544) -OnRecvRecoverAckTest:test_recover_ack() (gas: 248414) -OnRecvTimeoutTest:test_on_timeout() (gas: 122932) -ProcessMessageAckTest:test_ack_called_event() (gas: 219055) -ProcessMessageAckTest:test_ack_different_recipitents() (gas: 253701) -ProcessMessageAckTest:test_ack_less_time_than_expected(uint64,uint64) (runs: 256, μ: 256507, ~: 258584) -ProcessMessageAckTest:test_ack_more_time_than_expected(uint64,uint64) (runs: 256, μ: 259380, ~: 259380) -ProcessMessageAckTest:test_ack_process_message() (gas: 214262) -ProcessMessageCallTest:test_call_process_message() (gas: 177645) -ProcessMessageCallTest:test_call_process_message_twice() (gas: 173179) -ProcessMessageCallTest:test_expect_caller(address) (runs: 256, μ: 228410, ~: 228410) -ProcessMessageNoReceiveTest:test_application_does_not_implement_interface() (gas: 174683) -ReturnBombTest:test_process_ack_gas() (gas: 5338932) -SendMessagePaymentTest:test_error_send_message_without_additional_cost() (gas: 110120) +IncreaseBountyTest:test_fail_overpay() (gas: 128503) +IncreaseBountyTest:test_fail_under_and_overpay(int256) (runs: 256, μ: 130589, ~: 130589) +IncreaseBountyTest:test_increase_escrow() (gas: 130269) +IncreaseBountyTest:test_no_increase_escrow() (gas: 122998) +MessageIdentifierTest:test_destination_identifier_impacts_message_identifier() (gas: 301601) +MessageIdentifierTest:test_non_unique_bounty(bytes) (runs: 256, μ: 105083, ~: 104977) +MessageIdentifierTest:test_unique_identifier_block_10() (gas: 97308) +MessageIdentifierTest:test_unique_identifier_block_11() (gas: 97264) +NoImplementationAddressSetTest:test_error_no_implementation_address_set() (gas: 343767) +OnRecvAckTest:test_on_ack() (gas: 231441) +OnRecvCallTest:test_on_call() (gas: 163496) +OnRecvRecoverAckTest:test_recover_ack() (gas: 248366) +OnRecvTimeoutTest:test_on_timeout() (gas: 122894) +ProcessMessageAckTest:test_ack_called_event() (gas: 219012) +ProcessMessageAckTest:test_ack_different_recipitents() (gas: 253658) +ProcessMessageAckTest:test_ack_less_time_than_expected(uint64,uint64) (runs: 256, μ: 256360, ~: 258541) +ProcessMessageAckTest:test_ack_more_time_than_expected(uint64,uint64) (runs: 256, μ: 259337, ~: 259337) +ProcessMessageAckTest:test_ack_process_message() (gas: 214219) +ProcessMessageCallTest:test_call_process_message() (gas: 177597) +ProcessMessageCallTest:test_call_process_message_twice() (gas: 173131) +ProcessMessageCallTest:test_expect_caller(address) (runs: 256, μ: 228362, ~: 228362) +ProcessMessageNoReceiveTest:test_application_does_not_implement_interface() (gas: 174598) +ReturnBombTest:test_process_ack_gas() (gas: 5338852) +SendMessagePaymentTest:test_error_send_message_without_additional_cost() (gas: 110072) SendMessagePaymentTest:test_estimate_cost() (gas: 8086) -SendMessagePaymentTest:test_process_message_with_additional_payment(bytes) (runs: 256, μ: 175499, ~: 175285) -SendMessagePaymentTest:test_process_message_without_additional_payment(bytes) (runs: 256, μ: 176059, ~: 175845) -SendMessagePaymentTest:test_send_message_with_additional_cost() (gas: 102845) -TargetDeltaZeroTest:test_target_delta_zero(uint16) (runs: 256, μ: 257183, ~: 257183) +SendMessagePaymentTest:test_process_message_with_additional_payment(bytes) (runs: 256, μ: 175451, ~: 175237) +SendMessagePaymentTest:test_process_message_without_additional_payment(bytes) (runs: 256, μ: 176011, ~: 175797) +SendMessagePaymentTest:test_send_message_with_additional_cost() (gas: 102797) +TargetDeltaZeroTest:test_target_delta_zero(uint16) (runs: 256, μ: 257140, ~: 257140) TestMessages:testCannotVerifySignaturesWithInvalidSignature(bytes) (runs: 256, μ: 28353, ~: 28345) TestMessages:testCannotVerifySignaturesWithOutOfBoundsSignature(bytes) (runs: 256, μ: 29972, ~: 29964) TestMessages:testHashMismatchedVMIsNotVerified() (gas: 92458) @@ -49,6 +49,6 @@ TestMessagesC2Sigs:test_error_invalid_vm() (gas: 135944) TestMessagesC:test_compare_wormhole_implementation_and_calldata_version() (gas: 105270) TestMessagesC:test_error_invalid_vm() (gas: 103798) TestProcessMessageDisabled:test_process_message_disabled(bytes,bytes,address) (runs: 256, μ: 10140, ~: 10117) -TestRoundtrip:test_escrow_wormhole_message(bytes) (runs: 256, μ: 264468, ~: 263957) -TimeOverflowTest:test_larger_than_uint_time_is_fine() (gas: 253419) -TimeOverflowTest:test_overflow_in_unchecked_is_fine() (gas: 255631) \ No newline at end of file +TestRoundtrip:test_escrow_wormhole_message(bytes) (runs: 256, μ: 264396, ~: 263885) +TimeOverflowTest:test_larger_than_uint_time_is_fine() (gas: 253376) +TimeOverflowTest:test_overflow_in_unchecked_is_fine() (gas: 255588) \ No newline at end of file diff --git a/src/IncentivizedMessageEscrow.sol b/src/IncentivizedMessageEscrow.sol index 7aaa3de..aee7d8b 100644 --- a/src/IncentivizedMessageEscrow.sol +++ b/src/IncentivizedMessageEscrow.sol @@ -4,7 +4,7 @@ pragma solidity ^0.8.13; import { IIncentivizedMessageEscrow } from "./interfaces/IIncentivizedMessageEscrow.sol"; import { ICrossChainReceiver } from "./interfaces/ICrossChainReceiver.sol"; import { Bytes65 } from "./utils/Bytes65.sol"; -import { SourcetoDestination, DestinationtoSource } from "./MessagePayload.sol"; +import { CTX_SOURCE_TO_DESTINATION, CTX_DESTINATION_TO_SOURCE } from "./MessagePayload.sol"; import { Multicall } from "openzeppelin/utils/Multicall.sol"; import "./MessagePayload.sol"; @@ -42,8 +42,6 @@ abstract contract IncentivizedMessageEscrow is IIncentivizedMessageEscrow, Bytes /// the gas is sent here instead. address constant public SEND_LOST_GAS_TO = address(0); - bytes32 constant KECCACK_OF_NOTHING = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; - //--- Storage ---// mapping(bytes32 => IncentiveDescription) _bounty; @@ -85,6 +83,7 @@ abstract contract IncentivizedMessageEscrow is IIncentivizedMessageEscrow, Bytes } + // TODO: Not change when set. /// @notice Sets the escrow implementation for a specific chain function setRemoteEscrowImplementation(bytes32 chainIdentifier, bytes calldata implementation) external { implementationAddress[msg.sender][chainIdentifier] = implementation; @@ -113,7 +112,7 @@ abstract contract IncentivizedMessageEscrow is IIncentivizedMessageEscrow, Bytes uint128 ackGas = incentive.maxGasAck * ackGasPriceIncrease; uint128 sum = deliveryGas + ackGas; // Check that the provided gas is exact - if (msg.value != sum) revert NotEnoughGasProvided(sum, uint128(msg.value)); + if (msg.value != sum) revert IncorrectValueProvided(sum, uint128(msg.value)); // Update storage. incentive.priceOfDeliveryGas += deliveryGasPriceIncrease; @@ -149,8 +148,8 @@ abstract contract IncentivizedMessageEscrow is IIncentivizedMessageEscrow, Bytes ) checkBytes65Address(destinationAddress) external payable returns(uint256 gasRefund, bytes32 messageIdentifier) { // Check that the application has set a destination implementation bytes memory destinationImplementation = implementationAddress[msg.sender][destinationIdentifier]; - // It is assumed that it is enough to check the first 32 bytes. - if (keccak256(destinationImplementation) == KECCACK_OF_NOTHING) revert NoImplementationAddressSet(); + // todo: It is assumed that it is enough to check the first 32 bytes. // Check that the length is not 0. + if (destinationImplementation.length == 0) revert NoImplementationAddressSet(); // Prepare to store incentive messageIdentifier = _getMessageIdentifier( @@ -162,7 +161,7 @@ abstract contract IncentivizedMessageEscrow is IIncentivizedMessageEscrow, Bytes // Add escrow context to the message. bytes memory messageWithContext = abi.encodePacked( - bytes1(SourcetoDestination), // This is a sendMessage, + bytes1(CTX_SOURCE_TO_DESTINATION), // This is a sendMessage, messageIdentifier, // An unique identifier to recover identifier to recover convertEVMTo65(msg.sender), // Original sender destinationAddress, // The address to deliver the (original) message to. @@ -230,12 +229,12 @@ abstract contract IncentivizedMessageEscrow is IIncentivizedMessageEscrow, Bytes // Figure out if this is a call or an ack. bytes1 context = bytes1(message[0]); - if (context == SourcetoDestination) { + if (context == CTX_SOURCE_TO_DESTINATION) { bytes memory ackMessageWithContext = _handleCall(chainIdentifier, implementationIdentifier, message, feeRecipitent, gasLimit); // The cost management is made by _sendMessage so we don't have to check if enough gas has been provided. _sendMessage(chainIdentifier, implementationIdentifier, ackMessageWithContext); - } else if (context == DestinationtoSource) { + } else if (context == CTX_DESTINATION_TO_SOURCE) { _handleAck(chainIdentifier, implementationIdentifier, message, feeRecipitent, gasLimit); } else { revert NotImplementedError(); @@ -259,7 +258,7 @@ abstract contract IncentivizedMessageEscrow is IIncentivizedMessageEscrow, Bytes // Deliver message to application. // Decode gas limit, application address and sending application. - uint48 maxGas = uint48(bytes6(message[CTX0_MIN_GAS_LIMIT_START:CTX0_MIN_GAS_LIMIT_END])); + uint48 maxGas = uint48(bytes6(message[CTX0_MAX_GAS_LIMIT_START:CTX0_MAX_GAS_LIMIT_END])); address toApplication = address(bytes20(message[CTX0_TO_APPLICATION_START_EVM:CTX0_TO_APPLICATION_END])); bytes calldata fromApplication = message[FROM_APPLICATION_LENGTH_POS:FROM_APPLICATION_END]; @@ -272,7 +271,7 @@ abstract contract IncentivizedMessageEscrow is IIncentivizedMessageEscrow, Bytes if (expectedSourceImplementationHash != keccak256(sourceImplementationIdentifier)) { // If they are different, return send a failed message back with `0xfe`. acknowledgement = abi.encodePacked( - MESSAGE_REVERTED, + NO_AUTHENTICATION, message[CTX0_MESSAGE_START: ] ); } else { @@ -300,7 +299,7 @@ abstract contract IncentivizedMessageEscrow is IIncentivizedMessageEscrow, Bytes // Encode a new message to send back. This lets the relayer claim their payment. ackMessageWithContext = abi.encodePacked( - bytes1(DestinationtoSource), // This is a sendMessage + bytes1(CTX_DESTINATION_TO_SOURCE), // This is a sendMessage messageIdentifier, // message identifier fromApplication, feeRecipitent, @@ -352,7 +351,7 @@ abstract contract IncentivizedMessageEscrow is IIncentivizedMessageEscrow, Bytes // Deliver the ack to the application. // Ensure that if the call reverts it doesn't boil up. // We don't need any return values and don't care if the call reverts. - // This call implies we need reentry protection, since we need to call it before we delete the incentive map. + // This call implies we need reentry protection. bytes memory payload = abi.encodeWithSignature("ackMessage(bytes32,bytes32,bytes)", destinationIdentifier, messageIdentifier, message[CTX1_MESSAGE_START: ]); assembly ("memory-safe") { // Because Solidity always create RETURNDATACOPY for external calls, even low-level calls where no variables are assigned, @@ -392,7 +391,7 @@ abstract contract IncentivizedMessageEscrow is IIncentivizedMessageEscrow, Bytes if(!payable(refundGasTo).send(refund)) { payable(SEND_LOST_GAS_TO).transfer(refund); // If we don't send the gas somewhere, the gas is lost forever. } - address destinationFeeRecipitent = address(uint160(uint256(bytes32(message[CTX1_RELAYER_RECIPITENT_START:CTX1_RELAYER_RECIPITENT_END])))); + address destinationFeeRecipitent = address(uint160(uint256(bytes32(message[CTX1_RELAYER_RECIPIENT_START:CTX1_RELAYER_RECIPITENT_END])))); address sourceFeeRecipitent = address(uint160(uint256(feeRecipitent))); // If both the destination relayer and source relayer are the same then we don't have to figure out which fraction goes to who. if (destinationFeeRecipitent == sourceFeeRecipitent) { @@ -514,7 +513,7 @@ abstract contract IncentivizedMessageEscrow is IIncentivizedMessageEscrow, Bytes bytes1 context = bytes1(message[0]); // Only allow acks to do this. Normal messages are invalid after first execution. - if (context == DestinationtoSource) { + if (context == CTX_DESTINATION_TO_SOURCE) { bytes32 messageIdentifier = bytes32(message[MESSAGE_IDENTIFIER_START:MESSAGE_IDENTIFIER_END]); if(_bounty[messageIdentifier].refundGasTo != address(0)) revert AckHasNotBeenExecuted(); diff --git a/src/MessagePayload.sol b/src/MessagePayload.sol index be3a9da..07fcf8f 100644 --- a/src/MessagePayload.sol +++ b/src/MessagePayload.sol @@ -12,9 +12,9 @@ pragma solidity ^0.8.13; // // Context-depending Payload // CTX0 - 0x00 - Source to Destination -// + TO_VAULT_LENGTH 98 (1 byte) -// + TO_VAULT 99 (64 bytes) -// + MIN_GAS 163 (6 bytes) +// + TO_APPLICATION_LENGTH 98 (1 byte) +// + TO_APPLICATION 99 (64 bytes) +// + MAX_GAS 163 (6 bytes) // => MESSAGE_START 169 (remainder) // // CTX1 - 0x01 - Destination to Source @@ -26,8 +26,8 @@ pragma solidity ^0.8.13; // Contexts ********************************************************************************************************************* -bytes1 constant SourcetoDestination = 0x00; -bytes1 constant DestinationtoSource = 0x01; +bytes1 constant CTX_SOURCE_TO_DESTINATION = 0x00; +bytes1 constant CTX_DESTINATION_TO_SOURCE = 0x01; // Common Payload *************************************************************************************************************** @@ -50,14 +50,14 @@ uint constant CTX0_TO_APPLICATION_START = 99; uint constant CTX0_TO_APPLICATION_START_EVM = 143; // If the address is an EVM address, this is the start uint constant CTX0_TO_APPLICATION_END = 163; -uint constant CTX0_MIN_GAS_LIMIT_START = 163; -uint constant CTX0_MIN_GAS_LIMIT_END = 169; +uint constant CTX0_MAX_GAS_LIMIT_START = 163; +uint constant CTX0_MAX_GAS_LIMIT_END = 169; uint constant CTX0_MESSAGE_START = 169; // CTX1 Destination to Source ************************************************************************************************** -uint constant CTX1_RELAYER_RECIPITENT_START = 98; +uint constant CTX1_RELAYER_RECIPIENT_START = 98; uint constant CTX1_RELAYER_RECIPITENT_END = 130; uint constant CTX1_GAS_SPENT_START = 130; diff --git a/src/interfaces/IMessageEscrowErrors.sol b/src/interfaces/IMessageEscrowErrors.sol index a5992d9..ea0e6f8 100644 --- a/src/interfaces/IMessageEscrowErrors.sol +++ b/src/interfaces/IMessageEscrowErrors.sol @@ -16,4 +16,5 @@ interface IMessageEscrowErrors { error AckHasNotBeenExecuted(); // 3d1553f8 error NoImplementationAddressSet(); // 9f994b4b error InvalidImplementationAddress(); // c970156c + error IncorrectValueProvided(uint128 expected, uint128 actual); // 0b52a60b } \ No newline at end of file diff --git a/test/IncentivizedMessageEscrow/increaseBounty/IncreaseBounty.t.sol b/test/IncentivizedMessageEscrow/increaseBounty/IncreaseBounty.t.sol index 1ad0d07..f46eeba 100644 --- a/test/IncentivizedMessageEscrow/increaseBounty/IncreaseBounty.t.sol +++ b/test/IncentivizedMessageEscrow/increaseBounty/IncreaseBounty.t.sol @@ -36,7 +36,7 @@ contract IncreaseBountyTest is TestCommon { bytes32 messageIdentifier = escrowMessage(_MESSAGE); vm.expectRevert( - abi.encodeWithSignature("NotEnoughGasProvided(uint128,uint128)", 0, overPay) + abi.encodeWithSignature("IncorrectValueProvided(uint128,uint128)", 0, overPay) ); escrow.increaseBounty{value: overPay}( messageIdentifier, @@ -61,7 +61,7 @@ contract IncreaseBountyTest is TestCommon { uint128 newPay = uint128(uint256(int256(uint256(difference)) + diffPay)); vm.expectRevert( - abi.encodeWithSignature("NotEnoughGasProvided(uint128,uint128)", difference, newPay) + abi.encodeWithSignature("IncorrectValueProvided(uint128,uint128)", difference, newPay) ); escrow.increaseBounty{value: newPay}( diff --git a/test/IncentivizedMessageEscrow/processMessage/GasSpendControl.sol b/test/IncentivizedMessageEscrow/processMessage/GasSpendControl.sol index d3f4f3f..9fb9bab 100644 --- a/test/IncentivizedMessageEscrow/processMessage/GasSpendControl.sol +++ b/test/IncentivizedMessageEscrow/processMessage/GasSpendControl.sol @@ -58,7 +58,7 @@ contract GasSpendControlTest is TestCommon { messageIdentifier, _DESTINATION_ADDRESS_APPLICATION, destinationFeeRecipitent, - uint48(0x36eb2), // Gas used + uint48(0x36e8d), // Gas used uint64(1), bytes1(0xff), // This states that the call went wrong. message @@ -104,7 +104,7 @@ contract GasSpendControlTest is TestCommon { // The strange gas limit of ' + 5000 - 2' here is because is how much is actually spent (read from trace) and + 5000 - 2 is some kind of refund that // the relayer needs to add as extra. (reentry refund) - escrow.processMessage{gas: 239891}( + escrow.processMessage{gas: 239854}( mockContext, messageWithContext, destinationFeeRecipitent @@ -126,7 +126,7 @@ contract GasSpendControlTest is TestCommon { ) ) ); - escrow.processMessage{gas: 239891 - 1}( + escrow.processMessage{gas: 239854 - 1}( mockContext, messageWithContext, destinationFeeRecipitent diff --git a/test/IncentivizedMessageEscrow/processMessage/NoReceive.t.sol b/test/IncentivizedMessageEscrow/processMessage/NoReceive.t.sol index eb50059..a2b4f3b 100644 --- a/test/IncentivizedMessageEscrow/processMessage/NoReceive.t.sol +++ b/test/IncentivizedMessageEscrow/processMessage/NoReceive.t.sol @@ -54,7 +54,7 @@ contract ProcessMessageNoReceiveTest is TestCommon { messageIdentifier, _DESTINATION_ADDRESS_THIS, feeRecipitent, - uint48(0x8885), // Gas used + uint48(0x8860), // Gas used uint64(1), abi.encodePacked(bytes1(0xff)), message diff --git a/test/TestCommon.t.sol b/test/TestCommon.t.sol index 510913c..2cc7365 100644 --- a/test/TestCommon.t.sol +++ b/test/TestCommon.t.sol @@ -20,9 +20,9 @@ interface ICanEscrowMessage is IMessageEscrowStructs{ contract TestCommon is Test, IMessageEscrowEvents, IMessageEscrowStructs { - uint256 constant GAS_SPENT_ON_SOURCE = 6346; + uint256 constant GAS_SPENT_ON_SOURCE = 6354; uint256 constant GAS_SPENT_ON_DESTINATION = 33442; - uint256 constant GAS_RECEIVE_CONSTANT = 6161947440; + uint256 constant GAS_RECEIVE_CONSTANT = 6164516424; bytes32 constant _DESTINATION_IDENTIFIER = bytes32(uint256(0x123123) + uint256(2**255)); From 6be485b9dab88d9d57f1502c716ec3ada63447c1 Mon Sep 17 00:00:00 2001 From: Alexander Date: Mon, 23 Oct 2023 18:22:36 +0200 Subject: [PATCH 02/11] feat: further renamings --- .gas-snapshot | 88 +++++++++---------- src/IncentivizedMessageEscrow.sol | 54 ++++++------ src/TimeoutExtension.sol | 2 +- src/apps/mock/IncentivizedMockEscrow.sol | 6 +- .../mock/OnRecvIncentivizedMockEscrow.sol | 16 ++-- .../wormhole/IncentivizedWormholeEscrow.sol | 8 +- src/interfaces/ICrossChainReceiver.sol | 4 +- src/interfaces/IIncentivizedMessageEscrow.sol | 6 +- src/interfaces/IMessageEscrowEvents.sol | 2 +- .../escrowMessage/EscrowMessage.t.sol | 6 +- .../escrowMessage/MessageIdentifier.t.sol | 16 ++-- .../NoRemoteImplementation.t.sol | 2 +- .../escrowMessage/WrongGasPayment.t.sol | 6 +- .../feature/SendMessagePayment.t.sol | 18 ++-- .../increaseBounty/IncreaseBounty.t.sol | 10 +-- .../processMessage/GasSpendControl.sol | 14 +-- .../processMessage/NoReceive.t.sol | 8 +- .../processMessage/Reentry.ack.t.sol | 8 +- .../processMessage/Reentry.call.t.sol | 10 +-- .../processMessage/ReturnBomb.t.sol | 4 +- .../processMessage/TargetDeltaZero.t.sol | 2 +- .../processMessage/TimeOverflow.t.sol | 4 +- .../processMessage/_handleAck.t.sol | 14 +-- .../processMessage/_handleCall.t.sol | 20 ++--- .../TestOnRecvCommon.t.sol | 4 +- .../processMessage/_handleAck.t.sol | 4 +- .../processMessage/_handleCall.t.sol | 2 +- .../processMessage/_handleTimeout.t.sol | 4 +- .../processMessage/processMessage.t.sol | 4 +- .../processMessage/recoverAck.t.sol | 4 +- test/TestCommon.t.sol | 30 +++---- test/mocks/BadContract.sol | 2 +- test/mocks/MockApplication.sol | 19 +--- test/mocks/MockOnRecvAMB.sol | 2 +- test/mocks/MockSpendGas.sol | 6 +- test/mocks/ReturnBomber.sol | 10 +-- test/wormhole/roundtrip.t.sol | 8 +- 37 files changed, 207 insertions(+), 220 deletions(-) diff --git a/.gas-snapshot b/.gas-snapshot index 90b7d65..b1f57be 100644 --- a/.gas-snapshot +++ b/.gas-snapshot @@ -1,43 +1,29 @@ -AckReentryTest:test_reentry_on_ack_message() (gas: 531427) -CallReentryTest:test_reentry_on_call_message() (gas: 560468) -EscrowInformationTest:test_check_escrow_events() (gas: 100141) -EscrowInformationTest:test_check_escrow_state() (gas: 97535) -EscrowInformationTest:test_gas_refund(uint256) (runs: 256, μ: 148818, ~: 153696) -EscrowWrongGasPaymentTest:test_fail_not_enough_gas_sent() (gas: 94078) -EscrowWrongGasPaymentTest:test_place_incentive() (gas: 89980) -GasSpendControlTest:test_fail_relayer_has_to_provide_enough_gas() (gas: 605647) -GasSpendControlTest:test_process_ack_gas() (gas: 621329) -GasSpendControlTest:test_process_delivery_gas() (gas: 361074) -IncreaseBountyTest:test_fail_bounty_does_not_exist() (gas: 18092) -IncreaseBountyTest:test_fail_overpay() (gas: 128503) -IncreaseBountyTest:test_fail_under_and_overpay(int256) (runs: 256, μ: 130589, ~: 130589) -IncreaseBountyTest:test_increase_escrow() (gas: 130269) -IncreaseBountyTest:test_no_increase_escrow() (gas: 122998) -MessageIdentifierTest:test_destination_identifier_impacts_message_identifier() (gas: 301601) -MessageIdentifierTest:test_non_unique_bounty(bytes) (runs: 256, μ: 105083, ~: 104977) -MessageIdentifierTest:test_unique_identifier_block_10() (gas: 97308) -MessageIdentifierTest:test_unique_identifier_block_11() (gas: 97264) -NoImplementationAddressSetTest:test_error_no_implementation_address_set() (gas: 343767) -OnRecvAckTest:test_on_ack() (gas: 231441) -OnRecvCallTest:test_on_call() (gas: 163496) -OnRecvRecoverAckTest:test_recover_ack() (gas: 248366) -OnRecvTimeoutTest:test_on_timeout() (gas: 122894) -ProcessMessageAckTest:test_ack_called_event() (gas: 219012) -ProcessMessageAckTest:test_ack_different_recipitents() (gas: 253658) -ProcessMessageAckTest:test_ack_less_time_than_expected(uint64,uint64) (runs: 256, μ: 256360, ~: 258541) -ProcessMessageAckTest:test_ack_more_time_than_expected(uint64,uint64) (runs: 256, μ: 259337, ~: 259337) -ProcessMessageAckTest:test_ack_process_message() (gas: 214219) -ProcessMessageCallTest:test_call_process_message() (gas: 177597) -ProcessMessageCallTest:test_call_process_message_twice() (gas: 173131) -ProcessMessageCallTest:test_expect_caller(address) (runs: 256, μ: 228362, ~: 228362) -ProcessMessageNoReceiveTest:test_application_does_not_implement_interface() (gas: 174598) -ReturnBombTest:test_process_ack_gas() (gas: 5338852) -SendMessagePaymentTest:test_error_send_message_without_additional_cost() (gas: 110072) -SendMessagePaymentTest:test_estimate_cost() (gas: 8086) -SendMessagePaymentTest:test_process_message_with_additional_payment(bytes) (runs: 256, μ: 175451, ~: 175237) -SendMessagePaymentTest:test_process_message_without_additional_payment(bytes) (runs: 256, μ: 176011, ~: 175797) -SendMessagePaymentTest:test_send_message_with_additional_cost() (gas: 102797) -TargetDeltaZeroTest:test_target_delta_zero(uint16) (runs: 256, μ: 257140, ~: 257140) +AckReentryTest:test_reentry_on_ack_message() (gas: 531633) +CallReentryTest:test_reentry_on_call_message() (gas: 560819) +EscrowInformationTest:test_check_escrow_events() (gas: 100314) +EscrowInformationTest:test_check_escrow_state() (gas: 97683) +EscrowInformationTest:test_gas_refund(uint256) (runs: 256, μ: 148991, ~: 153869) +EscrowWrongGasPaymentTest:test_fail_not_enough_gas_sent() (gas: 94251) +EscrowWrongGasPaymentTest:test_place_incentive() (gas: 90153) +GasSpendControlTest:test_fail_relayer_has_to_provide_enough_gas() (gas: 605997) +GasSpendControlTest:test_process_ack_gas() (gas: 621671) +GasSpendControlTest:test_process_delivery_gas() (gas: 361342) +IncreaseBountyTest:test_fail_bounty_does_not_exist() (gas: 18045) +IncreaseBountyTest:test_fail_overpay() (gas: 128644) +IncreaseBountyTest:test_fail_under_and_overpay(int256) (runs: 256, μ: 130730, ~: 130730) +IncreaseBountyTest:test_increase_escrow() (gas: 130410) +IncreaseBountyTest:test_no_increase_escrow() (gas: 123139) +MessageIdentifierTest:test_destination_identifier_impacts_message_identifier() (gas: 302397) +MessageIdentifierTest:test_non_unique_bounty(bytes) (runs: 256, μ: 105429, ~: 105323) +MessageIdentifierTest:test_unique_identifier_block_10() (gas: 97481) +MessageIdentifierTest:test_unique_identifier_block_11() (gas: 97437) +NoImplementationAddressSetTest:test_error_no_implementation_address_set() (gas: 343962) +OnRecvAckTest:test_on_ack() (gas: 231241) +OnRecvCallTest:test_on_call() (gas: 163298) +OnRecvRecoverAckTest:test_recover_ack() (gas: 248098) +OnRecvTimeoutTest:test_on_timeout() (gas: 122840) +ReturnBombTest:test_process_ack_gas() (gas: 5339305) +TargetDeltaZeroTest:test_target_delta_zero(uint16) (runs: 256, μ: 257410, ~: 257410) TestMessages:testCannotVerifySignaturesWithInvalidSignature(bytes) (runs: 256, μ: 28353, ~: 28345) TestMessages:testCannotVerifySignaturesWithOutOfBoundsSignature(bytes) (runs: 256, μ: 29972, ~: 29964) TestMessages:testHashMismatchedVMIsNotVerified() (gas: 92458) @@ -48,7 +34,21 @@ TestMessagesC2Sigs:test_compare_wormhole_implementation_and_calldata_version() ( TestMessagesC2Sigs:test_error_invalid_vm() (gas: 135944) TestMessagesC:test_compare_wormhole_implementation_and_calldata_version() (gas: 105270) TestMessagesC:test_error_invalid_vm() (gas: 103798) -TestProcessMessageDisabled:test_process_message_disabled(bytes,bytes,address) (runs: 256, μ: 10140, ~: 10117) -TestRoundtrip:test_escrow_wormhole_message(bytes) (runs: 256, μ: 264396, ~: 263885) -TimeOverflowTest:test_larger_than_uint_time_is_fine() (gas: 253376) -TimeOverflowTest:test_overflow_in_unchecked_is_fine() (gas: 255588) \ No newline at end of file +TestRoundtrip:test_escrow_wormhole_message(bytes) (runs: 256, μ: 265001, ~: 264490) +TestprocessPacketDisabled:test_process_message_disabled(bytes,bytes,address) (runs: 256, μ: 10250, ~: 10227) +TimeOverflowTest:test_larger_than_uint_time_is_fine() (gas: 253696) +TimeOverflowTest:test_overflow_in_unchecked_is_fine() (gas: 255883) +processPacketAckTest:test_ack_called_event() (gas: 219307) +processPacketAckTest:test_ack_different_recipitents() (gas: 253978) +processPacketAckTest:test_ack_less_time_than_expected(uint64,uint64) (runs: 256, μ: 256863, ~: 258836) +processPacketAckTest:test_ack_more_time_than_expected(uint64,uint64) (runs: 256, μ: 259632, ~: 259632) +processPacketAckTest:test_ack_process_message() (gas: 214539) +processPacketCallTest:test_call_process_message() (gas: 177866) +processPacketCallTest:test_call_process_message_twice() (gas: 173482) +processPacketCallTest:test_expect_caller(address) (runs: 256, μ: 228841, ~: 228841) +processPacketNoReceiveTest:test_application_does_not_implement_interface() (gas: 174846) +sendPacketPaymentTest:test_error_send_message_without_additional_cost() (gas: 110220) +sendPacketPaymentTest:test_estimate_cost() (gas: 8079) +sendPacketPaymentTest:test_process_message_with_additional_payment(bytes) (runs: 256, μ: 175720, ~: 175506) +sendPacketPaymentTest:test_process_message_without_additional_payment(bytes) (runs: 256, μ: 176280, ~: 176066) +sendPacketPaymentTest:test_send_message_with_additional_cost() (gas: 102945) \ No newline at end of file diff --git a/src/IncentivizedMessageEscrow.sol b/src/IncentivizedMessageEscrow.sol index aee7d8b..a357f4b 100644 --- a/src/IncentivizedMessageEscrow.sol +++ b/src/IncentivizedMessageEscrow.sol @@ -17,7 +17,7 @@ import "./MessagePayload.sol"; * The goal is to overload the existing incentive scheme with one which is open for anyone. * * Each messaging protocol will have a respective implementation which understands - * how to send and verify messages. An integrating application shall deliver a message to escrowMessage + * how to send and verify messages. An integrating application shall deliver a message to submitMessage * along with the respective incentives. This contract will then handle transfering the message to the * destination and carry an ack back from the destination to return to the integrating application. * @@ -55,11 +55,11 @@ abstract contract IncentivizedMessageEscrow is IIncentivizedMessageEscrow, Bytes /// @notice Verify a message's authenticity. /// @dev Should be overwritten by the specific messaging protocol verification structure. - function _verifyMessage(bytes calldata messagingProtocolContext, bytes calldata rawMessage) virtual internal returns(bytes32 sourceIdentifier, bytes memory destinationIdentifier, bytes calldata message); + function _verifyPacket(bytes calldata messagingProtocolContext, bytes calldata rawMessage) virtual internal returns(bytes32 sourceIdentifier, bytes memory destinationIdentifier, bytes calldata message); /// @notice Send the message to the messaging protocol. /// @dev Should be overwritten to send a message using the specific messaging protocol. - function _sendMessage(bytes32 destinationIdentifier, bytes memory destinationImplementation, bytes memory message) virtual internal returns(uint128 costOfSendMessageInNativeToken); + function _sendPacket(bytes32 destinationIdentifier, bytes memory destinationImplementation, bytes memory message) virtual internal returns(uint128 costOfsendPacketInNativeToken); /// @notice Generates a unique message identifier for a message @@ -85,11 +85,11 @@ abstract contract IncentivizedMessageEscrow is IIncentivizedMessageEscrow, Bytes // TODO: Not change when set. /// @notice Sets the escrow implementation for a specific chain - function setRemoteEscrowImplementation(bytes32 chainIdentifier, bytes calldata implementation) external { - implementationAddress[msg.sender][chainIdentifier] = implementation; - implementationAddressHash[msg.sender][chainIdentifier] = keccak256(implementation); + function setRemoteImplementation(bytes32 destinationIdentifier, bytes calldata implementation) external { + implementationAddress[msg.sender][destinationIdentifier] = implementation; + implementationAddressHash[msg.sender][destinationIdentifier] = keccak256(implementation); - emit RemoteEscrowSet(msg.sender, chainIdentifier, keccak256(implementation), implementation); + emit RemoteImplementationSet(msg.sender, destinationIdentifier, keccak256(implementation), implementation); } //--- Public Endpoints ---// @@ -140,7 +140,7 @@ abstract contract IncentivizedMessageEscrow is IIncentivizedMessageEscrow, Bytes * @return gasRefund The amount of excess gas which was paid to this call. The app should handle the excess. * @return messageIdentifier An unique identifier for a message. */ - function escrowMessage( + function submitMessage( bytes32 destinationIdentifier, bytes calldata destinationAddress, bytes calldata message, @@ -161,7 +161,7 @@ abstract contract IncentivizedMessageEscrow is IIncentivizedMessageEscrow, Bytes // Add escrow context to the message. bytes memory messageWithContext = abi.encodePacked( - bytes1(CTX_SOURCE_TO_DESTINATION), // This is a sendMessage, + bytes1(CTX_SOURCE_TO_DESTINATION), // This is a sendPacket, messageIdentifier, // An unique identifier to recover identifier to recover convertEVMTo65(msg.sender), // Original sender destinationAddress, // The address to deliver the (original) message to. @@ -180,13 +180,13 @@ abstract contract IncentivizedMessageEscrow is IIncentivizedMessageEscrow, Bytes // Send message to messaging protocol // This call will collect payments for sending the message. It can be in any token but if it is in // native gas, it should return the amount it took. - uint128 costOfSendMessageInNativeToken = _sendMessage( + uint128 costOfsendPacketInNativeToken = _sendPacket( destinationIdentifier, destinationImplementation, messageWithContext ); // Add the cost of the send message. - sum += costOfSendMessageInNativeToken; + sum += costOfsendPacketInNativeToken; // Check that the provided gas is sufficient. The refund will be sent later. if (msg.value < sum) revert NotEnoughGasProvided(sum, uint128(msg.value)); @@ -210,14 +210,14 @@ abstract contract IncentivizedMessageEscrow is IIncentivizedMessageEscrow, Bytes * Please ensure that feeRecipitent can receive gas token: Either it is an EOA or a implement fallback() / receive(). * Likewise for any non-evm chains. Otherwise the message fails (ack) or the relay payment is lost (call). * You need to pass in incentive.maxGas(Delivery|Ack) + messaging protocol dependent buffer, otherwise this call might fail. - * On Receive implementations make _verifyMessage revert. The result is + * On Receive implementations make _verifyPacket revert. The result is * that this endpoint is disabled. * @param messagingProtocolContext Additional context required to verify the message by the messaging protocol. * @param rawMessage The raw message as it was emitted. * @param feeRecipitent An identifier for the the fee recipitent. The identifier should identify the relayer on the source chain. * For EVM (and this contract as a source), use the bytes32 encoded address. For other VMs you might have to register your address. */ - function processMessage( + function processPacket( bytes calldata messagingProtocolContext, bytes calldata rawMessage, bytes32 feeRecipitent @@ -225,15 +225,15 @@ abstract contract IncentivizedMessageEscrow is IIncentivizedMessageEscrow, Bytes uint256 gasLimit = gasleft(); // uint256 is used here instead of uint48, since there is no advantage to uint48 until after we calculate the difference. // Verify that the message is authentic and remove potential context that the messaging protocol added to the message. - (bytes32 chainIdentifier, bytes memory implementationIdentifier, bytes calldata message) = _verifyMessage(messagingProtocolContext, rawMessage); + (bytes32 chainIdentifier, bytes memory implementationIdentifier, bytes calldata message) = _verifyPacket(messagingProtocolContext, rawMessage); // Figure out if this is a call or an ack. bytes1 context = bytes1(message[0]); if (context == CTX_SOURCE_TO_DESTINATION) { - bytes memory ackMessageWithContext = _handleCall(chainIdentifier, implementationIdentifier, message, feeRecipitent, gasLimit); + bytes memory receiveAckWithContext = _handleMessage(chainIdentifier, implementationIdentifier, message, feeRecipitent, gasLimit); - // The cost management is made by _sendMessage so we don't have to check if enough gas has been provided. - _sendMessage(chainIdentifier, implementationIdentifier, ackMessageWithContext); + // The cost management is made by _sendPacket so we don't have to check if enough gas has been provided. + _sendPacket(chainIdentifier, implementationIdentifier, receiveAckWithContext); } else if (context == CTX_DESTINATION_TO_SOURCE) { _handleAck(chainIdentifier, implementationIdentifier, message, feeRecipitent, gasLimit); } else { @@ -246,7 +246,7 @@ abstract contract IncentivizedMessageEscrow is IIncentivizedMessageEscrow, Bytes /** * @notice Handles call messages. */ - function _handleCall(bytes32 sourceIdentifier, bytes memory sourceImplementationIdentifier, bytes calldata message, bytes32 feeRecipitent, uint256 gasLimit) internal returns(bytes memory ackMessageWithContext) { + function _handleMessage(bytes32 sourceIdentifier, bytes memory sourceImplementationIdentifier, bytes calldata message, bytes32 feeRecipitent, uint256 gasLimit) internal returns(bytes memory receiveAckWithContext) { // Ensure message is unique and can only be execyted once bytes32 messageIdentifier = bytes32(message[MESSAGE_IDENTIFIER_START:MESSAGE_IDENTIFIER_END]); @@ -298,8 +298,8 @@ abstract contract IncentivizedMessageEscrow is IIncentivizedMessageEscrow, Bytes // Encode a new message to send back. This lets the relayer claim their payment. - ackMessageWithContext = abi.encodePacked( - bytes1(CTX_DESTINATION_TO_SOURCE), // This is a sendMessage + receiveAckWithContext = abi.encodePacked( + bytes1(CTX_DESTINATION_TO_SOURCE), // This is a sendPacket messageIdentifier, // message identifier fromApplication, feeRecipitent, @@ -311,13 +311,13 @@ abstract contract IncentivizedMessageEscrow is IIncentivizedMessageEscrow, Bytes // Message has been delivered and shouldn't be executed again. emit MessageDelivered(messageIdentifier); - // Why is the messageDelivered event emitted before _sendMessage? + // Why is the messageDelivered event emitted before _sendPacket? // Because it lets us pop messageIdentifier from the stack. This avoid a stack limit reached error. // Not optimal but okay-ish. // Send message to messaging protocol - // This is done on processMessage. - // This is done by returning ackMessageWithContext while source identifier and sourceImplementationIdentifier are known. + // This is done on processPacket. + // This is done by returning receiveAckWithContext while source identifier and sourceImplementationIdentifier are known. } /** @@ -352,7 +352,7 @@ abstract contract IncentivizedMessageEscrow is IIncentivizedMessageEscrow, Bytes // Ensure that if the call reverts it doesn't boil up. // We don't need any return values and don't care if the call reverts. // This call implies we need reentry protection. - bytes memory payload = abi.encodeWithSignature("ackMessage(bytes32,bytes32,bytes)", destinationIdentifier, messageIdentifier, message[CTX1_MESSAGE_START: ]); + bytes memory payload = abi.encodeWithSignature("receiveAck(bytes32,bytes32,bytes)", destinationIdentifier, messageIdentifier, message[CTX1_MESSAGE_START: ]); assembly ("memory-safe") { // Because Solidity always create RETURNDATACOPY for external calls, even low-level calls where no variables are assigned, // the contract can be attacked by a so called return bomb. This incur additional cost to the relayer they aren't paid for. @@ -360,7 +360,7 @@ abstract contract IncentivizedMessageEscrow is IIncentivizedMessageEscrow, Bytes let success := call(maxGasAck, fromApplication, 0, add(payload, 0x20), mload(payload), 0, 0) // This is what the call would look like non-assembly. // fromApplication.call{gas: maxGasAck}( - // abi.encodeWithSignature("ackMessage(bytes32,bytes32,bytes)", destinationIdentifier, messageIdentifier, message[CTX1_MESSAGE_START: ]) + // abi.encodeWithSignature("receiveAck(bytes32,bytes32,bytes)", destinationIdentifier, messageIdentifier, message[CTX1_MESSAGE_START: ]) // ); } @@ -508,7 +508,7 @@ abstract contract IncentivizedMessageEscrow is IIncentivizedMessageEscrow, Bytes bytes calldata messagingProtocolContext, bytes calldata rawMessage ) external { - (bytes32 chainIdentifier, bytes memory implementationIdentifier, bytes calldata message) = _verifyMessage(messagingProtocolContext, rawMessage); + (bytes32 chainIdentifier, bytes memory implementationIdentifier, bytes calldata message) = _verifyPacket(messagingProtocolContext, rawMessage); bytes1 context = bytes1(message[0]); @@ -524,7 +524,7 @@ abstract contract IncentivizedMessageEscrow is IIncentivizedMessageEscrow, Bytes bytes32 expectedDestinationImplementationHash = implementationAddressHash[msg.sender][chainIdentifier]; if (expectedDestinationImplementationHash != keccak256(implementationIdentifier)) revert InvalidImplementationAddress(); - ICrossChainReceiver(fromApplication).ackMessage(chainIdentifier, messageIdentifier, message[CTX1_MESSAGE_START: ]); + ICrossChainReceiver(fromApplication).receiveAck(chainIdentifier, messageIdentifier, message[CTX1_MESSAGE_START: ]); emit MessageAcked(messageIdentifier); } else { diff --git a/src/TimeoutExtension.sol b/src/TimeoutExtension.sol index 2a0c066..4699897 100644 --- a/src/TimeoutExtension.sol +++ b/src/TimeoutExtension.sol @@ -43,7 +43,7 @@ abstract contract IMETimeoutExtension is IncentivizedMessageEscrow { // We don't need any return values and don't care if the call reverts. // This call implies we need reentry protection, since we need to call it before we delete the incentive map. fromApplication.call{gas: maxGasAck}( - abi.encodeWithSignature("ackMessage(bytes32,bytes32,bytes)", destinationIdentifier, messageIdentifier, abi.encodePacked(bytes1(0xff), message[CTX1_MESSAGE_START: ])) + abi.encodeWithSignature("receiveAck(bytes32,bytes32,bytes)", destinationIdentifier, messageIdentifier, abi.encodePacked(bytes1(0xff), message[CTX1_MESSAGE_START: ])) ); // Set the gas used on the destination to 15% diff --git a/src/apps/mock/IncentivizedMockEscrow.sol b/src/apps/mock/IncentivizedMockEscrow.sol index e69e3c1..edf0f1f 100644 --- a/src/apps/mock/IncentivizedMockEscrow.sol +++ b/src/apps/mock/IncentivizedMockEscrow.sol @@ -44,7 +44,7 @@ contract IncentivizedMockEscrow is IncentivizedMessageEscrow, Ownable2Step { ); } - function _verifyMessage(bytes calldata _metadata, bytes calldata _message) internal view override returns(bytes32 sourceIdentifier, bytes memory implementationIdentifier, bytes calldata message_) { + function _verifyPacket(bytes calldata _metadata, bytes calldata _message) internal view override returns(bytes32 sourceIdentifier, bytes memory implementationIdentifier, bytes calldata message_) { // Get signature from message payload (uint8 v, bytes32 r, bytes32 s) = abi.decode(_metadata, (uint8, bytes32, bytes32)); @@ -71,7 +71,7 @@ contract IncentivizedMockEscrow is IncentivizedMessageEscrow, Ownable2Step { message_ = _message[96:]; } - function _sendMessage(bytes32 destinationChainIdentifier, bytes memory destinationImplementation, bytes memory message) internal override returns(uint128 costOfSendMessageInNativeToken) { + function _sendPacket(bytes32 destinationChainIdentifier, bytes memory destinationImplementation, bytes memory message) internal override returns(uint128 costOfsendPacketInNativeToken) { emit Message( destinationChainIdentifier, destinationImplementation, @@ -86,6 +86,6 @@ contract IncentivizedMockEscrow is IncentivizedMessageEscrow, Ownable2Step { if (msg.value < verificationCost) revert NotEnoughGasProvidedForVerification(); accumulator += verificationCost; } - return costOfSendMessageInNativeToken = uint128(verificationCost); + return costOfsendPacketInNativeToken = uint128(verificationCost); } } \ No newline at end of file diff --git a/src/apps/mock/OnRecvIncentivizedMockEscrow.sol b/src/apps/mock/OnRecvIncentivizedMockEscrow.sol index d61b2fa..82cb860 100644 --- a/src/apps/mock/OnRecvIncentivizedMockEscrow.sol +++ b/src/apps/mock/OnRecvIncentivizedMockEscrow.sol @@ -52,7 +52,7 @@ contract OnRecvIncentivizedMockEscrow is IMETimeoutExtension { ); } - function _verifyMessage(bytes calldata /* _metadata */, bytes calldata _message) internal view override returns (bytes32 sourceIdentifier, bytes memory implementationIdentifier, bytes calldata message_) { + function _verifyPacket(bytes calldata /* _metadata */, bytes calldata _message) internal view override returns (bytes32 sourceIdentifier, bytes memory implementationIdentifier, bytes calldata message_) { sourceIdentifier = isVerifiedMessageHash[keccak256(_message)].chainIdentifier; implementationIdentifier = isVerifiedMessageHash[keccak256(_message)].implementationIdentifier; @@ -65,7 +65,7 @@ contract OnRecvIncentivizedMockEscrow is IMETimeoutExtension { /// @dev This is an example of how this function can be disabled. /// This doesn't have to be how it is done. This implementation works /// fine with and without (There is even a test for that). - function processMessage( + function processPacket( bytes calldata /* messagingProtocolContext */, bytes calldata /* rawMessage */, bytes32 /* feeRecipitent */ @@ -81,12 +81,12 @@ contract OnRecvIncentivizedMockEscrow is IMETimeoutExtension { ) onlyMessagingProtocol external { // _onReceive(chainIdentifier, rawMessage, feeRecipitent); uint256 gasLimit = gasleft(); - bytes memory ackMessage = _handleCall(chainIdentifier, sourceImplementationIdentifier, rawMessage, feeRecipitent, gasLimit); + bytes memory receiveAck = _handleMessage(chainIdentifier, sourceImplementationIdentifier, rawMessage, feeRecipitent, gasLimit); // Send ack: - _sendMessage(chainIdentifier, sourceImplementationIdentifier, ackMessage); - // * For an actual implementation, the _sendMessage might also be implemented as a return value for onReceive like: - // * return ReturnStruct?({chainIdentifier: chainIdentifier, message: ackMessage}); + _sendPacket(chainIdentifier, sourceImplementationIdentifier, receiveAck); + // * For an actual implementation, the _sendPacket might also be implemented as a return value for onReceive like: + // * return ReturnStruct?({chainIdentifier: chainIdentifier, message: receiveAck}); } // The escrow manages acks, so any message can be directly provided to _onReceive. @@ -115,8 +115,8 @@ contract OnRecvIncentivizedMockEscrow is IMETimeoutExtension { } // * Send to messaging_protocol - function _sendMessage(bytes32 destinationChainIdentifier, bytes memory destinationImplementation, bytes memory message) internal override returns(uint128 costOfSendMessageInNativeToken) { - MockOnRecvAMB(MESSAGING_PROTOCOL_CALLER).sendMessage( + function _sendPacket(bytes32 destinationChainIdentifier, bytes memory destinationImplementation, bytes memory message) internal override returns(uint128 costOfsendPacketInNativeToken) { + MockOnRecvAMB(MESSAGING_PROTOCOL_CALLER).sendPacket( destinationChainIdentifier, destinationImplementation, abi.encodePacked( diff --git a/src/apps/wormhole/IncentivizedWormholeEscrow.sol b/src/apps/wormhole/IncentivizedWormholeEscrow.sol index 1f8eae2..6997479 100644 --- a/src/apps/wormhole/IncentivizedWormholeEscrow.sol +++ b/src/apps/wormhole/IncentivizedWormholeEscrow.sol @@ -41,7 +41,7 @@ contract IncentivizedWormholeEscrow is IncentivizedMessageEscrow, WormholeVerifi ); } - function _verifyMessage(bytes calldata _metadata, bytes calldata _message) internal view override returns(bytes32 sourceIdentifier, bytes memory implementationIdentifier, bytes calldata message_) { + function _verifyPacket(bytes calldata _metadata, bytes calldata _message) internal view override returns(bytes32 sourceIdentifier, bytes memory implementationIdentifier, bytes calldata message_) { ( SmallStructs.SmallVM memory vm, @@ -68,15 +68,15 @@ contract IncentivizedWormholeEscrow is IncentivizedMessageEscrow, WormholeVerifi message_ = payload[32:]; } - function _sendMessage(bytes32 destinationChainIdentifier, bytes memory destinationImplementation, bytes memory message) internal override returns(uint128 costOfSendMessageInNativeToken) { + function _sendPacket(bytes32 destinationChainIdentifier, bytes memory destinationImplementation, bytes memory message) internal override returns(uint128 costOfsendPacketInNativeToken) { // Get the cost of sending wormhole messages. - costOfSendMessageInNativeToken = uint128(WORMHOLE.messageFee()); + costOfsendPacketInNativeToken = uint128(WORMHOLE.messageFee()); // Emit context for relayers so they know where to send the message emit WormholeMessage(destinationChainIdentifier, destinationImplementation); // Handoff the message to wormhole. - WORMHOLE.publishMessage{value: costOfSendMessageInNativeToken}( + WORMHOLE.publishMessage{value: costOfsendPacketInNativeToken}( 0, abi.encodePacked( destinationChainIdentifier, diff --git a/src/interfaces/ICrossChainReceiver.sol b/src/interfaces/ICrossChainReceiver.sol index 2151bbd..f4b8878 100644 --- a/src/interfaces/ICrossChainReceiver.sol +++ b/src/interfaces/ICrossChainReceiver.sol @@ -12,12 +12,12 @@ interface ICrossChainReceiver { * This identifier can be mismanaged by the messaging protocol. * @param acknowledgement The acknowledgement sent back by receiveMessage. Is 0xff if receiveMessage reverted. */ - function ackMessage(bytes32 destinationIdentifier, bytes32 messageIdentifier, bytes calldata acknowledgement) external; + function receiveAck(bytes32 destinationIdentifier, bytes32 messageIdentifier, bytes calldata acknowledgement) external; /** * @notice receiveMessage from a cross-chain call. * @dev The application needs to check the fromApplication combined with sourceIdentifierbytes to figure out if the call is authenticated. - * @return acknowledgement Information which is passed to ackMessage. + * @return acknowledgement Information which is passed to receiveAck. * If you return 0xff, you cannot know the difference between Executed but "failed" and outright failed. */ function receiveMessage(bytes32 sourceIdentifierbytes, bytes32 messageIdentifier, bytes calldata fromApplication, bytes calldata message) external returns(bytes memory acknowledgement); diff --git a/src/interfaces/IIncentivizedMessageEscrow.sol b/src/interfaces/IIncentivizedMessageEscrow.sol index 5f90246..f452063 100644 --- a/src/interfaces/IIncentivizedMessageEscrow.sol +++ b/src/interfaces/IIncentivizedMessageEscrow.sol @@ -18,16 +18,16 @@ interface IIncentivizedMessageEscrow is IMessageEscrowStructs, IMessageEscrowErr uint96 priceOfAckGas ) external payable; - function escrowMessage( + function submitMessage( bytes32 destinationIdentifier, bytes calldata destinationAddress, bytes calldata message, IncentiveDescription calldata incentive ) external payable returns(uint256 gasRefund, bytes32 messageIdentifier); - function processMessage(bytes calldata messagingProtocolContext, bytes calldata message, bytes32 feeRecipitent) payable external; + function processPacket(bytes calldata messagingProtocolContext, bytes calldata message, bytes32 feeRecipitent) payable external; - function setRemoteEscrowImplementation(bytes32 chainIdentifier, bytes calldata implementation) external; + function setRemoteImplementation(bytes32 chainIdentifier, bytes calldata implementation) external; /** * @notice Estimates the additional cost to the messaging router to validate the message diff --git a/src/interfaces/IMessageEscrowEvents.sol b/src/interfaces/IMessageEscrowEvents.sol index de4479e..a19e0f8 100644 --- a/src/interfaces/IMessageEscrowEvents.sol +++ b/src/interfaces/IMessageEscrowEvents.sol @@ -29,5 +29,5 @@ interface IMessageEscrowEvents { ); - event RemoteEscrowSet(address application, bytes32 chainIdentifier, bytes32 implementationAddressHash, bytes implementationAddress); + event RemoteImplementationSet(address application, bytes32 chainIdentifier, bytes32 implementationAddressHash, bytes implementationAddress); } \ No newline at end of file diff --git a/test/IncentivizedMessageEscrow/escrowMessage/EscrowMessage.t.sol b/test/IncentivizedMessageEscrow/escrowMessage/EscrowMessage.t.sol index 4a24a69..432bef4 100644 --- a/test/IncentivizedMessageEscrow/escrowMessage/EscrowMessage.t.sol +++ b/test/IncentivizedMessageEscrow/escrowMessage/EscrowMessage.t.sol @@ -9,7 +9,7 @@ contract EscrowInformationTest is TestCommon { function test_check_escrow_state() public { IncentiveDescription storage incentive = _INCENTIVE; - (, bytes32 messageIdentifier) = escrow.escrowMessage{value: _getTotalIncentive(_INCENTIVE)}( + (, bytes32 messageIdentifier) = escrow.submitMessage{value: _getTotalIncentive(_INCENTIVE)}( bytes32(uint256(0x123123) + uint256(2**255)), _DESTINATION_ADDRESS_THIS, _MESSAGE, @@ -33,7 +33,7 @@ contract EscrowInformationTest is TestCommon { vm.expectEmit(); emit BountyPlaced(bytes32(0x2dfdcf3ed929fb394f4f06ccf6d75629926d36dc4409186a42a5904a2f80d74d), incentive); - escrow.escrowMessage{value: _getTotalIncentive(_INCENTIVE)}( + escrow.submitMessage{value: _getTotalIncentive(_INCENTIVE)}( bytes32(uint256(0x123123) + uint256(2**255)), _DESTINATION_ADDRESS_THIS, _MESSAGE, @@ -48,7 +48,7 @@ contract EscrowInformationTest is TestCommon { _overpay = overpay; - (uint256 gasRefund, ) = escrow.escrowMessage{value: _getTotalIncentive(_INCENTIVE) + overpay}( + (uint256 gasRefund, ) = escrow.submitMessage{value: _getTotalIncentive(_INCENTIVE) + overpay}( bytes32(uint256(0x123123) + uint256(2**255)), _DESTINATION_ADDRESS_THIS, _MESSAGE, diff --git a/test/IncentivizedMessageEscrow/escrowMessage/MessageIdentifier.t.sol b/test/IncentivizedMessageEscrow/escrowMessage/MessageIdentifier.t.sol index 4801c8c..e0cac31 100644 --- a/test/IncentivizedMessageEscrow/escrowMessage/MessageIdentifier.t.sol +++ b/test/IncentivizedMessageEscrow/escrowMessage/MessageIdentifier.t.sol @@ -9,7 +9,7 @@ contract MessageIdentifierTest is TestCommon { function test_unique_identifier_block_10() public { vm.roll(10); IncentiveDescription storage incentive = _INCENTIVE; - (, bytes32 messageIdentifier) = escrow.escrowMessage{value: _getTotalIncentive(_INCENTIVE)}( + (, bytes32 messageIdentifier) = escrow.submitMessage{value: _getTotalIncentive(_INCENTIVE)}( _DESTINATION_IDENTIFIER, _DESTINATION_ADDRESS_THIS, _MESSAGE, @@ -22,7 +22,7 @@ contract MessageIdentifierTest is TestCommon { function test_unique_identifier_block_11() public { vm.roll(11); IncentiveDescription storage incentive = _INCENTIVE; - (, bytes32 messageIdentifier) = escrow.escrowMessage{value: _getTotalIncentive(_INCENTIVE)}( + (, bytes32 messageIdentifier) = escrow.submitMessage{value: _getTotalIncentive(_INCENTIVE)}( _DESTINATION_IDENTIFIER, _DESTINATION_ADDRESS_THIS, _MESSAGE, @@ -35,7 +35,7 @@ contract MessageIdentifierTest is TestCommon { // Even with the same message, the identifier should be different between blocks. function test_non_unique_bounty(bytes calldata message) public { IncentiveDescription storage incentive = _INCENTIVE; - escrow.escrowMessage{value: _getTotalIncentive(_INCENTIVE)}( + escrow.submitMessage{value: _getTotalIncentive(_INCENTIVE)}( _DESTINATION_IDENTIFIER, _DESTINATION_ADDRESS_THIS, message, @@ -45,7 +45,7 @@ contract MessageIdentifierTest is TestCommon { vm.expectRevert( abi.encodeWithSignature("MessageAlreadyBountied()") ); - escrow.escrowMessage{value: _getTotalIncentive(_INCENTIVE)}( + escrow.submitMessage{value: _getTotalIncentive(_INCENTIVE)}( _DESTINATION_IDENTIFIER, _DESTINATION_ADDRESS_THIS, message, @@ -57,18 +57,18 @@ contract MessageIdentifierTest is TestCommon { function test_destination_identifier_impacts_message_identifier() public { IncentiveDescription storage incentive = _INCENTIVE; - escrow.setRemoteEscrowImplementation(bytes32(uint256(_DESTINATION_IDENTIFIER) + uint256(1)), abi.encode(address(escrow))); + escrow.setRemoteImplementation(bytes32(uint256(_DESTINATION_IDENTIFIER) + uint256(1)), abi.encode(address(escrow))); - (, bytes32 messageIdentifier1) = escrow.escrowMessage{value: _getTotalIncentive(_INCENTIVE)}( + (, bytes32 messageIdentifier1) = escrow.submitMessage{value: _getTotalIncentive(_INCENTIVE)}( bytes32(uint256(_DESTINATION_IDENTIFIER) + uint256(1)), _DESTINATION_ADDRESS_THIS, _MESSAGE, incentive ); - escrow.setRemoteEscrowImplementation(bytes32(uint256(_DESTINATION_IDENTIFIER) + uint256(2)), abi.encode(address(escrow))); + escrow.setRemoteImplementation(bytes32(uint256(_DESTINATION_IDENTIFIER) + uint256(2)), abi.encode(address(escrow))); - (, bytes32 messageIdentifier2) = escrow.escrowMessage{value: _getTotalIncentive(_INCENTIVE)}( + (, bytes32 messageIdentifier2) = escrow.submitMessage{value: _getTotalIncentive(_INCENTIVE)}( bytes32(uint256(_DESTINATION_IDENTIFIER) + uint256(2)), _DESTINATION_ADDRESS_THIS, _MESSAGE, diff --git a/test/IncentivizedMessageEscrow/escrowMessage/NoRemoteImplementation.t.sol b/test/IncentivizedMessageEscrow/escrowMessage/NoRemoteImplementation.t.sol index 7919725..90468da 100644 --- a/test/IncentivizedMessageEscrow/escrowMessage/NoRemoteImplementation.t.sol +++ b/test/IncentivizedMessageEscrow/escrowMessage/NoRemoteImplementation.t.sol @@ -14,7 +14,7 @@ contract NoImplementationAddressSetTest is TestCommon { vm.expectRevert( abi.encodeWithSignature("NoImplementationAddressSet()") ); - applicationWithNoImplementationAddress.escrowMessage{value: _getTotalIncentive(_INCENTIVE)}( + applicationWithNoImplementationAddress.submitMessage{value: _getTotalIncentive(_INCENTIVE)}( _DESTINATION_IDENTIFIER, _DESTINATION_ADDRESS_THIS, _MESSAGE, diff --git a/test/IncentivizedMessageEscrow/escrowMessage/WrongGasPayment.t.sol b/test/IncentivizedMessageEscrow/escrowMessage/WrongGasPayment.t.sol index 26f5b19..9e1b158 100644 --- a/test/IncentivizedMessageEscrow/escrowMessage/WrongGasPayment.t.sol +++ b/test/IncentivizedMessageEscrow/escrowMessage/WrongGasPayment.t.sol @@ -15,7 +15,7 @@ contract EscrowWrongGasPaymentTest is TestCommon { priceOfAckGas: 321123, targetDelta: 30 minutes }); - escrow.escrowMessage{value: _getTotalIncentive(incentive)}( + escrow.submitMessage{value: _getTotalIncentive(incentive)}( _DESTINATION_IDENTIFIER, _DESTINATION_ADDRESS_THIS, _MESSAGE, @@ -36,7 +36,7 @@ contract EscrowWrongGasPaymentTest is TestCommon { // vm.expectRevert( // abi.encodeWithSignature("ZeroIncentiveNotAllowed()") // ); - // escrow.escrowMessage{value: _getTotalIncentive(incentive)}( + // escrow.submitMessage{value: _getTotalIncentive(incentive)}( // _DESTINATION_IDENTIFIER, // _DESTINATION_ADDRESS_THIS, // _MESSAGE, @@ -57,7 +57,7 @@ contract EscrowWrongGasPaymentTest is TestCommon { vm.expectRevert( abi.encodeWithSignature("NotEnoughGasProvided(uint128,uint128)", _getTotalIncentive(incentive), _getTotalIncentive(incentive) - error) ); - escrow.escrowMessage{value: _getTotalIncentive(incentive) - error}( + escrow.submitMessage{value: _getTotalIncentive(incentive) - error}( _DESTINATION_IDENTIFIER, _DESTINATION_ADDRESS_THIS, _MESSAGE, diff --git a/test/IncentivizedMessageEscrow/feature/SendMessagePayment.t.sol b/test/IncentivizedMessageEscrow/feature/SendMessagePayment.t.sol index 65c2cc8..32764db 100644 --- a/test/IncentivizedMessageEscrow/feature/SendMessagePayment.t.sol +++ b/test/IncentivizedMessageEscrow/feature/SendMessagePayment.t.sol @@ -10,7 +10,7 @@ import { IMessageEscrowStructs } from "../../../src/interfaces/IMessageEscrowStr import "./../../mocks/MockApplication.sol"; import { ICrossChainReceiver } from "../../../src/interfaces/ICrossChainReceiver.sol"; -contract SendMessagePaymentTest is TestCommon { +contract sendPacketPaymentTest is TestCommon { uint128 constant SEND_MESSAGE_PAYMENT_COST = 10_000; @@ -32,10 +32,10 @@ contract SendMessagePaymentTest is TestCommon { // Set implementations to the escrow address. vm.prank(address(application)); - escrow.setRemoteEscrowImplementation(_DESTINATION_IDENTIFIER, abi.encode(address(escrow))); + escrow.setRemoteImplementation(_DESTINATION_IDENTIFIER, abi.encode(address(escrow))); vm.prank(address(this)); - escrow.setRemoteEscrowImplementation(_DESTINATION_IDENTIFIER, abi.encode(address(escrow))); + escrow.setRemoteImplementation(_DESTINATION_IDENTIFIER, abi.encode(address(escrow))); _MESSAGE = abi.encode(keccak256(abi.encode(1))); _DESTINATION_ADDRESS_THIS = abi.encodePacked( @@ -68,7 +68,7 @@ contract SendMessagePaymentTest is TestCommon { function test_send_message_with_additional_cost() external { IncentiveDescription storage incentive = _INCENTIVE; - (, bytes32 messageIdentifier) = escrow.escrowMessage{value: _getTotalIncentive(_INCENTIVE) + SEND_MESSAGE_PAYMENT_COST}( + (, bytes32 messageIdentifier) = escrow.submitMessage{value: _getTotalIncentive(_INCENTIVE) + SEND_MESSAGE_PAYMENT_COST}( bytes32(uint256(0x123123) + uint256(2**255)), _DESTINATION_ADDRESS_THIS, _MESSAGE, @@ -95,7 +95,7 @@ contract SendMessagePaymentTest is TestCommon { 529440925002 ) ); - (, bytes32 messageIdentifier) = escrow.escrowMessage{value: _getTotalIncentive(_INCENTIVE) + SEND_MESSAGE_PAYMENT_COST - 1}( + (, bytes32 messageIdentifier) = escrow.submitMessage{value: _getTotalIncentive(_INCENTIVE) + SEND_MESSAGE_PAYMENT_COST - 1}( bytes32(uint256(0x123123) + uint256(2**255)), _DESTINATION_ADDRESS_THIS, _MESSAGE, @@ -114,7 +114,7 @@ contract SendMessagePaymentTest is TestCommon { } function test_process_message_with_additional_payment(bytes calldata message) external { - (, bytes memory messageWithContext) = setupEscrowMessage(address(application), message); + (, bytes memory messageWithContext) = setupsubmitMessage(address(application), message); bytes32 feeRecipitent = bytes32(uint256(uint160(address(this)))); (uint8 v, bytes32 r, bytes32 s) = signMessageForMock(messageWithContext); @@ -122,7 +122,7 @@ contract SendMessagePaymentTest is TestCommon { abi.encode(keccak256(bytes.concat(message, _DESTINATION_ADDRESS_APPLICATION))); - escrow.processMessage{value: SEND_MESSAGE_PAYMENT_COST}( + escrow.processPacket{value: SEND_MESSAGE_PAYMENT_COST}( mockContext, messageWithContext, feeRecipitent @@ -130,7 +130,7 @@ contract SendMessagePaymentTest is TestCommon { } function test_process_message_without_additional_payment(bytes calldata message) external { - (, bytes memory messageWithContext) = setupEscrowMessage(address(application), message); + (, bytes memory messageWithContext) = setupsubmitMessage(address(application), message); bytes32 feeRecipitent = bytes32(uint256(uint160(address(this)))); (uint8 v, bytes32 r, bytes32 s) = signMessageForMock(messageWithContext); @@ -143,7 +143,7 @@ contract SendMessagePaymentTest is TestCommon { "NotEnoughGasProvidedForVerification()" ) ); - escrow.processMessage{value: SEND_MESSAGE_PAYMENT_COST - 1}( + escrow.processPacket{value: SEND_MESSAGE_PAYMENT_COST - 1}( mockContext, messageWithContext, feeRecipitent diff --git a/test/IncentivizedMessageEscrow/increaseBounty/IncreaseBounty.t.sol b/test/IncentivizedMessageEscrow/increaseBounty/IncreaseBounty.t.sol index f46eeba..5d9f696 100644 --- a/test/IncentivizedMessageEscrow/increaseBounty/IncreaseBounty.t.sol +++ b/test/IncentivizedMessageEscrow/increaseBounty/IncreaseBounty.t.sol @@ -8,7 +8,7 @@ contract IncreaseBountyTest is TestCommon { function test_fail_bounty_does_not_exist() public { // Do not escrow the message - // bytes32 messageIdentifier = escrowMessage(_MESSAGE); + // bytes32 messageIdentifier = submitMessage(_MESSAGE); vm.expectRevert( abi.encodeWithSignature("MessageDoesNotExist()") @@ -21,7 +21,7 @@ contract IncreaseBountyTest is TestCommon { } function test_no_increase_escrow() public { - bytes32 messageIdentifier = escrowMessage(_MESSAGE); + bytes32 messageIdentifier = submitMessage(_MESSAGE); escrow.increaseBounty{value: 0}( messageIdentifier, @@ -33,7 +33,7 @@ contract IncreaseBountyTest is TestCommon { function test_fail_overpay() public { uint128 overPay = 1; - bytes32 messageIdentifier = escrowMessage(_MESSAGE); + bytes32 messageIdentifier = submitMessage(_MESSAGE); vm.expectRevert( abi.encodeWithSignature("IncorrectValueProvided(uint128,uint128)", 0, overPay) @@ -51,7 +51,7 @@ contract IncreaseBountyTest is TestCommon { uint64 increaseAck = 123123; uint64 increaseDelivery = 321321; - bytes32 messageIdentifier = escrowMessage(_MESSAGE); + bytes32 messageIdentifier = submitMessage(_MESSAGE); uint128 deliveryGas = _INCENTIVE.maxGasDelivery * increaseDelivery; uint128 ackGas = _INCENTIVE.maxGasAck * increaseAck; @@ -75,7 +75,7 @@ contract IncreaseBountyTest is TestCommon { uint64 increaseAck = 123123; uint64 increaseDelivery = 321321; - bytes32 messageIdentifier = escrowMessage(_MESSAGE); + bytes32 messageIdentifier = submitMessage(_MESSAGE); uint128 deliveryGas = _INCENTIVE.maxGasDelivery * increaseDelivery; uint128 ackGas = _INCENTIVE.maxGasAck * increaseAck; diff --git a/test/IncentivizedMessageEscrow/processMessage/GasSpendControl.sol b/test/IncentivizedMessageEscrow/processMessage/GasSpendControl.sol index 9fb9bab..092f4e7 100644 --- a/test/IncentivizedMessageEscrow/processMessage/GasSpendControl.sol +++ b/test/IncentivizedMessageEscrow/processMessage/GasSpendControl.sol @@ -23,7 +23,7 @@ contract GasSpendControlTest is TestCommon { // Set implementations to the escrow address. vm.prank(address(application)); - escrow.setRemoteEscrowImplementation(_DESTINATION_IDENTIFIER, abi.encode(address(escrow))); + escrow.setRemoteImplementation(_DESTINATION_IDENTIFIER, abi.encode(address(escrow))); _DESTINATION_ADDRESS_APPLICATION = abi.encodePacked( uint8(20), @@ -39,7 +39,7 @@ contract GasSpendControlTest is TestCommon { _INCENTIVE.maxGasDelivery = 193010; // This is not enough gas to execute the receiveCall. We should expect the sub-call to revert but the main call shouldn't. - (bytes32 messageIdentifier, bytes memory messageWithContext) = setupEscrowMessage(address(application), message); + (bytes32 messageIdentifier, bytes memory messageWithContext) = setupsubmitMessage(address(application), message); (uint8 v, bytes32 r, bytes32 s) = signMessageForMock(messageWithContext); bytes memory mockContext = abi.encode(v, r, s); @@ -65,7 +65,7 @@ contract GasSpendControlTest is TestCommon { ) ); - escrow.processMessage( + escrow.processPacket( mockContext, messageWithContext, destinationFeeRecipitent @@ -83,7 +83,7 @@ contract GasSpendControlTest is TestCommon { (uint8 v, bytes32 r, bytes32 s) = signMessageForMock(messageWithContext); bytes memory mockContext = abi.encode(v, r, s); - escrow.processMessage( + escrow.processPacket( mockContext, messageWithContext, destinationFeeRecipitent @@ -95,7 +95,7 @@ contract GasSpendControlTest is TestCommon { _INCENTIVE.maxGasDelivery = 200000; // This is not enough gas to execute the receiveCall. We should expect the sub-call to revert but the main call shouldn't. - (bytes32 messageIdentifier, bytes memory messageWithContext) = setupEscrowMessage(address(application), abi.encodePacked(bytes2(uint16(1000)))); + (bytes32 messageIdentifier, bytes memory messageWithContext) = setupsubmitMessage(address(application), abi.encodePacked(bytes2(uint16(1000)))); (uint8 v, bytes32 r, bytes32 s) = signMessageForMock(messageWithContext); bytes memory mockContext = abi.encode(v, r, s); @@ -104,7 +104,7 @@ contract GasSpendControlTest is TestCommon { // The strange gas limit of ' + 5000 - 2' here is because is how much is actually spent (read from trace) and + 5000 - 2 is some kind of refund that // the relayer needs to add as extra. (reentry refund) - escrow.processMessage{gas: 239854}( + escrow.processPacket{gas: 239936}( mockContext, messageWithContext, destinationFeeRecipitent @@ -126,7 +126,7 @@ contract GasSpendControlTest is TestCommon { ) ) ); - escrow.processMessage{gas: 239854 - 1}( + escrow.processPacket{gas: 239936 - 1}( mockContext, messageWithContext, destinationFeeRecipitent diff --git a/test/IncentivizedMessageEscrow/processMessage/NoReceive.t.sol b/test/IncentivizedMessageEscrow/processMessage/NoReceive.t.sol index a2b4f3b..6e99e27 100644 --- a/test/IncentivizedMessageEscrow/processMessage/NoReceive.t.sol +++ b/test/IncentivizedMessageEscrow/processMessage/NoReceive.t.sol @@ -7,7 +7,7 @@ import { BadContract } from "../../mocks/BadContract.sol"; import { ICrossChainReceiver } from "../../../src/interfaces/ICrossChainReceiver.sol"; -contract ProcessMessageNoReceiveTest is TestCommon { +contract processPacketNoReceiveTest is TestCommon { event Message( bytes32 destinationIdentifier, bytes recipitent, @@ -19,7 +19,7 @@ contract ProcessMessageNoReceiveTest is TestCommon { application = ICrossChainReceiver(address(new BadContract())); vm.prank(address(application)); - escrow.setRemoteEscrowImplementation(_DESTINATION_IDENTIFIER, abi.encode(address(escrow))); + escrow.setRemoteImplementation(_DESTINATION_IDENTIFIER, abi.encode(address(escrow))); _DESTINATION_ADDRESS_APPLICATION = abi.encodePacked( uint8(20), @@ -32,7 +32,7 @@ contract ProcessMessageNoReceiveTest is TestCommon { bytes memory message = _MESSAGE; bytes32 feeRecipitent = bytes32(uint256(uint160(address(this)))); - (bytes32 messageIdentifier, bytes memory messageWithContext) = setupEscrowMessage(address(escrow), message); + (bytes32 messageIdentifier, bytes memory messageWithContext) = setupsubmitMessage(address(escrow), message); (uint8 v, bytes32 r, bytes32 s) = signMessageForMock(messageWithContext); bytes memory mockContext = abi.encode(v, r, s); @@ -74,7 +74,7 @@ contract ProcessMessageNoReceiveTest is TestCommon { ) ); - escrow.processMessage( + escrow.processPacket( mockContext, messageWithContext, feeRecipitent diff --git a/test/IncentivizedMessageEscrow/processMessage/Reentry.ack.t.sol b/test/IncentivizedMessageEscrow/processMessage/Reentry.ack.t.sol index 13b1c03..98932b1 100644 --- a/test/IncentivizedMessageEscrow/processMessage/Reentry.ack.t.sol +++ b/test/IncentivizedMessageEscrow/processMessage/Reentry.ack.t.sol @@ -39,7 +39,7 @@ contract AckReentryTest is TestCommon, ICrossChainReceiver { vm.expectCall( address(this), abi.encodeCall( - application.ackMessage, + application.receiveAck, ( bytes32(0x8000000000000000000000000000000000000000000000000000000000123123), messageIdentifier, @@ -52,7 +52,7 @@ contract AckReentryTest is TestCommon, ICrossChainReceiver { _messageWithContext = messageWithContext; _feeRecipitent = feeRecipitent; - escrow.processMessage( + escrow.processPacket( mockContext, messageWithContext, feeRecipitent @@ -68,11 +68,11 @@ contract AckReentryTest is TestCommon, ICrossChainReceiver { bool flag; - function ackMessage(bytes32 /* destinationIdentifier */, bytes32 /* messageIdentifier */, bytes calldata acknowledgement) external { + function receiveAck(bytes32 /* destinationIdentifier */, bytes32 /* messageIdentifier */, bytes calldata acknowledgement) external { vm.expectRevert( abi.encodeWithSignature("MessageAlreadyAcked()") ); - escrow.processMessage( + escrow.processPacket( _mockContext, _messageWithContext, _feeRecipitent diff --git a/test/IncentivizedMessageEscrow/processMessage/Reentry.call.t.sol b/test/IncentivizedMessageEscrow/processMessage/Reentry.call.t.sol index c5b7d82..5cadf7c 100644 --- a/test/IncentivizedMessageEscrow/processMessage/Reentry.call.t.sol +++ b/test/IncentivizedMessageEscrow/processMessage/Reentry.call.t.sol @@ -25,7 +25,7 @@ contract CallReentryTest is TestCommon, ICrossChainReceiver { bytes32(uint256(uint160((address(this))))) ); - (bytes32 messageIdentifier, bytes memory messageWithContext) = setupEscrowMessage(address(escrow), message); + (bytes32 messageIdentifier, bytes memory messageWithContext) = setupsubmitMessage(address(escrow), message); (uint8 v, bytes32 r, bytes32 s) = signMessageForMock(messageWithContext); bytes memory mockContext = abi.encode(v, r, s); @@ -61,12 +61,12 @@ contract CallReentryTest is TestCommon, ICrossChainReceiver { messageIdentifier, _DESTINATION_ADDRESS_APPLICATION, feeRecipitent, - uint48(0xffd3), // Gas used + uint48(0x10024), // Gas used uint64(1), uint8(1) ) ); - escrow.processMessage( + escrow.processPacket( mockContext, messageWithContext, feeRecipitent @@ -87,7 +87,7 @@ contract CallReentryTest is TestCommon, ICrossChainReceiver { vm.expectRevert( abi.encodeWithSignature("MessageAlreadySpent()") ); - escrow.processMessage( + escrow.processPacket( _mockContext, _messageWithContext, _feeRecipitent @@ -99,7 +99,7 @@ contract CallReentryTest is TestCommon, ICrossChainReceiver { } // Placeholder - function ackMessage(bytes32 destinationIdentifier, bytes32 messageIdentifier, bytes calldata acknowledgement) external { + function receiveAck(bytes32 destinationIdentifier, bytes32 messageIdentifier, bytes calldata acknowledgement) external { } } \ No newline at end of file diff --git a/test/IncentivizedMessageEscrow/processMessage/ReturnBomb.t.sol b/test/IncentivizedMessageEscrow/processMessage/ReturnBomb.t.sol index db65899..db7356e 100644 --- a/test/IncentivizedMessageEscrow/processMessage/ReturnBomb.t.sol +++ b/test/IncentivizedMessageEscrow/processMessage/ReturnBomb.t.sol @@ -23,7 +23,7 @@ contract ReturnBombTest is TestCommon { // Set implementations to the escrow address. vm.prank(address(application)); - escrow.setRemoteEscrowImplementation(_DESTINATION_IDENTIFIER, abi.encode(address(escrow))); + escrow.setRemoteImplementation(_DESTINATION_IDENTIFIER, abi.encode(address(escrow))); _DESTINATION_ADDRESS_APPLICATION = abi.encodePacked( uint8(20), @@ -45,7 +45,7 @@ contract ReturnBombTest is TestCommon { bytes memory mockContext = abi.encode(v, r, s); uint256 beforeReturnBomb = gasleft(); - escrow.processMessage( + escrow.processPacket( mockContext, messageWithContext, destinationFeeRecipitent diff --git a/test/IncentivizedMessageEscrow/processMessage/TargetDeltaZero.t.sol b/test/IncentivizedMessageEscrow/processMessage/TargetDeltaZero.t.sol index cc9f7f7..8e1afe7 100644 --- a/test/IncentivizedMessageEscrow/processMessage/TargetDeltaZero.t.sol +++ b/test/IncentivizedMessageEscrow/processMessage/TargetDeltaZero.t.sol @@ -50,7 +50,7 @@ contract TargetDeltaZeroTest is TestCommon { uint128(_receive) ); - escrow.processMessage( + escrow.processPacket( mockContext, messageWithContext, feeRecipitent diff --git a/test/IncentivizedMessageEscrow/processMessage/TimeOverflow.t.sol b/test/IncentivizedMessageEscrow/processMessage/TimeOverflow.t.sol index 0078900..1dbd589 100644 --- a/test/IncentivizedMessageEscrow/processMessage/TimeOverflow.t.sol +++ b/test/IncentivizedMessageEscrow/processMessage/TimeOverflow.t.sol @@ -46,7 +46,7 @@ contract TimeOverflowTest is TestCommon { uint128(_receive) ); - escrow.processMessage( + escrow.processPacket( mockContext, messageWithContext, feeRecipitent @@ -94,7 +94,7 @@ contract TimeOverflowTest is TestCommon { uint128(_receive) ); - escrow.processMessage( + escrow.processPacket( mockContext, messageWithContext, feeRecipitent diff --git a/test/IncentivizedMessageEscrow/processMessage/_handleAck.t.sol b/test/IncentivizedMessageEscrow/processMessage/_handleAck.t.sol index 5ade2e2..0357fa0 100644 --- a/test/IncentivizedMessageEscrow/processMessage/_handleAck.t.sol +++ b/test/IncentivizedMessageEscrow/processMessage/_handleAck.t.sol @@ -5,7 +5,7 @@ import "forge-std/Test.sol"; import { TestCommon } from "../../TestCommon.t.sol"; -contract ProcessMessageAckTest is TestCommon { +contract processPacketAckTest is TestCommon { uint256 _receive; @@ -28,7 +28,7 @@ contract ProcessMessageAckTest is TestCommon { _receive = GAS_RECEIVE_CONSTANT; - escrow.processMessage( + escrow.processPacket( mockContext, messageWithContext, feeRecipitent @@ -65,7 +65,7 @@ contract ProcessMessageAckTest is TestCommon { vm.expectCall( address(application), abi.encodeCall( - application.ackMessage, + application.receiveAck, ( bytes32(0x8000000000000000000000000000000000000000000000000000000000123123), messageIdentifier, @@ -74,7 +74,7 @@ contract ProcessMessageAckTest is TestCommon { ) ); - escrow.processMessage( + escrow.processPacket( mockContext, messageWithContext, feeRecipitent @@ -116,7 +116,7 @@ contract ProcessMessageAckTest is TestCommon { uint128(_receive) ); - escrow.processMessage( + escrow.processPacket( mockContext, messageWithContext, feeRecipitent @@ -159,7 +159,7 @@ contract ProcessMessageAckTest is TestCommon { uint128(_receive) ); - escrow.processMessage( + escrow.processPacket( mockContext, messageWithContext, feeRecipitent @@ -208,7 +208,7 @@ contract ProcessMessageAckTest is TestCommon { uint128(_receive) ); - escrow.processMessage( + escrow.processPacket( mockContext, messageWithContext, feeRecipitent diff --git a/test/IncentivizedMessageEscrow/processMessage/_handleCall.t.sol b/test/IncentivizedMessageEscrow/processMessage/_handleCall.t.sol index 0b85f6c..fe16f83 100644 --- a/test/IncentivizedMessageEscrow/processMessage/_handleCall.t.sol +++ b/test/IncentivizedMessageEscrow/processMessage/_handleCall.t.sol @@ -5,7 +5,7 @@ import "forge-std/Test.sol"; import { TestCommon } from "../../TestCommon.t.sol"; -contract ProcessMessageCallTest is TestCommon { +contract processPacketCallTest is TestCommon { event Message( bytes32 destinationIdentifier, bytes recipitent, @@ -16,7 +16,7 @@ contract ProcessMessageCallTest is TestCommon { bytes memory message = _MESSAGE; bytes32 feeRecipitent = bytes32(uint256(uint160(address(this)))); - (bytes32 messageIdentifier, bytes memory messageWithContext) = setupEscrowMessage(address(application), message); + (bytes32 messageIdentifier, bytes memory messageWithContext) = setupsubmitMessage(address(application), message); (uint8 v, bytes32 r, bytes32 s) = signMessageForMock(messageWithContext); bytes memory mockContext = abi.encode(v, r, s); @@ -40,7 +40,7 @@ contract ProcessMessageCallTest is TestCommon { messageIdentifier, _DESTINATION_ADDRESS_APPLICATION, feeRecipitent, - uint48(0x82a2), // Gas used + uint48(0x82a1), // Gas used uint64(1), mockAck ) @@ -59,7 +59,7 @@ contract ProcessMessageCallTest is TestCommon { ) ); - escrow.processMessage( + escrow.processPacket( mockContext, messageWithContext, feeRecipitent @@ -70,12 +70,12 @@ contract ProcessMessageCallTest is TestCommon { bytes memory message = _MESSAGE; bytes32 feeRecipitent = bytes32(uint256(uint160(address(this)))); - (, bytes memory messageWithContext) = setupEscrowMessage(address(application), message); + (, bytes memory messageWithContext) = setupsubmitMessage(address(application), message); (uint8 v, bytes32 r, bytes32 s) = signMessageForMock(messageWithContext); bytes memory mockContext = abi.encode(v, r, s); - escrow.processMessage( + escrow.processPacket( mockContext, messageWithContext, feeRecipitent @@ -84,7 +84,7 @@ contract ProcessMessageCallTest is TestCommon { vm.expectRevert( abi.encodeWithSignature("MessageAlreadySpent()") ); - escrow.processMessage( + escrow.processPacket( mockContext, messageWithContext, feeRecipitent @@ -96,12 +96,12 @@ contract ProcessMessageCallTest is TestCommon { bytes32 feeRecipitent = bytes32(uint256(uint160(address(this)))); vm.prank(caller); - escrow.setRemoteEscrowImplementation(_DESTINATION_IDENTIFIER, abi.encode(escrow)); + escrow.setRemoteImplementation(_DESTINATION_IDENTIFIER, abi.encode(escrow)); vm.recordLogs(); vm.deal(caller, _getTotalIncentive(_INCENTIVE)); vm.prank(caller); - (, bytes32 messageIdentifier) = escrow.escrowMessage{value: _getTotalIncentive(_INCENTIVE)}( + (, bytes32 messageIdentifier) = escrow.submitMessage{value: _getTotalIncentive(_INCENTIVE)}( _DESTINATION_IDENTIFIER, _DESTINATION_ADDRESS_APPLICATION, message, @@ -132,7 +132,7 @@ contract ProcessMessageCallTest is TestCommon { ) ); - escrow.processMessage( + escrow.processPacket( _metadata, newMessage, feeRecipitent diff --git a/test/OnRecvIncentivizedMockEscrow/TestOnRecvCommon.t.sol b/test/OnRecvIncentivizedMockEscrow/TestOnRecvCommon.t.sol index 33ad46b..135419b 100644 --- a/test/OnRecvIncentivizedMockEscrow/TestOnRecvCommon.t.sol +++ b/test/OnRecvIncentivizedMockEscrow/TestOnRecvCommon.t.sol @@ -30,10 +30,10 @@ contract TestOnRecvCommon is Test, IMessageEscrowEvents, IMessageEscrowStructs, // Set implementations to the escrow address. vm.prank(address(application)); - escrow.setRemoteEscrowImplementation(_DESTINATION_IDENTIFIER, abi.encode(address(escrow))); + escrow.setRemoteImplementation(_DESTINATION_IDENTIFIER, abi.encode(address(escrow))); vm.prank(address(this)); - escrow.setRemoteEscrowImplementation(_DESTINATION_IDENTIFIER, abi.encode(address(escrow))); + escrow.setRemoteImplementation(_DESTINATION_IDENTIFIER, abi.encode(address(escrow))); _MESSAGE = abi.encode(keccak256(abi.encode(1))); _DESTINATION_ADDRESS_THIS = abi.encodePacked( diff --git a/test/OnRecvIncentivizedMockEscrow/processMessage/_handleAck.t.sol b/test/OnRecvIncentivizedMockEscrow/processMessage/_handleAck.t.sol index 670f874..56ca74e 100644 --- a/test/OnRecvIncentivizedMockEscrow/processMessage/_handleAck.t.sol +++ b/test/OnRecvIncentivizedMockEscrow/processMessage/_handleAck.t.sol @@ -12,7 +12,7 @@ contract OnRecvAckTest is TestOnRecvCommon { vm.recordLogs(); payable(address(application)).transfer(_getTotalIncentive(_INCENTIVE)); vm.prank(address(application)); - (, bytes32 messageIdentifier) = escrow.escrowMessage{value: _getTotalIncentive(_INCENTIVE)}( + (, bytes32 messageIdentifier) = escrow.submitMessage{value: _getTotalIncentive(_INCENTIVE)}( _DESTINATION_IDENTIFIER, abi.encodePacked( uint8(20), @@ -47,7 +47,7 @@ contract OnRecvAckTest is TestOnRecvCommon { vm.expectCall( address(application), abi.encodeCall( - application.ackMessage, + application.receiveAck, ( bytes32(0x8000000000000000000000000000000000000000000000000000000000123123), messageIdentifier, diff --git a/test/OnRecvIncentivizedMockEscrow/processMessage/_handleCall.t.sol b/test/OnRecvIncentivizedMockEscrow/processMessage/_handleCall.t.sol index 0fbfa09..e57db1b 100644 --- a/test/OnRecvIncentivizedMockEscrow/processMessage/_handleCall.t.sol +++ b/test/OnRecvIncentivizedMockEscrow/processMessage/_handleCall.t.sol @@ -14,7 +14,7 @@ contract OnRecvCallTest is TestOnRecvCommon { vm.recordLogs(); payable(address(application)).transfer(_getTotalIncentive(_INCENTIVE)); vm.prank(address(application)); - (, bytes32 messageIdentifier) = escrow.escrowMessage{value: _getTotalIncentive(_INCENTIVE)}( + (, bytes32 messageIdentifier) = escrow.submitMessage{value: _getTotalIncentive(_INCENTIVE)}( _DESTINATION_IDENTIFIER, abi.encodePacked( uint8(20), diff --git a/test/OnRecvIncentivizedMockEscrow/processMessage/_handleTimeout.t.sol b/test/OnRecvIncentivizedMockEscrow/processMessage/_handleTimeout.t.sol index 4be2390..d24124e 100644 --- a/test/OnRecvIncentivizedMockEscrow/processMessage/_handleTimeout.t.sol +++ b/test/OnRecvIncentivizedMockEscrow/processMessage/_handleTimeout.t.sol @@ -13,7 +13,7 @@ contract OnRecvTimeoutTest is TestOnRecvCommon { vm.recordLogs(); payable(address(application)).transfer(_getTotalIncentive(_INCENTIVE)); vm.prank(address(application)); - (, bytes32 messageIdentifier) = escrow.escrowMessage{value: _getTotalIncentive(_INCENTIVE)}( + (, bytes32 messageIdentifier) = escrow.submitMessage{value: _getTotalIncentive(_INCENTIVE)}( _DESTINATION_IDENTIFIER, abi.encodePacked( uint8(20), @@ -36,7 +36,7 @@ contract OnRecvTimeoutTest is TestOnRecvCommon { vm.expectCall( address(application), abi.encodeCall( - application.ackMessage, + application.receiveAck, ( bytes32(0x8000000000000000000000000000000000000000000000000000000000123123), messageIdentifier, diff --git a/test/OnRecvIncentivizedMockEscrow/processMessage/processMessage.t.sol b/test/OnRecvIncentivizedMockEscrow/processMessage/processMessage.t.sol index a9a64aa..6f3c588 100644 --- a/test/OnRecvIncentivizedMockEscrow/processMessage/processMessage.t.sol +++ b/test/OnRecvIncentivizedMockEscrow/processMessage/processMessage.t.sol @@ -5,11 +5,11 @@ import "forge-std/Test.sol"; import { TestOnRecvCommon } from "../TestOnRecvCommon.t.sol"; -contract TestProcessMessageDisabled is TestOnRecvCommon { +contract TestprocessPacketDisabled is TestOnRecvCommon { function test_process_message_disabled(bytes memory mockContext, bytes memory messageWithContext, address feeRecipitent) public { vm.expectRevert(); - escrow.processMessage( + escrow.processPacket( mockContext, messageWithContext, bytes32(uint256(uint160(feeRecipitent))) diff --git a/test/OnRecvIncentivizedMockEscrow/processMessage/recoverAck.t.sol b/test/OnRecvIncentivizedMockEscrow/processMessage/recoverAck.t.sol index 8c900d7..e0f196d 100644 --- a/test/OnRecvIncentivizedMockEscrow/processMessage/recoverAck.t.sol +++ b/test/OnRecvIncentivizedMockEscrow/processMessage/recoverAck.t.sol @@ -12,7 +12,7 @@ contract OnRecvRecoverAckTest is TestOnRecvCommon { vm.recordLogs(); payable(address(application)).transfer(_getTotalIncentive(_INCENTIVE)); vm.prank(address(application)); - ( , bytes32 messageIdentifier) = escrow.escrowMessage{value: _getTotalIncentive(_INCENTIVE)}( + ( , bytes32 messageIdentifier) = escrow.submitMessage{value: _getTotalIncentive(_INCENTIVE)}( _DESTINATION_IDENTIFIER, abi.encodePacked( uint8(20), @@ -60,7 +60,7 @@ contract OnRecvRecoverAckTest is TestOnRecvCommon { vm.expectCall( address(application), abi.encodeCall( - application.ackMessage, + application.receiveAck, ( bytes32(0x8000000000000000000000000000000000000000000000000000000000123123), messageIdentifier, diff --git a/test/TestCommon.t.sol b/test/TestCommon.t.sol index 2cc7365..bcfda45 100644 --- a/test/TestCommon.t.sol +++ b/test/TestCommon.t.sol @@ -9,8 +9,8 @@ import { IMessageEscrowStructs } from "../src/interfaces/IMessageEscrowStructs.s import "./mocks/MockApplication.sol"; import { ICrossChainReceiver } from "../src/interfaces/ICrossChainReceiver.sol"; -interface ICanEscrowMessage is IMessageEscrowStructs{ - function escrowMessage( +interface ICansubmitMessage is IMessageEscrowStructs{ + function submitMessage( bytes32 destinationIdentifier, bytes calldata destinationAddress, bytes calldata message, @@ -20,9 +20,9 @@ interface ICanEscrowMessage is IMessageEscrowStructs{ contract TestCommon is Test, IMessageEscrowEvents, IMessageEscrowStructs { - uint256 constant GAS_SPENT_ON_SOURCE = 6354; - uint256 constant GAS_SPENT_ON_DESTINATION = 33442; - uint256 constant GAS_RECEIVE_CONSTANT = 6164516424; + uint256 constant GAS_SPENT_ON_SOURCE = 6330; + uint256 constant GAS_SPENT_ON_DESTINATION = 33441; + uint256 constant GAS_RECEIVE_CONSTANT = 6156686151; bytes32 constant _DESTINATION_IDENTIFIER = bytes32(uint256(0x123123) + uint256(2**255)); @@ -49,10 +49,10 @@ contract TestCommon is Test, IMessageEscrowEvents, IMessageEscrowStructs { // Set implementations to the escrow address. vm.prank(address(application)); - escrow.setRemoteEscrowImplementation(_DESTINATION_IDENTIFIER, abi.encode(address(escrow))); + escrow.setRemoteImplementation(_DESTINATION_IDENTIFIER, abi.encode(address(escrow))); vm.prank(address(this)); - escrow.setRemoteEscrowImplementation(_DESTINATION_IDENTIFIER, abi.encode(address(escrow))); + escrow.setRemoteImplementation(_DESTINATION_IDENTIFIER, abi.encode(address(escrow))); _MESSAGE = abi.encode(keccak256(abi.encode(1))); _DESTINATION_ADDRESS_THIS = abi.encodePacked( @@ -93,16 +93,16 @@ contract TestCommon is Test, IMessageEscrowEvents, IMessageEscrowStructs { _metadata = abi.encode(v, r, s); } - function escrowMessage(bytes memory message) internal returns(bytes32) { - (bytes32 messageIdentifier, ) = setupEscrowMessage(address(application), message); + function submitMessage(bytes memory message) internal returns(bytes32) { + (bytes32 messageIdentifier, ) = setupsubmitMessage(address(application), message); return messageIdentifier; } - function setupEscrowMessage(address fromAddress, bytes memory message) internal returns(bytes32, bytes memory) { + function setupsubmitMessage(address fromAddress, bytes memory message) internal returns(bytes32, bytes memory) { vm.recordLogs(); (, uint256 cost) = escrow.estimateAdditionalCost(); - (, bytes32 messageIdentifier) = ICanEscrowMessage(fromAddress).escrowMessage{value: _getTotalIncentive(_INCENTIVE) + cost}( + (, bytes32 messageIdentifier) = ICansubmitMessage(fromAddress).submitMessage{value: _getTotalIncentive(_INCENTIVE) + cost}( _DESTINATION_IDENTIFIER, _DESTINATION_ADDRESS_APPLICATION, message, @@ -116,13 +116,13 @@ contract TestCommon is Test, IMessageEscrowEvents, IMessageEscrowStructs { return (messageIdentifier, abi.encodePacked(bytes32(uint256(uint160(address(escrow)))), messageWithContext)); } - function setupProcessMessage(bytes memory message, bytes32 destinationFeeRecipitent) internal returns(bytes memory) { + function setupprocessPacket(bytes memory message, bytes32 destinationFeeRecipitent) internal returns(bytes memory) { (uint8 v, bytes32 r, bytes32 s) = signMessageForMock(message); bytes memory mockContext = abi.encode(v, r, s); (, uint256 cost) = escrow.estimateAdditionalCost(); vm.recordLogs(); - escrow.processMessage{value: cost}( + escrow.processPacket{value: cost}( mockContext, message, destinationFeeRecipitent @@ -136,9 +136,9 @@ contract TestCommon is Test, IMessageEscrowEvents, IMessageEscrowStructs { } function setupForAck(address fromAddress, bytes memory message, bytes32 destinationFeeRecipitent) internal returns(bytes32, bytes memory) { - (bytes32 messageIdentifier, bytes memory messageWithContext) = setupEscrowMessage(fromAddress, message); + (bytes32 messageIdentifier, bytes memory messageWithContext) = setupsubmitMessage(fromAddress, message); - return (messageIdentifier, setupProcessMessage(messageWithContext, destinationFeeRecipitent)); + return (messageIdentifier, setupprocessPacket(messageWithContext, destinationFeeRecipitent)); } } diff --git a/test/mocks/BadContract.sol b/test/mocks/BadContract.sol index 32cd677..258980b 100644 --- a/test/mocks/BadContract.sol +++ b/test/mocks/BadContract.sol @@ -8,7 +8,7 @@ import { ICrossChainReceiver } from "../../src/interfaces/ICrossChainReceiver.so * @title BadContract */ contract BadContract is ICrossChainReceiver { - function ackMessage(bytes32 /* destinationIdentifier */, bytes32 /* messageIdentifier */, bytes calldata /* acknowledgement */) pure external { + function receiveAck(bytes32 /* destinationIdentifier */, bytes32 /* messageIdentifier */, bytes calldata /* acknowledgement */) pure external { require(false); } diff --git a/test/mocks/MockApplication.sol b/test/mocks/MockApplication.sol index 08a09b3..7bdba26 100644 --- a/test/mocks/MockApplication.sol +++ b/test/mocks/MockApplication.sol @@ -9,44 +9,31 @@ import { ICrossChainReceiver } from "../../src/interfaces/ICrossChainReceiver.so */ contract MockApplication is ICrossChainReceiver { - event EscrowMessage(uint256 gasRefund, bytes32 messageIdentifier); - event AckMessage(bytes32 destinationIdentifier, bytes acknowledgement); - event ReceiveMessage(bytes32 sourceIdentifierbytes, bytes fromApplication, bytes message, bytes acknowledgement); - IIncentivizedMessageEscrow immutable MESSAGE_ESCROW; constructor(address messageEscrow_) { MESSAGE_ESCROW = IIncentivizedMessageEscrow(messageEscrow_); } - function escrowMessage( + function submitMessage( bytes32 destinationIdentifier, bytes calldata destinationAddress, bytes calldata message, IIncentivizedMessageEscrow.IncentiveDescription calldata incentive ) external payable returns(uint256 gasRefund, bytes32 messageIdentifier) { - (gasRefund, messageIdentifier) = MESSAGE_ESCROW.escrowMessage{value: msg.value}( + (gasRefund, messageIdentifier) = MESSAGE_ESCROW.submitMessage{value: msg.value}( destinationIdentifier, destinationAddress, message, incentive ); - - // emit EscrowMessage(gasRefund, messageIdentifier); } - function ackMessage(bytes32 destinationIdentifier, bytes32 messageIdentifier, bytes calldata acknowledgement) pure external { - // emit AckMessage(destinationIdentifier, acknowledgement); + function receiveAck(bytes32 destinationIdentifier, bytes32 messageIdentifier, bytes calldata acknowledgement) pure external { } function receiveMessage(bytes32 /* sourceIdentifierbytes */, bytes32 /* messageIdentifier */, bytes calldata fromApplication, bytes calldata message) pure external returns(bytes memory acknowledgement) { acknowledgement = abi.encodePacked(keccak256(bytes.concat(message, fromApplication))); - // emit ReceiveMessage( - // sourceIdentifierbytes, - // fromApplication, - // message, - // acknowledgement - // ); return acknowledgement; } diff --git a/test/mocks/MockOnRecvAMB.sol b/test/mocks/MockOnRecvAMB.sol index bb05bdc..5df54ea 100644 --- a/test/mocks/MockOnRecvAMB.sol +++ b/test/mocks/MockOnRecvAMB.sol @@ -12,7 +12,7 @@ contract MockOnRecvAMB { bytes message ); - function sendMessage( + function sendPacket( bytes32 destinationIdentifier, bytes calldata recipitent, bytes calldata message diff --git a/test/mocks/MockSpendGas.sol b/test/mocks/MockSpendGas.sol index ccf5780..8e02831 100644 --- a/test/mocks/MockSpendGas.sol +++ b/test/mocks/MockSpendGas.sol @@ -14,13 +14,13 @@ contract MockSpendGas is ICrossChainReceiver { MESSAGE_ESCROW = IIncentivizedMessageEscrow(messageEscrow_); } - function escrowMessage( + function submitMessage( bytes32 destinationIdentifier, bytes calldata destinationAddress, bytes calldata message, IIncentivizedMessageEscrow.IncentiveDescription calldata incentive ) external payable returns(uint256 gasRefund, bytes32 messageIdentifier) { - (gasRefund, messageIdentifier) = MESSAGE_ESCROW.escrowMessage{value: msg.value}( + (gasRefund, messageIdentifier) = MESSAGE_ESCROW.submitMessage{value: msg.value}( destinationIdentifier, destinationAddress, message, @@ -28,7 +28,7 @@ contract MockSpendGas is ICrossChainReceiver { ); } - function ackMessage(bytes32 destinationIdentifier, bytes32 messageIdentifier, bytes calldata acknowledgement) external view { + function receiveAck(bytes32 destinationIdentifier, bytes32 messageIdentifier, bytes calldata acknowledgement) external view { this.receiveMessage(destinationIdentifier, messageIdentifier, abi.encodePacked(bytes1(0x00)), acknowledgement); } diff --git a/test/mocks/ReturnBomber.sol b/test/mocks/ReturnBomber.sol index c5d10b4..f19a5ea 100644 --- a/test/mocks/ReturnBomber.sol +++ b/test/mocks/ReturnBomber.sol @@ -7,7 +7,7 @@ import { ICrossChainReceiver } from "../../src/interfaces/ICrossChainReceiver.so /** * @title ReturnBomber * This contract tries to return bomb (https://github.com/ethereum/solidity/issues/12306) - * the incentive contract when ackMessage is called. + * the incentive contract when receiveAck is called. */ contract ReturnBomber is ICrossChainReceiver { IIncentivizedMessageEscrow immutable MESSAGE_ESCROW; @@ -16,23 +16,23 @@ contract ReturnBomber is ICrossChainReceiver { MESSAGE_ESCROW = IIncentivizedMessageEscrow(messageEscrow_); } - function escrowMessage( + function submitMessage( bytes32 destinationIdentifier, bytes calldata destinationAddress, bytes calldata message, IIncentivizedMessageEscrow.IncentiveDescription calldata incentive ) external payable returns(uint256 gasRefund, bytes32 messageIdentifier) { - (gasRefund, messageIdentifier) = MESSAGE_ESCROW.escrowMessage{value: msg.value}( + (gasRefund, messageIdentifier) = MESSAGE_ESCROW.submitMessage{value: msg.value}( destinationIdentifier, destinationAddress, message, incentive ); - // emit EscrowMessage(gasRefund, messageIdentifier); + // emit submitMessage(gasRefund, messageIdentifier); } - function ackMessage(bytes32 /* destinationIdentifier */, bytes32 /* messageIdentifier */, bytes calldata /* acknowledgement */) view external { + function receiveAck(bytes32 /* destinationIdentifier */, bytes32 /* messageIdentifier */, bytes calldata /* acknowledgement */) view external { // approximate solution to Cmem for new_mem_size_words uint256 rsize = sqrt(gasleft() / 2 * 512); assembly { diff --git a/test/wormhole/roundtrip.t.sol b/test/wormhole/roundtrip.t.sol index c8200ea..2b270be 100644 --- a/test/wormhole/roundtrip.t.sol +++ b/test/wormhole/roundtrip.t.sol @@ -76,7 +76,7 @@ contract TestRoundtrip is Test, IMessageEscrowStructs, Bytes65 { _DESTINATION_IDENTIFIER = bytes32(uint256(messages.chainId())); - escrow.setRemoteEscrowImplementation(_DESTINATION_IDENTIFIER, abi.encode(address(escrow))); + escrow.setRemoteImplementation(_DESTINATION_IDENTIFIER, abi.encode(address(escrow))); // initialize guardian set with one guardian address[] memory keys = new address[](1); @@ -129,7 +129,7 @@ contract TestRoundtrip is Test, IMessageEscrowStructs, Bytes65 { IncentiveDescription storage incentive = _INCENTIVE; vm.recordLogs(); - (uint256 gasRefund, bytes32 messageIdentifier) = escrow.escrowMessage{value: _getTotalIncentive(_INCENTIVE)}( + (uint256 gasRefund, bytes32 messageIdentifier) = escrow.submitMessage{value: _getTotalIncentive(_INCENTIVE)}( _DESTINATION_IDENTIFIER, convertEVMTo65(address(this)), message, @@ -145,7 +145,7 @@ contract TestRoundtrip is Test, IMessageEscrowStructs, Bytes65 { bytes memory validVM = makeValidVM(payload, uint16(uint256(_DESTINATION_IDENTIFIER)), bytes32(uint256(uint160(address(escrow))))); vm.recordLogs(); - escrow.processMessage(hex"", validVM, bytes32(uint256(0xdead))); + escrow.processPacket(hex"", validVM, bytes32(uint256(0xdead))); entries = vm.getRecordedLogs(); (sequence, nonce, payload, consistencyLevel) = abi.decode( @@ -155,6 +155,6 @@ contract TestRoundtrip is Test, IMessageEscrowStructs, Bytes65 { validVM = makeValidVM(payload, uint16(uint256(_DESTINATION_IDENTIFIER)), bytes32(uint256(uint160(address(escrow))))); - escrow.processMessage(hex"", validVM, bytes32(uint256(0xdead))); + escrow.processPacket(hex"", validVM, bytes32(uint256(0xdead))); } } From 1eadff84ddc1f60a10fbb6d14b38e8e0fd875423 Mon Sep 17 00:00:00 2001 From: Alexander Date: Tue, 24 Oct 2023 12:16:12 +0200 Subject: [PATCH 03/11] feat: make gas and fee naming usage more consistent --- src/IncentivizedMessageEscrow.sol | 38 +++++++++++++++---------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/src/IncentivizedMessageEscrow.sol b/src/IncentivizedMessageEscrow.sol index a357f4b..56e1dfb 100644 --- a/src/IncentivizedMessageEscrow.sol +++ b/src/IncentivizedMessageEscrow.sol @@ -108,9 +108,9 @@ abstract contract IncentivizedMessageEscrow is IIncentivizedMessageEscrow, Bytes IncentiveDescription storage incentive = _bounty[messageIdentifier]; // Compute incentive metrics. - uint128 deliveryGas = incentive.maxGasDelivery * deliveryGasPriceIncrease; - uint128 ackGas = incentive.maxGasAck * ackGasPriceIncrease; - uint128 sum = deliveryGas + ackGas; + uint128 maxDeliveryFee = incentive.maxGasDelivery * deliveryGasPriceIncrease; + uint128 maxAckFee = incentive.maxGasAck * ackGasPriceIncrease; + uint128 sum = maxDeliveryFee + maxAckFee; // Check that the provided gas is exact if (msg.value != sum) revert IncorrectValueProvided(sum, uint128(msg.value)); @@ -368,7 +368,7 @@ abstract contract IncentivizedMessageEscrow is IIncentivizedMessageEscrow, Bytes uint256 gasSpentOnDestination = uint48(bytes6(message[CTX1_GAS_SPENT_START:CTX1_GAS_SPENT_END])); // Find the respective rewards for delivery and ack. - uint256 deliveryFee; uint256 ackFee; uint256 sumFee; uint256 refund; uint256 gasSpentOnSource; + uint256 deliveryFee; uint256 ackFee; uint256 actualFee; uint256 refund; uint256 gasSpentOnSource; unchecked { // gasSpentOnDestination * priceOfDeliveryGas < 2**48 * 2**96 = 2**144 if (maxGasDelivery <= gasSpentOnDestination) gasSpentOnDestination = maxGasDelivery; // If more gas was spent then allocated, then only use the allocation. @@ -380,12 +380,12 @@ abstract contract IncentivizedMessageEscrow is IIncentivizedMessageEscrow, Bytes // gasSpentOnSource * priceOfAckGas < 2**48 * 2**96 = 2**144 ackFee = gasSpentOnSource * priceOfAckGas; // deliveryFee + ackFee < 2**144 + 2**144 = 2**145 - sumFee = deliveryFee + ackFee; + actualFee = deliveryFee + ackFee; // (priceOfDeliveryGas * maxGasDelivery + priceOfDeliveryGas * maxGasAck) has been caculated before (escrowBounty) < (2**48 * 2**96) + (2**48 * 2**96) = 2**144 + 2**144 = 2**145 - uint256 maxDeliveryGas = maxGasDelivery * priceOfDeliveryGas; - uint256 maxAckGas = maxGasAck * priceOfAckGas; - uint256 maxSum = maxDeliveryGas + maxAckGas; - refund = maxSum - sumFee; + uint256 maxDeliveryFee = maxGasDelivery * priceOfDeliveryGas; + uint256 maxAckFee = maxGasAck * priceOfAckGas; + uint256 maxFee = maxDeliveryFee + maxAckFee; + refund = maxFee - actualFee; } // send is used to ensure this doesn't revert. Transfer could revert and block the ack from ever being delivered. if(!payable(refundGasTo).send(refund)) { @@ -395,13 +395,13 @@ abstract contract IncentivizedMessageEscrow is IIncentivizedMessageEscrow, Bytes address sourceFeeRecipitent = address(uint160(uint256(feeRecipitent))); // If both the destination relayer and source relayer are the same then we don't have to figure out which fraction goes to who. if (destinationFeeRecipitent == sourceFeeRecipitent) { - payable(sourceFeeRecipitent).transfer(sumFee); // If this reverts, then the relayer that is executing this tx provided a bad input. + payable(sourceFeeRecipitent).transfer(actualFee); // If this reverts, then the relayer that is executing this tx provided a bad input. emit MessageAcked(messageIdentifier); emit BountyClaimed( messageIdentifier, uint64(gasSpentOnDestination), uint64(gasSpentOnSource), - uint128(sumFee), + uint128(actualFee), 0 ); return; @@ -443,7 +443,7 @@ abstract contract IncentivizedMessageEscrow is IIncentivizedMessageEscrow, Bytes if (timeBetweenTargetAndExecution <= 0) { // Less time than target passed and the destination relayer should get a larger chunk. // targetDelta != 0, we checked for that. - // max abs timeBetweenTargetAndExecution = | - targetDelta| = targetDelta => ackFee * targetDelta < sumFee * targetDelta + // max abs timeBetweenTargetAndExecution = | - targetDelta| = targetDelta => ackFee * targetDelta < actualFee * targetDelta // 2**127 * 2**64 = 2**191 forDestinationRelayer += ackFee * uint256(- timeBetweenTargetAndExecution) / targetDelta; } else { @@ -452,7 +452,7 @@ abstract contract IncentivizedMessageEscrow is IIncentivizedMessageEscrow, Bytes if (uint256(timeBetweenTargetAndExecution) < targetDelta) { // targetDelta != 0, we checked for that. // max abs timeBetweenTargetAndExecution = targetDelta since we have the above check - // => deliveryFee * targetDelta < sumFee * targetDelta < 2**127 * 2**64 = 2**191 + // => deliveryFee * targetDelta < actualFee * targetDelta < 2**127 * 2**64 = 2**191 forDestinationRelayer -= deliveryFee * uint256(timeBetweenTargetAndExecution) / targetDelta; } else { // This doesn't discourage relaying, since executionTime first begins counting once the destinaion call has been executed. @@ -467,9 +467,9 @@ abstract contract IncentivizedMessageEscrow is IIncentivizedMessageEscrow, Bytes } uint256 forSourceRelayer; unchecked { - // max forDestinationRelayer is deliveryFee + ackFee = sumFee => sumFee - forDestinationRelayer == 0 - // min forDestinationRelayer = 0 => sumFee - 0 = sumFee - forSourceRelayer = sumFee - forDestinationRelayer; + // max forDestinationRelayer is deliveryFee + ackFee = actualFee => actualFee - forDestinationRelayer == 0 + // min forDestinationRelayer = 0 => actualFee - 0 = actualFee + forSourceRelayer = actualFee - forDestinationRelayer; } payable(sourceFeeRecipitent).transfer(forSourceRelayer); // If this reverts, then the relayer that is executing this tx provided a bad input. @@ -492,9 +492,9 @@ abstract contract IncentivizedMessageEscrow is IIncentivizedMessageEscrow, Bytes ) internal returns(uint128 sum){ if (_bounty[messageIdentifier].refundGasTo != address(0)) revert MessageAlreadyBountied(); // Compute incentive metrics. - uint128 deliveryGas = incentive.maxGasDelivery * incentive.priceOfDeliveryGas; - uint128 ackGas = incentive.maxGasAck * incentive.priceOfAckGas; - sum = deliveryGas + ackGas; + uint128 maxDeliveryFee = incentive.maxGasDelivery * incentive.priceOfDeliveryGas; + uint128 maxAckFee = incentive.maxGasAck * incentive.priceOfAckGas; + sum = maxDeliveryFee + maxAckFee; _bounty[messageIdentifier] = incentive; } From 6779ad6110ff549e5f25fd79a061023e5d5f84fb Mon Sep 17 00:00:00 2001 From: Alexander Date: Tue, 24 Oct 2023 12:41:29 +0200 Subject: [PATCH 04/11] feat: rename _spentMessageIdentifier --- .gas-snapshot | 88 +++++++++---------- src/IncentivizedMessageEscrow.sol | 10 +-- src/interfaces/IIncentivizedMessageEscrow.sol | 2 +- .../processMessage/GasSpendControl.sol | 4 +- .../processMessage/Reentry.call.t.sol | 2 +- 5 files changed, 53 insertions(+), 53 deletions(-) diff --git a/.gas-snapshot b/.gas-snapshot index b1f57be..e54321d 100644 --- a/.gas-snapshot +++ b/.gas-snapshot @@ -1,29 +1,29 @@ -AckReentryTest:test_reentry_on_ack_message() (gas: 531633) -CallReentryTest:test_reentry_on_call_message() (gas: 560819) -EscrowInformationTest:test_check_escrow_events() (gas: 100314) -EscrowInformationTest:test_check_escrow_state() (gas: 97683) -EscrowInformationTest:test_gas_refund(uint256) (runs: 256, μ: 148991, ~: 153869) -EscrowWrongGasPaymentTest:test_fail_not_enough_gas_sent() (gas: 94251) -EscrowWrongGasPaymentTest:test_place_incentive() (gas: 90153) -GasSpendControlTest:test_fail_relayer_has_to_provide_enough_gas() (gas: 605997) -GasSpendControlTest:test_process_ack_gas() (gas: 621671) -GasSpendControlTest:test_process_delivery_gas() (gas: 361342) -IncreaseBountyTest:test_fail_bounty_does_not_exist() (gas: 18045) -IncreaseBountyTest:test_fail_overpay() (gas: 128644) -IncreaseBountyTest:test_fail_under_and_overpay(int256) (runs: 256, μ: 130730, ~: 130730) -IncreaseBountyTest:test_increase_escrow() (gas: 130410) -IncreaseBountyTest:test_no_increase_escrow() (gas: 123139) -MessageIdentifierTest:test_destination_identifier_impacts_message_identifier() (gas: 302397) -MessageIdentifierTest:test_non_unique_bounty(bytes) (runs: 256, μ: 105429, ~: 105323) -MessageIdentifierTest:test_unique_identifier_block_10() (gas: 97481) -MessageIdentifierTest:test_unique_identifier_block_11() (gas: 97437) -NoImplementationAddressSetTest:test_error_no_implementation_address_set() (gas: 343962) -OnRecvAckTest:test_on_ack() (gas: 231241) -OnRecvCallTest:test_on_call() (gas: 163298) -OnRecvRecoverAckTest:test_recover_ack() (gas: 248098) -OnRecvTimeoutTest:test_on_timeout() (gas: 122840) -ReturnBombTest:test_process_ack_gas() (gas: 5339305) -TargetDeltaZeroTest:test_target_delta_zero(uint16) (runs: 256, μ: 257410, ~: 257410) +AckReentryTest:test_reentry_on_ack_message() (gas: 531765) +CallReentryTest:test_reentry_on_call_message() (gas: 560907) +EscrowInformationTest:test_check_escrow_events() (gas: 100336) +EscrowInformationTest:test_check_escrow_state() (gas: 97727) +EscrowInformationTest:test_gas_refund(uint256) (runs: 256, μ: 148801, ~: 153891) +EscrowWrongGasPaymentTest:test_fail_not_enough_gas_sent() (gas: 94273) +EscrowWrongGasPaymentTest:test_place_incentive() (gas: 90175) +GasSpendControlTest:test_fail_relayer_has_to_provide_enough_gas() (gas: 606085) +GasSpendControlTest:test_process_ack_gas() (gas: 621781) +GasSpendControlTest:test_process_delivery_gas() (gas: 361408) +IncreaseBountyTest:test_fail_bounty_does_not_exist() (gas: 18067) +IncreaseBountyTest:test_fail_overpay() (gas: 128710) +IncreaseBountyTest:test_fail_under_and_overpay(int256) (runs: 256, μ: 130796, ~: 130796) +IncreaseBountyTest:test_increase_escrow() (gas: 130476) +IncreaseBountyTest:test_no_increase_escrow() (gas: 123205) +MessageIdentifierTest:test_destination_identifier_impacts_message_identifier() (gas: 302441) +MessageIdentifierTest:test_non_unique_bounty(bytes) (runs: 256, μ: 105473, ~: 105367) +MessageIdentifierTest:test_unique_identifier_block_10() (gas: 97503) +MessageIdentifierTest:test_unique_identifier_block_11() (gas: 97459) +NoImplementationAddressSetTest:test_error_no_implementation_address_set() (gas: 343984) +OnRecvAckTest:test_on_ack() (gas: 231285) +OnRecvCallTest:test_on_call() (gas: 163342) +OnRecvRecoverAckTest:test_recover_ack() (gas: 248186) +OnRecvTimeoutTest:test_on_timeout() (gas: 122875) +ReturnBombTest:test_process_ack_gas() (gas: 5339415) +TargetDeltaZeroTest:test_target_delta_zero(uint16) (runs: 256, μ: 257564, ~: 257564) TestMessages:testCannotVerifySignaturesWithInvalidSignature(bytes) (runs: 256, μ: 28353, ~: 28345) TestMessages:testCannotVerifySignaturesWithOutOfBoundsSignature(bytes) (runs: 256, μ: 29972, ~: 29964) TestMessages:testHashMismatchedVMIsNotVerified() (gas: 92458) @@ -34,21 +34,21 @@ TestMessagesC2Sigs:test_compare_wormhole_implementation_and_calldata_version() ( TestMessagesC2Sigs:test_error_invalid_vm() (gas: 135944) TestMessagesC:test_compare_wormhole_implementation_and_calldata_version() (gas: 105270) TestMessagesC:test_error_invalid_vm() (gas: 103798) -TestRoundtrip:test_escrow_wormhole_message(bytes) (runs: 256, μ: 265001, ~: 264490) -TestprocessPacketDisabled:test_process_message_disabled(bytes,bytes,address) (runs: 256, μ: 10250, ~: 10227) -TimeOverflowTest:test_larger_than_uint_time_is_fine() (gas: 253696) -TimeOverflowTest:test_overflow_in_unchecked_is_fine() (gas: 255883) -processPacketAckTest:test_ack_called_event() (gas: 219307) -processPacketAckTest:test_ack_different_recipitents() (gas: 253978) -processPacketAckTest:test_ack_less_time_than_expected(uint64,uint64) (runs: 256, μ: 256863, ~: 258836) -processPacketAckTest:test_ack_more_time_than_expected(uint64,uint64) (runs: 256, μ: 259632, ~: 259632) -processPacketAckTest:test_ack_process_message() (gas: 214539) -processPacketCallTest:test_call_process_message() (gas: 177866) -processPacketCallTest:test_call_process_message_twice() (gas: 173482) -processPacketCallTest:test_expect_caller(address) (runs: 256, μ: 228841, ~: 228841) -processPacketNoReceiveTest:test_application_does_not_implement_interface() (gas: 174846) -sendPacketPaymentTest:test_error_send_message_without_additional_cost() (gas: 110220) -sendPacketPaymentTest:test_estimate_cost() (gas: 8079) -sendPacketPaymentTest:test_process_message_with_additional_payment(bytes) (runs: 256, μ: 175720, ~: 175506) -sendPacketPaymentTest:test_process_message_without_additional_payment(bytes) (runs: 256, μ: 176280, ~: 176066) -sendPacketPaymentTest:test_send_message_with_additional_cost() (gas: 102945) \ No newline at end of file +TestRoundtrip:test_escrow_wormhole_message(bytes) (runs: 256, μ: 265067, ~: 264556) +TestprocessPacketDisabled:test_process_message_disabled(bytes,bytes,address) (runs: 256, μ: 10272, ~: 10249) +TimeOverflowTest:test_larger_than_uint_time_is_fine() (gas: 253806) +TimeOverflowTest:test_overflow_in_unchecked_is_fine() (gas: 256015) +processPacketAckTest:test_ack_called_event() (gas: 219439) +processPacketAckTest:test_ack_different_recipitents() (gas: 254088) +processPacketAckTest:test_ack_less_time_than_expected(uint64,uint64) (runs: 256, μ: 256683, ~: 258968) +processPacketAckTest:test_ack_more_time_than_expected(uint64,uint64) (runs: 256, μ: 259764, ~: 259764) +processPacketAckTest:test_ack_process_message() (gas: 214649) +processPacketCallTest:test_call_process_message() (gas: 177932) +processPacketCallTest:test_call_process_message_twice() (gas: 173570) +processPacketCallTest:test_expect_caller(address) (runs: 256, μ: 228885, ~: 228885) +processPacketNoReceiveTest:test_application_does_not_implement_interface() (gas: 174912) +sendPacketPaymentTest:test_error_send_message_without_additional_cost() (gas: 110264) +sendPacketPaymentTest:test_estimate_cost() (gas: 8101) +sendPacketPaymentTest:test_process_message_with_additional_payment(bytes) (runs: 256, μ: 175786, ~: 175572) +sendPacketPaymentTest:test_process_message_without_additional_payment(bytes) (runs: 256, μ: 176346, ~: 176132) +sendPacketPaymentTest:test_send_message_with_additional_cost() (gas: 102989) \ No newline at end of file diff --git a/src/IncentivizedMessageEscrow.sol b/src/IncentivizedMessageEscrow.sol index 56e1dfb..7900e45 100644 --- a/src/IncentivizedMessageEscrow.sol +++ b/src/IncentivizedMessageEscrow.sol @@ -45,7 +45,7 @@ abstract contract IncentivizedMessageEscrow is IIncentivizedMessageEscrow, Bytes //--- Storage ---// mapping(bytes32 => IncentiveDescription) _bounty; - mapping(bytes32 => bool) _spentMessageIdentifier; + mapping(bytes32 => bool) _messageDelivered; // Maps applications to their escrow implementations. mapping(address => mapping(bytes32 => bytes)) public implementationAddress; @@ -78,8 +78,8 @@ abstract contract IncentivizedMessageEscrow is IIncentivizedMessageEscrow, Bytes return _bounty[messageIdentifier]; } - function spentMessageIdentifier(bytes32 messageIdentifier) external view returns(bool hasMessageBeenExecuted) { - return _spentMessageIdentifier[messageIdentifier]; + function messageDelivered(bytes32 messageIdentifier) external view returns(bool hasMessageBeenExecuted) { + return _messageDelivered[messageIdentifier]; } @@ -251,9 +251,9 @@ abstract contract IncentivizedMessageEscrow is IIncentivizedMessageEscrow, Bytes bytes32 messageIdentifier = bytes32(message[MESSAGE_IDENTIFIER_START:MESSAGE_IDENTIFIER_END]); // The 3 next lines act as a reentry guard, so this call doesn't have to be protected by reentry. - bool messageState = _spentMessageIdentifier[messageIdentifier]; + bool messageState = _messageDelivered[messageIdentifier]; if (messageState) revert MessageAlreadySpent(); - _spentMessageIdentifier[messageIdentifier] = true; + _messageDelivered[messageIdentifier] = true; // Deliver message to application. diff --git a/src/interfaces/IIncentivizedMessageEscrow.sol b/src/interfaces/IIncentivizedMessageEscrow.sol index f452063..e68f479 100644 --- a/src/interfaces/IIncentivizedMessageEscrow.sol +++ b/src/interfaces/IIncentivizedMessageEscrow.sol @@ -10,7 +10,7 @@ import { IMessageEscrowEvents } from "./IMessageEscrowEvents.sol"; interface IIncentivizedMessageEscrow is IMessageEscrowStructs, IMessageEscrowErrors, IMessageEscrowEvents { function bounty(bytes32 messageIdentifier) external view returns(IncentiveDescription memory incentive); - function spentMessageIdentifier(bytes32 messageIdentifier) external view returns(bool hasMessageBeenExecuted); + function messageDelivered(bytes32 messageIdentifier) external view returns(bool hasMessageBeenExecuted); function increaseBounty( bytes32 messageIdentifier, diff --git a/test/IncentivizedMessageEscrow/processMessage/GasSpendControl.sol b/test/IncentivizedMessageEscrow/processMessage/GasSpendControl.sol index 092f4e7..9013632 100644 --- a/test/IncentivizedMessageEscrow/processMessage/GasSpendControl.sol +++ b/test/IncentivizedMessageEscrow/processMessage/GasSpendControl.sol @@ -104,7 +104,7 @@ contract GasSpendControlTest is TestCommon { // The strange gas limit of ' + 5000 - 2' here is because is how much is actually spent (read from trace) and + 5000 - 2 is some kind of refund that // the relayer needs to add as extra. (reentry refund) - escrow.processPacket{gas: 239936}( + escrow.processPacket{gas: 239958}( mockContext, messageWithContext, destinationFeeRecipitent @@ -126,7 +126,7 @@ contract GasSpendControlTest is TestCommon { ) ) ); - escrow.processPacket{gas: 239936 - 1}( + escrow.processPacket{gas: 239958 - 1}( mockContext, messageWithContext, destinationFeeRecipitent diff --git a/test/IncentivizedMessageEscrow/processMessage/Reentry.call.t.sol b/test/IncentivizedMessageEscrow/processMessage/Reentry.call.t.sol index 5cadf7c..985ce04 100644 --- a/test/IncentivizedMessageEscrow/processMessage/Reentry.call.t.sol +++ b/test/IncentivizedMessageEscrow/processMessage/Reentry.call.t.sol @@ -61,7 +61,7 @@ contract CallReentryTest is TestCommon, ICrossChainReceiver { messageIdentifier, _DESTINATION_ADDRESS_APPLICATION, feeRecipitent, - uint48(0x10024), // Gas used + uint48(0x1003a), // Gas used uint64(1), uint8(1) ) From b5e6d8003a00e4313b1f71a4def5600fab8798e2 Mon Sep 17 00:00:00 2001 From: Alexander Date: Tue, 24 Oct 2023 12:58:11 +0200 Subject: [PATCH 05/11] feat: ensure remote implementation cannot be set twice --- .gas-snapshot | 12 +++--- src/IncentivizedMessageEscrow.sol | 9 ++++- src/interfaces/IMessageEscrowErrors.sol | 1 + .../setRemoteImplementation.t.sol | 39 +++++++++++++++++++ 4 files changed, 54 insertions(+), 7 deletions(-) create mode 100644 test/IncentivizedMessageEscrow/setRemoteImplementation.t.sol diff --git a/.gas-snapshot b/.gas-snapshot index e54321d..b06f818 100644 --- a/.gas-snapshot +++ b/.gas-snapshot @@ -2,7 +2,7 @@ AckReentryTest:test_reentry_on_ack_message() (gas: 531765) CallReentryTest:test_reentry_on_call_message() (gas: 560907) EscrowInformationTest:test_check_escrow_events() (gas: 100336) EscrowInformationTest:test_check_escrow_state() (gas: 97727) -EscrowInformationTest:test_gas_refund(uint256) (runs: 256, μ: 148801, ~: 153891) +EscrowInformationTest:test_gas_refund(uint256) (runs: 256, μ: 149225, ~: 153891) EscrowWrongGasPaymentTest:test_fail_not_enough_gas_sent() (gas: 94273) EscrowWrongGasPaymentTest:test_place_incentive() (gas: 90175) GasSpendControlTest:test_fail_relayer_has_to_provide_enough_gas() (gas: 606085) @@ -13,7 +13,7 @@ IncreaseBountyTest:test_fail_overpay() (gas: 128710) IncreaseBountyTest:test_fail_under_and_overpay(int256) (runs: 256, μ: 130796, ~: 130796) IncreaseBountyTest:test_increase_escrow() (gas: 130476) IncreaseBountyTest:test_no_increase_escrow() (gas: 123205) -MessageIdentifierTest:test_destination_identifier_impacts_message_identifier() (gas: 302441) +MessageIdentifierTest:test_destination_identifier_impacts_message_identifier() (gas: 302723) MessageIdentifierTest:test_non_unique_bounty(bytes) (runs: 256, μ: 105473, ~: 105367) MessageIdentifierTest:test_unique_identifier_block_10() (gas: 97503) MessageIdentifierTest:test_unique_identifier_block_11() (gas: 97459) @@ -34,18 +34,20 @@ TestMessagesC2Sigs:test_compare_wormhole_implementation_and_calldata_version() ( TestMessagesC2Sigs:test_error_invalid_vm() (gas: 135944) TestMessagesC:test_compare_wormhole_implementation_and_calldata_version() (gas: 105270) TestMessagesC:test_error_invalid_vm() (gas: 103798) -TestRoundtrip:test_escrow_wormhole_message(bytes) (runs: 256, μ: 265067, ~: 264556) +TestRoundtrip:test_escrow_wormhole_message(bytes) (runs: 256, μ: 265081, ~: 264570) +TestSetRemoteImplementation:test_set_remote_implementation(bytes32,bytes) (runs: 256, μ: 110311, ~: 96467) +TestSetRemoteImplementation:test_set_remote_implementation_twice(bytes32,bytes) (runs: 256, μ: 93461, ~: 83021) TestprocessPacketDisabled:test_process_message_disabled(bytes,bytes,address) (runs: 256, μ: 10272, ~: 10249) TimeOverflowTest:test_larger_than_uint_time_is_fine() (gas: 253806) TimeOverflowTest:test_overflow_in_unchecked_is_fine() (gas: 256015) processPacketAckTest:test_ack_called_event() (gas: 219439) processPacketAckTest:test_ack_different_recipitents() (gas: 254088) -processPacketAckTest:test_ack_less_time_than_expected(uint64,uint64) (runs: 256, μ: 256683, ~: 258968) +processPacketAckTest:test_ack_less_time_than_expected(uint64,uint64) (runs: 256, μ: 256475, ~: 258968) processPacketAckTest:test_ack_more_time_than_expected(uint64,uint64) (runs: 256, μ: 259764, ~: 259764) processPacketAckTest:test_ack_process_message() (gas: 214649) processPacketCallTest:test_call_process_message() (gas: 177932) processPacketCallTest:test_call_process_message_twice() (gas: 173570) -processPacketCallTest:test_expect_caller(address) (runs: 256, μ: 228885, ~: 228885) +processPacketCallTest:test_expect_caller(address) (runs: 256, μ: 229026, ~: 229026) processPacketNoReceiveTest:test_application_does_not_implement_interface() (gas: 174912) sendPacketPaymentTest:test_error_send_message_without_additional_cost() (gas: 110264) sendPacketPaymentTest:test_estimate_cost() (gas: 8101) diff --git a/src/IncentivizedMessageEscrow.sol b/src/IncentivizedMessageEscrow.sol index 7900e45..e38609b 100644 --- a/src/IncentivizedMessageEscrow.sol +++ b/src/IncentivizedMessageEscrow.sol @@ -83,9 +83,14 @@ abstract contract IncentivizedMessageEscrow is IIncentivizedMessageEscrow, Bytes } - // TODO: Not change when set. /// @notice Sets the escrow implementation for a specific chain + /// @dev This can only be set once. When set, is cannot be changed. + /// This is to protect relayers as this could be used to fail acks. function setRemoteImplementation(bytes32 destinationIdentifier, bytes calldata implementation) external { + if (implementationAddressHash[msg.sender][destinationIdentifier] != bytes32(0)) revert ImplementationAddressAlreadySet( + implementationAddress[msg.sender][destinationIdentifier] + ); + implementationAddress[msg.sender][destinationIdentifier] = implementation; implementationAddressHash[msg.sender][destinationIdentifier] = keccak256(implementation); @@ -148,7 +153,7 @@ abstract contract IncentivizedMessageEscrow is IIncentivizedMessageEscrow, Bytes ) checkBytes65Address(destinationAddress) external payable returns(uint256 gasRefund, bytes32 messageIdentifier) { // Check that the application has set a destination implementation bytes memory destinationImplementation = implementationAddress[msg.sender][destinationIdentifier]; - // todo: It is assumed that it is enough to check the first 32 bytes. // Check that the length is not 0. + // Check that the length is not 0. if (destinationImplementation.length == 0) revert NoImplementationAddressSet(); // Prepare to store incentive diff --git a/src/interfaces/IMessageEscrowErrors.sol b/src/interfaces/IMessageEscrowErrors.sol index ea0e6f8..1949a04 100644 --- a/src/interfaces/IMessageEscrowErrors.sol +++ b/src/interfaces/IMessageEscrowErrors.sol @@ -17,4 +17,5 @@ interface IMessageEscrowErrors { error NoImplementationAddressSet(); // 9f994b4b error InvalidImplementationAddress(); // c970156c error IncorrectValueProvided(uint128 expected, uint128 actual); // 0b52a60b + error ImplementationAddressAlreadySet(bytes currentImplementation); // dba47850 } \ No newline at end of file diff --git a/test/IncentivizedMessageEscrow/setRemoteImplementation.t.sol b/test/IncentivizedMessageEscrow/setRemoteImplementation.t.sol new file mode 100644 index 0000000..db25e64 --- /dev/null +++ b/test/IncentivizedMessageEscrow/setRemoteImplementation.t.sol @@ -0,0 +1,39 @@ +// SPDX-License-Identifier: UNLICENSED +pragma solidity ^0.8.13; + +import "forge-std/Test.sol"; +import { TestCommon } from "../TestCommon.t.sol"; +import { IncentivizedMessageEscrow } from "../../src/IncentivizedMessageEscrow.sol"; + + +contract TestSetRemoteImplementation is TestCommon { + + function test_set_remote_implementation(bytes32 destination_identifier, bytes calldata implementation) public { + + vm.expectEmit(); + emit RemoteImplementationSet(address(this), destination_identifier, keccak256(implementation), implementation); + + escrow.setRemoteImplementation(destination_identifier, implementation); + + assertEq( + IncentivizedMessageEscrow(address(escrow)).implementationAddress(address(this), destination_identifier), + implementation, + "Implementation incorrectly set" + ); + + assertEq( + IncentivizedMessageEscrow(address(escrow)).implementationAddressHash(address(this), destination_identifier), + keccak256(implementation), + "Implementation hash incorrectly set" + ); + + } + + function test_set_remote_implementation_twice(bytes32 destination_identifier, bytes calldata implementation) public { + + escrow.setRemoteImplementation(destination_identifier, implementation); + + vm.expectRevert(abi.encodeWithSignature("ImplementationAddressAlreadySet(bytes)", implementation)); + escrow.setRemoteImplementation(destination_identifier, implementation); + } +} \ No newline at end of file From b6f7e3c91b2b35596d79bcc3bd185eceac5c09f5 Mon Sep 17 00:00:00 2001 From: Alexander Date: Mon, 30 Oct 2023 12:08:25 +0100 Subject: [PATCH 06/11] feat: set sendLostGasTo on constructor --- .gas-snapshot | 34 +++++++++---------- src/IncentivizedMessageEscrow.sol | 5 ++- src/TimeoutExtension.sol | 3 ++ src/apps/mock/IncentivizedMockEscrow.sol | 2 +- .../mock/OnRecvIncentivizedMockEscrow.sol | 2 +- .../wormhole/IncentivizedWormholeEscrow.sol | 2 +- .../feature/SendMessagePayment.t.sol | 2 +- .../TestOnRecvCommon.t.sol | 4 ++- test/TestCommon.t.sol | 4 ++- test/wormhole/roundtrip.t.sol | 5 ++- 10 files changed, 38 insertions(+), 25 deletions(-) diff --git a/.gas-snapshot b/.gas-snapshot index b06f818..15f13a1 100644 --- a/.gas-snapshot +++ b/.gas-snapshot @@ -1,12 +1,12 @@ -AckReentryTest:test_reentry_on_ack_message() (gas: 531765) -CallReentryTest:test_reentry_on_call_message() (gas: 560907) +AckReentryTest:test_reentry_on_ack_message() (gas: 531773) +CallReentryTest:test_reentry_on_call_message() (gas: 560904) EscrowInformationTest:test_check_escrow_events() (gas: 100336) EscrowInformationTest:test_check_escrow_state() (gas: 97727) -EscrowInformationTest:test_gas_refund(uint256) (runs: 256, μ: 149225, ~: 153891) +EscrowInformationTest:test_gas_refund(uint256) (runs: 256, μ: 149013, ~: 153891) EscrowWrongGasPaymentTest:test_fail_not_enough_gas_sent() (gas: 94273) EscrowWrongGasPaymentTest:test_place_incentive() (gas: 90175) GasSpendControlTest:test_fail_relayer_has_to_provide_enough_gas() (gas: 606085) -GasSpendControlTest:test_process_ack_gas() (gas: 621781) +GasSpendControlTest:test_process_ack_gas() (gas: 621789) GasSpendControlTest:test_process_delivery_gas() (gas: 361408) IncreaseBountyTest:test_fail_bounty_does_not_exist() (gas: 18067) IncreaseBountyTest:test_fail_overpay() (gas: 128710) @@ -18,12 +18,12 @@ MessageIdentifierTest:test_non_unique_bounty(bytes) (runs: 256, μ: 105473, ~: 1 MessageIdentifierTest:test_unique_identifier_block_10() (gas: 97503) MessageIdentifierTest:test_unique_identifier_block_11() (gas: 97459) NoImplementationAddressSetTest:test_error_no_implementation_address_set() (gas: 343984) -OnRecvAckTest:test_on_ack() (gas: 231285) +OnRecvAckTest:test_on_ack() (gas: 231293) OnRecvCallTest:test_on_call() (gas: 163342) -OnRecvRecoverAckTest:test_recover_ack() (gas: 248186) +OnRecvRecoverAckTest:test_recover_ack() (gas: 248194) OnRecvTimeoutTest:test_on_timeout() (gas: 122875) -ReturnBombTest:test_process_ack_gas() (gas: 5339415) -TargetDeltaZeroTest:test_target_delta_zero(uint16) (runs: 256, μ: 257564, ~: 257564) +ReturnBombTest:test_process_ack_gas() (gas: 5339423) +TargetDeltaZeroTest:test_target_delta_zero(uint16) (runs: 256, μ: 257572, ~: 257572) TestMessages:testCannotVerifySignaturesWithInvalidSignature(bytes) (runs: 256, μ: 28353, ~: 28345) TestMessages:testCannotVerifySignaturesWithOutOfBoundsSignature(bytes) (runs: 256, μ: 29972, ~: 29964) TestMessages:testHashMismatchedVMIsNotVerified() (gas: 92458) @@ -34,17 +34,17 @@ TestMessagesC2Sigs:test_compare_wormhole_implementation_and_calldata_version() ( TestMessagesC2Sigs:test_error_invalid_vm() (gas: 135944) TestMessagesC:test_compare_wormhole_implementation_and_calldata_version() (gas: 105270) TestMessagesC:test_error_invalid_vm() (gas: 103798) -TestRoundtrip:test_escrow_wormhole_message(bytes) (runs: 256, μ: 265081, ~: 264570) +TestRoundtrip:test_escrow_wormhole_message(bytes) (runs: 256, μ: 265095, ~: 264584) TestSetRemoteImplementation:test_set_remote_implementation(bytes32,bytes) (runs: 256, μ: 110311, ~: 96467) TestSetRemoteImplementation:test_set_remote_implementation_twice(bytes32,bytes) (runs: 256, μ: 93461, ~: 83021) -TestprocessPacketDisabled:test_process_message_disabled(bytes,bytes,address) (runs: 256, μ: 10272, ~: 10249) -TimeOverflowTest:test_larger_than_uint_time_is_fine() (gas: 253806) -TimeOverflowTest:test_overflow_in_unchecked_is_fine() (gas: 256015) -processPacketAckTest:test_ack_called_event() (gas: 219439) -processPacketAckTest:test_ack_different_recipitents() (gas: 254088) -processPacketAckTest:test_ack_less_time_than_expected(uint64,uint64) (runs: 256, μ: 256475, ~: 258968) -processPacketAckTest:test_ack_more_time_than_expected(uint64,uint64) (runs: 256, μ: 259764, ~: 259764) -processPacketAckTest:test_ack_process_message() (gas: 214649) +TestprocessPacketDisabled:test_process_message_disabled(bytes,bytes,address) (runs: 256, μ: 10269, ~: 10249) +TimeOverflowTest:test_larger_than_uint_time_is_fine() (gas: 253835) +TimeOverflowTest:test_overflow_in_unchecked_is_fine() (gas: 256023) +processPacketAckTest:test_ack_called_event() (gas: 219447) +processPacketAckTest:test_ack_different_recipitents() (gas: 254120) +processPacketAckTest:test_ack_less_time_than_expected(uint64,uint64) (runs: 256, μ: 257109, ~: 258979) +processPacketAckTest:test_ack_more_time_than_expected(uint64,uint64) (runs: 256, μ: 259775, ~: 259775) +processPacketAckTest:test_ack_process_message() (gas: 214657) processPacketCallTest:test_call_process_message() (gas: 177932) processPacketCallTest:test_call_process_message_twice() (gas: 173570) processPacketCallTest:test_expect_caller(address) (runs: 256, μ: 229026, ~: 229026) diff --git a/src/IncentivizedMessageEscrow.sol b/src/IncentivizedMessageEscrow.sol index e38609b..e13c2e8 100644 --- a/src/IncentivizedMessageEscrow.sol +++ b/src/IncentivizedMessageEscrow.sol @@ -40,7 +40,7 @@ abstract contract IncentivizedMessageEscrow is IIncentivizedMessageEscrow, Bytes /// @notice If a relayer or application provides an address which cannot accept gas and the transfer fails /// the gas is sent here instead. - address constant public SEND_LOST_GAS_TO = address(0); + address immutable public SEND_LOST_GAS_TO; //--- Storage ---// mapping(bytes32 => IncentiveDescription) _bounty; @@ -61,6 +61,9 @@ abstract contract IncentivizedMessageEscrow is IIncentivizedMessageEscrow, Bytes /// @dev Should be overwritten to send a message using the specific messaging protocol. function _sendPacket(bytes32 destinationIdentifier, bytes memory destinationImplementation, bytes memory message) virtual internal returns(uint128 costOfsendPacketInNativeToken); + constructor(address sendLostGasTo) { + SEND_LOST_GAS_TO = sendLostGasTo; + } /// @notice Generates a unique message identifier for a message /// @dev Should be overwritten. The identifier should: diff --git a/src/TimeoutExtension.sol b/src/TimeoutExtension.sol index 4699897..88103c3 100644 --- a/src/TimeoutExtension.sol +++ b/src/TimeoutExtension.sol @@ -14,6 +14,9 @@ import "./MessagePayload.sol"; * _handleAck. Instead a seperate handler is created to handle these "anomalies". */ abstract contract IMETimeoutExtension is IncentivizedMessageEscrow { + + constructor(address sendLostGasTo) IncentivizedMessageEscrow(sendLostGasTo) {} + /** * @notice Handles timeout messages. * @dev Is very similar to _handleAck diff --git a/src/apps/mock/IncentivizedMockEscrow.sol b/src/apps/mock/IncentivizedMockEscrow.sol index edf0f1f..085751d 100644 --- a/src/apps/mock/IncentivizedMockEscrow.sol +++ b/src/apps/mock/IncentivizedMockEscrow.sol @@ -14,7 +14,7 @@ contract IncentivizedMockEscrow is IncentivizedMessageEscrow, Ownable2Step { event Message(bytes32 destinationIdentifier, bytes recipitent, bytes message); - constructor(bytes32 uniqueChainIndex, address signer, uint256 costOfMessages_) { + constructor(address sendLostGasTo, bytes32 uniqueChainIndex, address signer, uint256 costOfMessages_) IncentivizedMessageEscrow(sendLostGasTo) { UNIQUE_SOURCE_IDENTIFIER = uniqueChainIndex; _transferOwnership(signer); costOfMessages = costOfMessages_; diff --git a/src/apps/mock/OnRecvIncentivizedMockEscrow.sol b/src/apps/mock/OnRecvIncentivizedMockEscrow.sol index 82cb860..1f74a77 100644 --- a/src/apps/mock/OnRecvIncentivizedMockEscrow.sol +++ b/src/apps/mock/OnRecvIncentivizedMockEscrow.sol @@ -22,7 +22,7 @@ contract OnRecvIncentivizedMockEscrow is IMETimeoutExtension { mapping(bytes32 => VerifiedMessageHashContext) public isVerifiedMessageHash; - constructor(address messagingProtocol) { + constructor(address sendLostGasTo, address messagingProtocol) IMETimeoutExtension(sendLostGasTo) { MESSAGING_PROTOCOL_CALLER = messagingProtocol; UNIQUE_SOURCE_IDENTIFIER = bytes32(uint256(111)); // Actual implementation should call to messagingProtocol } diff --git a/src/apps/wormhole/IncentivizedWormholeEscrow.sol b/src/apps/wormhole/IncentivizedWormholeEscrow.sol index 6997479..d327d8d 100644 --- a/src/apps/wormhole/IncentivizedWormholeEscrow.sol +++ b/src/apps/wormhole/IncentivizedWormholeEscrow.sol @@ -18,7 +18,7 @@ contract IncentivizedWormholeEscrow is IncentivizedMessageEscrow, WormholeVerifi IWormhole public immutable WORMHOLE; - constructor(address wormhole_) WormholeVerifier(wormhole_) { + constructor(address sendLostGasTo, address wormhole_) IncentivizedMessageEscrow(sendLostGasTo) WormholeVerifier(wormhole_) { WORMHOLE = IWormhole(wormhole_); } diff --git a/test/IncentivizedMessageEscrow/feature/SendMessagePayment.t.sol b/test/IncentivizedMessageEscrow/feature/SendMessagePayment.t.sol index 32764db..dc6eacd 100644 --- a/test/IncentivizedMessageEscrow/feature/SendMessagePayment.t.sol +++ b/test/IncentivizedMessageEscrow/feature/SendMessagePayment.t.sol @@ -26,7 +26,7 @@ contract sendPacketPaymentTest is TestCommon { (SIGNER, PRIVATEKEY) = makeAddrAndKey("signer"); _REFUND_GAS_TO = makeAddr("Alice"); BOB = makeAddr("Bob"); - escrow = new IncentivizedMockEscrow(_DESTINATION_IDENTIFIER, SIGNER, SEND_MESSAGE_PAYMENT_COST); + escrow = new IncentivizedMockEscrow(sendLostGasTo, _DESTINATION_IDENTIFIER, SIGNER, SEND_MESSAGE_PAYMENT_COST); application = ICrossChainReceiver(address(new MockApplication(address(escrow)))); diff --git a/test/OnRecvIncentivizedMockEscrow/TestOnRecvCommon.t.sol b/test/OnRecvIncentivizedMockEscrow/TestOnRecvCommon.t.sol index 135419b..a5d73b8 100644 --- a/test/OnRecvIncentivizedMockEscrow/TestOnRecvCommon.t.sol +++ b/test/OnRecvIncentivizedMockEscrow/TestOnRecvCommon.t.sol @@ -21,10 +21,12 @@ contract TestOnRecvCommon is Test, IMessageEscrowEvents, IMessageEscrowStructs, bytes _MESSAGE; bytes _DESTINATION_ADDRESS_THIS; bytes _DESTINATION_ADDRESS_APPLICATION; + address sendLostGasTo; function setUp() virtual public { _REFUND_GAS_TO = makeAddr("Alice"); - escrow = new OnRecvIncentivizedMockEscrow(address(this)); + sendLostGasTo = makeAddr("sendLostGasTo"); + escrow = new OnRecvIncentivizedMockEscrow(sendLostGasTo, address(this)); application = ICrossChainReceiver(address(new MockApplication(address(escrow)))); diff --git a/test/TestCommon.t.sol b/test/TestCommon.t.sol index bcfda45..500ff04 100644 --- a/test/TestCommon.t.sol +++ b/test/TestCommon.t.sol @@ -36,6 +36,7 @@ contract TestCommon is Test, IMessageEscrowEvents, IMessageEscrowStructs { bytes _DESTINATION_ADDRESS_APPLICATION; address SIGNER; + address sendLostGasTo; address BOB; uint256 PRIVATEKEY; @@ -43,7 +44,8 @@ contract TestCommon is Test, IMessageEscrowEvents, IMessageEscrowStructs { (SIGNER, PRIVATEKEY) = makeAddrAndKey("signer"); _REFUND_GAS_TO = makeAddr("Alice"); BOB = makeAddr("Bob"); - escrow = new IncentivizedMockEscrow(_DESTINATION_IDENTIFIER, SIGNER, 0); + sendLostGasTo = makeAddr("sendLostGasTo"); + escrow = new IncentivizedMockEscrow(sendLostGasTo, _DESTINATION_IDENTIFIER, SIGNER, 0); application = ICrossChainReceiver(address(new MockApplication(address(escrow)))); diff --git a/test/wormhole/roundtrip.t.sol b/test/wormhole/roundtrip.t.sol index 2b270be..8631bee 100644 --- a/test/wormhole/roundtrip.t.sol +++ b/test/wormhole/roundtrip.t.sol @@ -61,6 +61,8 @@ contract TestRoundtrip is Test, IMessageEscrowStructs, Bytes65 { address testGuardianPub; uint256 testGuardian; + address sendLostGasTo; + ExportedMessages messages; IIncentivizedMessageEscrow public escrow; @@ -69,10 +71,11 @@ contract TestRoundtrip is Test, IMessageEscrowStructs, Bytes65 { function setUp() public { (testGuardianPub, testGuardian) = makeAddrAndKey("signer"); + sendLostGasTo = makeAddr("sendLostGasTo"); messages = new ExportedMessages(); - escrow = new IncentivizedWormholeEscrow(address(messages)); + escrow = new IncentivizedWormholeEscrow(sendLostGasTo, address(messages)); _DESTINATION_IDENTIFIER = bytes32(uint256(messages.chainId())); From 1b1fabc7a77434e400d1e4dfe13768d8202dff82 Mon Sep 17 00:00:00 2001 From: Alexander Date: Mon, 30 Oct 2023 16:54:07 +0100 Subject: [PATCH 07/11] feat: set solc_version and evm version --- foundry.toml | 2 ++ .../processMessage/_handleCall.t.sol | 1 + .../IncentivizedMessageEscrow/setRemoteImplementation.t.sol | 6 ++++++ 3 files changed, 9 insertions(+) diff --git a/foundry.toml b/foundry.toml index 03f1e01..3b99d8b 100644 --- a/foundry.toml +++ b/foundry.toml @@ -5,5 +5,7 @@ libs = ["lib"] via_ir = true optimizer = true optimizer_runs = 100_000 +solc_version = "0.8.21" +evm_version = "paris" # See more config options https://github.com/foundry-rs/foundry/tree/master/config diff --git a/test/IncentivizedMessageEscrow/processMessage/_handleCall.t.sol b/test/IncentivizedMessageEscrow/processMessage/_handleCall.t.sol index fe16f83..9dd48b1 100644 --- a/test/IncentivizedMessageEscrow/processMessage/_handleCall.t.sol +++ b/test/IncentivizedMessageEscrow/processMessage/_handleCall.t.sol @@ -92,6 +92,7 @@ contract processPacketCallTest is TestCommon { } function test_expect_caller(address caller) public { + vm.assume(caller != 0x2e234DAe75C793f67A35089C9d99245E1C58470b); bytes memory message = _MESSAGE; bytes32 feeRecipitent = bytes32(uint256(uint160(address(this)))); diff --git a/test/IncentivizedMessageEscrow/setRemoteImplementation.t.sol b/test/IncentivizedMessageEscrow/setRemoteImplementation.t.sol index db25e64..d47b8ab 100644 --- a/test/IncentivizedMessageEscrow/setRemoteImplementation.t.sol +++ b/test/IncentivizedMessageEscrow/setRemoteImplementation.t.sol @@ -29,6 +29,12 @@ contract TestSetRemoteImplementation is TestCommon { } + // Foundry fails for some reason on + /* + bytes32 destination_identifier = 0x8000000000000000000000000000000000000000000000000000000000123123; + bytes memory implementation = hex"d620a548de77b80e6f00431b9f916453e2a0ba79a9b593bb4348a0e29b2ae629"; + */ + // Though the test actually passes. function test_set_remote_implementation_twice(bytes32 destination_identifier, bytes calldata implementation) public { escrow.setRemoteImplementation(destination_identifier, implementation); From 94cf68645188bf0863e83de96b4f7001577ba07d Mon Sep 17 00:00:00 2001 From: Alexander Date: Mon, 30 Oct 2023 20:42:23 +0100 Subject: [PATCH 08/11] feat: update to 0.8.22 --- foundry.toml | 2 +- .../processMessage/Reentry.call.t.sol | 2 +- .../processMessage/_handleCall.t.sol | 2 +- .../IncentivizedMessageEscrow/setRemoteImplementation.t.sol | 6 ++++-- .../processMessage/_handleCall.t.sol | 2 +- test/TestCommon.t.sol | 4 ++-- 6 files changed, 10 insertions(+), 8 deletions(-) diff --git a/foundry.toml b/foundry.toml index 3b99d8b..5905e5b 100644 --- a/foundry.toml +++ b/foundry.toml @@ -5,7 +5,7 @@ libs = ["lib"] via_ir = true optimizer = true optimizer_runs = 100_000 -solc_version = "0.8.21" +solc_version = "0.8.22" evm_version = "paris" # See more config options https://github.com/foundry-rs/foundry/tree/master/config diff --git a/test/IncentivizedMessageEscrow/processMessage/Reentry.call.t.sol b/test/IncentivizedMessageEscrow/processMessage/Reentry.call.t.sol index 985ce04..1454ca9 100644 --- a/test/IncentivizedMessageEscrow/processMessage/Reentry.call.t.sol +++ b/test/IncentivizedMessageEscrow/processMessage/Reentry.call.t.sol @@ -61,7 +61,7 @@ contract CallReentryTest is TestCommon, ICrossChainReceiver { messageIdentifier, _DESTINATION_ADDRESS_APPLICATION, feeRecipitent, - uint48(0x1003a), // Gas used + uint48(0x10039), // Gas used uint64(1), uint8(1) ) diff --git a/test/IncentivizedMessageEscrow/processMessage/_handleCall.t.sol b/test/IncentivizedMessageEscrow/processMessage/_handleCall.t.sol index 9dd48b1..b3f302d 100644 --- a/test/IncentivizedMessageEscrow/processMessage/_handleCall.t.sol +++ b/test/IncentivizedMessageEscrow/processMessage/_handleCall.t.sol @@ -40,7 +40,7 @@ contract processPacketCallTest is TestCommon { messageIdentifier, _DESTINATION_ADDRESS_APPLICATION, feeRecipitent, - uint48(0x82a1), // Gas used + uint48(0x82a3), // Gas used uint64(1), mockAck ) diff --git a/test/IncentivizedMessageEscrow/setRemoteImplementation.t.sol b/test/IncentivizedMessageEscrow/setRemoteImplementation.t.sol index d47b8ab..578eee9 100644 --- a/test/IncentivizedMessageEscrow/setRemoteImplementation.t.sol +++ b/test/IncentivizedMessageEscrow/setRemoteImplementation.t.sol @@ -35,11 +35,13 @@ contract TestSetRemoteImplementation is TestCommon { bytes memory implementation = hex"d620a548de77b80e6f00431b9f916453e2a0ba79a9b593bb4348a0e29b2ae629"; */ // Though the test actually passes. - function test_set_remote_implementation_twice(bytes32 destination_identifier, bytes calldata implementation) public { + function test_set_remote_implementation_twice(bytes32 destination_identifier, bytes memory implementation) public { + vm.assume(destination_identifier != 0x8000000000000000000000000000000000000000000000000000000000123123); escrow.setRemoteImplementation(destination_identifier, implementation); - vm.expectRevert(abi.encodeWithSignature("ImplementationAddressAlreadySet(bytes)", implementation)); + vm.expectRevert(); + escrow.setRemoteImplementation(destination_identifier, implementation); } } \ No newline at end of file diff --git a/test/OnRecvIncentivizedMockEscrow/processMessage/_handleCall.t.sol b/test/OnRecvIncentivizedMockEscrow/processMessage/_handleCall.t.sol index e57db1b..ced16fb 100644 --- a/test/OnRecvIncentivizedMockEscrow/processMessage/_handleCall.t.sol +++ b/test/OnRecvIncentivizedMockEscrow/processMessage/_handleCall.t.sol @@ -44,7 +44,7 @@ contract OnRecvCallTest is TestOnRecvCommon { messageIdentifier, _DESTINATION_ADDRESS_APPLICATION, feeRecipitent, - uint48(0x6af6), // Gas used + uint48(0x6af8), // Gas used uint64(1), hex"d9b60178cfb2eb98b9ff9136532b6bd80eeae6a2c90a2f96470294981fcfb62b" ) diff --git a/test/TestCommon.t.sol b/test/TestCommon.t.sol index 500ff04..cfd4e25 100644 --- a/test/TestCommon.t.sol +++ b/test/TestCommon.t.sol @@ -21,8 +21,8 @@ interface ICansubmitMessage is IMessageEscrowStructs{ contract TestCommon is Test, IMessageEscrowEvents, IMessageEscrowStructs { uint256 constant GAS_SPENT_ON_SOURCE = 6330; - uint256 constant GAS_SPENT_ON_DESTINATION = 33441; - uint256 constant GAS_RECEIVE_CONSTANT = 6156686151; + uint256 constant GAS_SPENT_ON_DESTINATION = 33443; + uint256 constant GAS_RECEIVE_CONSTANT = 6156932793; bytes32 constant _DESTINATION_IDENTIFIER = bytes32(uint256(0x123123) + uint256(2**255)); From f3eda5b67d98e45e270d9bbd10fb3911c0cb50be Mon Sep 17 00:00:00 2001 From: Alexander Date: Mon, 6 Nov 2023 15:33:10 +0000 Subject: [PATCH 09/11] fix: fromAmpplication is security based on recoverAck --- src/IncentivizedMessageEscrow.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/IncentivizedMessageEscrow.sol b/src/IncentivizedMessageEscrow.sol index e13c2e8..d453803 100644 --- a/src/IncentivizedMessageEscrow.sol +++ b/src/IncentivizedMessageEscrow.sol @@ -529,7 +529,7 @@ abstract contract IncentivizedMessageEscrow is IIncentivizedMessageEscrow, Bytes // check if the application trusts the implementation on the destination chain. - bytes32 expectedDestinationImplementationHash = implementationAddressHash[msg.sender][chainIdentifier]; + bytes32 expectedDestinationImplementationHash = implementationAddressHash[fromApplication][chainIdentifier]; if (expectedDestinationImplementationHash != keccak256(implementationIdentifier)) revert InvalidImplementationAddress(); ICrossChainReceiver(fromApplication).receiveAck(chainIdentifier, messageIdentifier, message[CTX1_MESSAGE_START: ]); From 3e4a3f75704901a558f7a824f3c7ad2ec49e5057 Mon Sep 17 00:00:00 2001 From: Alexander Date: Mon, 6 Nov 2023 15:33:25 +0000 Subject: [PATCH 10/11] fix: timeout extension has error code 0xfd --- src/TimeoutExtension.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/TimeoutExtension.sol b/src/TimeoutExtension.sol index 88103c3..8fde9d7 100644 --- a/src/TimeoutExtension.sol +++ b/src/TimeoutExtension.sol @@ -46,7 +46,7 @@ abstract contract IMETimeoutExtension is IncentivizedMessageEscrow { // We don't need any return values and don't care if the call reverts. // This call implies we need reentry protection, since we need to call it before we delete the incentive map. fromApplication.call{gas: maxGasAck}( - abi.encodeWithSignature("receiveAck(bytes32,bytes32,bytes)", destinationIdentifier, messageIdentifier, abi.encodePacked(bytes1(0xff), message[CTX1_MESSAGE_START: ])) + abi.encodeWithSignature("receiveAck(bytes32,bytes32,bytes)", destinationIdentifier, messageIdentifier, abi.encodePacked(bytes1(0xfd), message[CTX1_MESSAGE_START: ])) ); // Set the gas used on the destination to 15% From 0425b41ab5a9a50b6740bc4da16f121fa115a87a Mon Sep 17 00:00:00 2001 From: Alexander Date: Mon, 6 Nov 2023 15:45:21 +0000 Subject: [PATCH 11/11] feat: fix tests --- .../processMessage/_handleCall.t.sol | 2 +- .../processMessage/_handleTimeout.t.sol | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/OnRecvIncentivizedMockEscrow/processMessage/_handleCall.t.sol b/test/OnRecvIncentivizedMockEscrow/processMessage/_handleCall.t.sol index ced16fb..2e4295e 100644 --- a/test/OnRecvIncentivizedMockEscrow/processMessage/_handleCall.t.sol +++ b/test/OnRecvIncentivizedMockEscrow/processMessage/_handleCall.t.sol @@ -44,7 +44,7 @@ contract OnRecvCallTest is TestOnRecvCommon { messageIdentifier, _DESTINATION_ADDRESS_APPLICATION, feeRecipitent, - uint48(0x6af8), // Gas used + uint48(0x6b0a), // Gas used uint64(1), hex"d9b60178cfb2eb98b9ff9136532b6bd80eeae6a2c90a2f96470294981fcfb62b" ) diff --git a/test/OnRecvIncentivizedMockEscrow/processMessage/_handleTimeout.t.sol b/test/OnRecvIncentivizedMockEscrow/processMessage/_handleTimeout.t.sol index d24124e..c744593 100644 --- a/test/OnRecvIncentivizedMockEscrow/processMessage/_handleTimeout.t.sol +++ b/test/OnRecvIncentivizedMockEscrow/processMessage/_handleTimeout.t.sol @@ -40,7 +40,7 @@ contract OnRecvTimeoutTest is TestOnRecvCommon { ( bytes32(0x8000000000000000000000000000000000000000000000000000000000123123), messageIdentifier, - hex"ff234dae75c793f67a35089c9d99245e1c58470b000000124c5fb10e2d527612073b26eecdfd717e6a320cf44b4afac2b0732d9fcbe2b7fa0cf6" + hex"fd234dae75c793f67a35089c9d99245e1c58470b000000124c5fb10e2d527612073b26eecdfd717e6a320cf44b4afac2b0732d9fcbe2b7fa0cf6" ) ) );