Skip to content

Commit

Permalink
feat: set sendLostGasTo on constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
reednaa committed Oct 30, 2023
1 parent b5e6d80 commit b6f7e3c
Show file tree
Hide file tree
Showing 10 changed files with 38 additions and 25 deletions.
34 changes: 17 additions & 17 deletions .gas-snapshot
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down
5 changes: 4 additions & 1 deletion src/IncentivizedMessageEscrow.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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:
Expand Down
3 changes: 3 additions & 0 deletions src/TimeoutExtension.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/apps/mock/IncentivizedMockEscrow.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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_;
Expand Down
2 changes: 1 addition & 1 deletion src/apps/mock/OnRecvIncentivizedMockEscrow.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion src/apps/wormhole/IncentivizedWormholeEscrow.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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_);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))));

Expand Down
4 changes: 3 additions & 1 deletion test/OnRecvIncentivizedMockEscrow/TestOnRecvCommon.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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))));

Expand Down
4 changes: 3 additions & 1 deletion test/TestCommon.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,16 @@ contract TestCommon is Test, IMessageEscrowEvents, IMessageEscrowStructs {
bytes _DESTINATION_ADDRESS_APPLICATION;

address SIGNER;
address sendLostGasTo;
address BOB;
uint256 PRIVATEKEY;

function setUp() virtual public {
(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))));

Expand Down
5 changes: 4 additions & 1 deletion test/wormhole/roundtrip.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ contract TestRoundtrip is Test, IMessageEscrowStructs, Bytes65 {
address testGuardianPub;
uint256 testGuardian;

address sendLostGasTo;

ExportedMessages messages;

IIncentivizedMessageEscrow public escrow;
Expand All @@ -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()));

Expand Down

0 comments on commit b6f7e3c

Please sign in to comment.