Skip to content

Commit

Permalink
feat: add source identifier to message identifier storage on remote
Browse files Browse the repository at this point in the history
  • Loading branch information
reednaa committed Mar 20, 2024
1 parent 20c27d3 commit c7eb07e
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 17 deletions.
20 changes: 10 additions & 10 deletions src/IncentivizedMessageEscrow.sol
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ abstract contract IncentivizedMessageEscrow is IIncentivizedMessageEscrow, Bytes
mapping(bytes32 => IncentiveDescription) _bounty;

/** @notice A hash of the emitted message on receive such that we can emit a similar one. */
mapping(bytes => mapping(bytes32 => bytes32)) _messageDelivered;
mapping(bytes32 => mapping(bytes => mapping(bytes32 => bytes32))) _messageDelivered;

// Maps applications to their escrow implementations.
mapping(address => mapping(bytes32 => bytes)) public implementationAddress;
Expand Down Expand Up @@ -168,8 +168,8 @@ abstract contract IncentivizedMessageEscrow is IIncentivizedMessageEscrow, Bytes
* @notice Returns a hash of the ack unless there was no ack then it returns bytes32(uint256(1));
* If the message hasn't been delivered yet it still returns bytes32(0)
*/
function messageDelivered(bytes calldata sourceImplementationIdentifier, bytes32 messageIdentifier) external view returns(bytes32 hasMessageBeenExecuted) {
return _messageDelivered[sourceImplementationIdentifier][messageIdentifier];
function messageDelivered(bytes32 sourceIdentifier, bytes calldata sourceImplementationIdentifier, bytes32 messageIdentifier) external view returns(bytes32 hasMessageBeenExecuted) {
return _messageDelivered[sourceIdentifier][sourceImplementationIdentifier][messageIdentifier];
}

/**
Expand Down Expand Up @@ -396,9 +396,9 @@ abstract contract IncentivizedMessageEscrow is IIncentivizedMessageEscrow, Bytes
// The 3 next lines act as a reentry guard, so this call doesn't have to be protected by reentry.
// We will re-set _messageDelivered[messageIdentifier] again later as the hash of the ack, however, we need re-entry protection
// so applications don't try to claim incentives multiple times. So, we set it now and change it later.
bytes32 messageState = _messageDelivered[sourceImplementationIdentifier][messageIdentifier];
bytes32 messageState = _messageDelivered[sourceIdentifier][sourceImplementationIdentifier][messageIdentifier];
if (messageState != bytes32(0)) revert MessageAlreadySpent();
_messageDelivered[sourceImplementationIdentifier][messageIdentifier] = bytes32(uint256(1));
_messageDelivered[sourceIdentifier][sourceImplementationIdentifier][messageIdentifier] = bytes32(uint256(1));

// Deliver message to application.
// Decode gas limit, application address and sending application.
Expand Down Expand Up @@ -434,7 +434,7 @@ abstract contract IncentivizedMessageEscrow is IIncentivizedMessageEscrow, Bytes
);

// Store a hash of the acknowledgement so we can later retry a potentially invalid ack proof.
_messageDelivered[sourceImplementationIdentifier][messageIdentifier] = keccak256(receiveAckWithContext);
_messageDelivered[sourceIdentifier][sourceImplementationIdentifier][messageIdentifier] = keccak256(receiveAckWithContext);

// Message has been delivered and shouldn't be executed again.
emit MessageDelivered(messageIdentifier);
Expand Down Expand Up @@ -463,7 +463,7 @@ abstract contract IncentivizedMessageEscrow is IIncentivizedMessageEscrow, Bytes
);

// Store a hash of the acknowledgement so we can later retry a potentially invalid ack proof.
_messageDelivered[sourceImplementationIdentifier][messageIdentifier] = keccak256(receiveAckWithContext);
_messageDelivered[sourceIdentifier][sourceImplementationIdentifier][messageIdentifier] = keccak256(receiveAckWithContext);

// Message has been delivered and shouldn't be executed again.
emit MessageDelivered(messageIdentifier);
Expand Down Expand Up @@ -510,7 +510,7 @@ abstract contract IncentivizedMessageEscrow is IIncentivizedMessageEscrow, Bytes
);

// Store a hash of the acknowledgement so we can later retry a potentially invalid ack proof.
_messageDelivered[sourceImplementationIdentifier][messageIdentifier] = keccak256(receiveAckWithContext);
_messageDelivered[sourceIdentifier][sourceImplementationIdentifier][messageIdentifier] = keccak256(receiveAckWithContext);

// Why is the messageDelivered event emitted before _sendPacket?
// Because it lets us pop messageIdentifier from the stack. This avoid a stack limit reached error.
Expand Down Expand Up @@ -923,7 +923,7 @@ abstract contract IncentivizedMessageEscrow is IIncentivizedMessageEscrow, Bytes
// This makes it ever so slighly easier to retry messages.
bytes32 messageIdentifier = bytes32(receiveAckWithContext[MESSAGE_IDENTIFIER_START:MESSAGE_IDENTIFIER_END]);

bytes32 storedAckHash = _messageDelivered[implementationIdentifier][messageIdentifier];
bytes32 storedAckHash = _messageDelivered[sourceIdentifier][implementationIdentifier][messageIdentifier];
// First, check if there is actually an appropiate hash at the message identifier.
// Then, check if the storedAckHash matches the executed one.
if (storedAckHash == bytes32(0) || storedAckHash != keccak256(receiveAckWithContext)) revert CannotRetryWrongMessage(storedAckHash, keccak256(receiveAckWithContext));
Expand Down Expand Up @@ -976,7 +976,7 @@ abstract contract IncentivizedMessageEscrow is IIncentivizedMessageEscrow, Bytes
// Get the message identifier from the message.
bytes32 messageIdentifier = bytes32(message[MESSAGE_IDENTIFIER_START:MESSAGE_IDENTIFIER_END]);
// Read the status of the package at MessageIdentifier.
bytes32 storedAckHash = _messageDelivered[implementationIdentifier][messageIdentifier];
bytes32 storedAckHash = _messageDelivered[sourceIdentifier][implementationIdentifier][messageIdentifier];
// If has already been processed, then don't allow timeouting the message. Instead, it should be retried.
if (storedAckHash != bytes32(0)) revert MessageAlreadyProcessed();
// This also protects a relayer that delivered a timedout message.
Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/IIncentivizedMessageEscrow.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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 messageDelivered(bytes calldata sourceImplementationIdentifier, bytes32 messageIdentifier) external view returns(bytes32 hasMessageBeenExecuted);
function messageDelivered(bytes32 sourceIdentifier, bytes calldata sourceImplementationIdentifier, bytes32 messageIdentifier) external view returns(bytes32 hasMessageBeenExecuted);

function increaseBounty(
bytes32 messageIdentifier,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ contract GasSpendControlTest is TestCommon {
messageIdentifier,
_DESTINATION_ADDRESS_APPLICATION,
destinationFeeRecipient,
uint48(0x368c3), // Gas used
uint48(0x3697d), // Gas used
uint64(1),
bytes1(0xff), // This states that the call went wrong.
message
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ contract processPacketNoReceiveTest is TestCommon {
messageIdentifier,
_DESTINATION_ADDRESS_THIS,
feeRecipient,
uint48(0x8296), // Gas used
uint48(0x8350), // Gas used
uint64(1),
abi.encodePacked(bytes1(0xff)),
message
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ contract CallReentryTest is TestCommon, ICrossChainReceiver {
messageIdentifier,
_DESTINATION_ADDRESS_APPLICATION,
feeRecipient,
uint48(0xfc1d), // Gas used
uint48(0xfd07), // Gas used
uint64(1),
uint8(1)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ contract processPacketCallTest is TestCommon {
messageIdentifier,
_DESTINATION_ADDRESS_APPLICATION,
feeRecipient,
uint48(0x7cbe), // Gas used
uint48(0x7d66), // Gas used
uint64(1),
mockAck
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ contract OnRecvCallTest is TestOnRecvCommon {
messageIdentifier,
_DESTINATION_ADDRESS_APPLICATION,
feeRecipient,
uint48(0x6cf3), // Gas used
uint48(0x6d9b), // Gas used
uint64(1),
hex"d9b60178cfb2eb98b9ff9136532b6bd80eeae6a2c90a2f96470294981fcfb62b"
)
Expand Down
2 changes: 1 addition & 1 deletion test/TestCommon.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ interface ICansubmitMessage is IMessageEscrowStructs{
contract TestCommon is Test, IMessageEscrowEvents, IMessageEscrowStructs {

uint256 constant GAS_SPENT_ON_SOURCE = 6617;
uint256 constant GAS_SPENT_ON_DESTINATION = 31934;
uint256 constant GAS_SPENT_ON_DESTINATION = 32102;

bytes32 constant _DESTINATION_IDENTIFIER = bytes32(uint256(0x123123) + uint256(2**255));

Expand Down

0 comments on commit c7eb07e

Please sign in to comment.