Skip to content

Commit

Permalink
fix: grammer
Browse files Browse the repository at this point in the history
  • Loading branch information
reednaa committed Jan 10, 2024
1 parent bb61af1 commit a47f437
Show file tree
Hide file tree
Showing 24 changed files with 135 additions and 132 deletions.
2 changes: 1 addition & 1 deletion .gas-snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ TestprocessPacketDisabled:test_process_message_disabled(bytes,bytes,address) (ru
TimeOverflowTest:test_larger_than_uint_time_is_fine() (gas: 253819)
TimeOverflowTest:test_overflow_in_unchecked_is_fine() (gas: 255989)
processPacketAckTest:test_ack_called_event() (gas: 219449)
processPacketAckTest:test_ack_different_recipitents() (gas: 254122)
processPacketAckTest:test_ack_different_recipients() (gas: 254122)
processPacketAckTest:test_ack_less_time_than_expected(uint64,uint64) (runs: 256, μ: 256800, ~: 258981)
processPacketAckTest:test_ack_more_time_than_expected(uint64,uint64) (runs: 256, μ: 259777, ~: 259777)
processPacketAckTest:test_ack_process_message() (gas: 214659)
Expand Down
45 changes: 24 additions & 21 deletions src/IncentivizedMessageEscrow.sol
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ abstract contract IncentivizedMessageEscrow is IIncentivizedMessageEscrow, Bytes
/// @notice If a swap reverts on the destination chain, 1 bytes is sent back instead. This is the byte.
bytes1 constant public MESSAGE_REVERTED = 0xff;

/// @notice If a swap reverts on the destination chain, 1 bytes is sent back instead. This is the byte.
/// @notice If the original sender is not authorised on the application on the destination chain, 1 bytes is sent back instead. This is the byte.
bytes1 constant public NO_AUTHENTICATION = 0xfe;

/// @notice If a relayer or application provides an address which cannot accept gas and the transfer fails
Expand All @@ -59,6 +59,9 @@ abstract contract IncentivizedMessageEscrow is IIncentivizedMessageEscrow, Bytes

/// @notice Send the message to the messaging protocol.
/// @dev Should be overwritten to send a message using the specific messaging protocol.
/// If there is an additional cost to emitting messages, this cost should be caled on the function and returned
/// as costOfsendPacketInNativeToken. The function is allowed to take ERC20 tokens (transferFrom(msg.sender,...)) in which case
/// costOfsendPacketInNativeToken should be set to 0.
function _sendPacket(bytes32 destinationIdentifier, bytes memory destinationImplementation, bytes memory message) virtual internal returns(uint128 costOfsendPacketInNativeToken);

constructor(address sendLostGasTo) {
Expand Down Expand Up @@ -172,7 +175,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 sendPacket,
messageIdentifier, // An unique identifier to recover identifier to recover
messageIdentifier, // A unique message identifier
convertEVMTo65(msg.sender), // Original sender
destinationAddress, // The address to deliver the (original) message to.
incentive.maxGasDelivery, // Send the gas limit to the other chain so we can enforce it
Expand Down Expand Up @@ -217,20 +220,20 @@ abstract contract IncentivizedMessageEscrow is IIncentivizedMessageEscrow, Bytes
/**
* @notice Deliver a message which has been *signed* by a messaging protocol.
* @dev This function is intended to be called by off-chain agents.
* Please ensure that feeRecipitent can receive gas token: Either it is an EOA or a implement fallback() / receive().
* Please ensure that feeRecipient 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 _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.
* @param feeRecipient An identifier for the the fee recipient. 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 processPacket(
bytes calldata messagingProtocolContext,
bytes calldata rawMessage,
bytes32 feeRecipitent
bytes32 feeRecipient
) external virtual payable {
uint256 gasLimit = gasleft(); // uint256 is used here instead of uint48, since there is no advantage to uint48 until after we calculate the difference.

Expand All @@ -240,12 +243,12 @@ abstract contract IncentivizedMessageEscrow is IIncentivizedMessageEscrow, Bytes
// Figure out if this is a call or an ack.
bytes1 context = bytes1(message[0]);
if (context == CTX_SOURCE_TO_DESTINATION) {
bytes memory receiveAckWithContext = _handleMessage(chainIdentifier, implementationIdentifier, message, feeRecipitent, gasLimit);
bytes memory receiveAckWithContext = _handleMessage(chainIdentifier, implementationIdentifier, message, feeRecipient, gasLimit);

// 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);
_handleAck(chainIdentifier, implementationIdentifier, message, feeRecipient, gasLimit);
} else {
revert NotImplementedError();
}
Expand All @@ -256,7 +259,7 @@ abstract contract IncentivizedMessageEscrow is IIncentivizedMessageEscrow, Bytes
/**
* @notice Handles call messages.
*/
function _handleMessage(bytes32 sourceIdentifier, bytes memory sourceImplementationIdentifier, bytes calldata message, bytes32 feeRecipitent, uint256 gasLimit) internal returns(bytes memory receiveAckWithContext) {
function _handleMessage(bytes32 sourceIdentifier, bytes memory sourceImplementationIdentifier, bytes calldata message, bytes32 feeRecipient, 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]);

Expand Down Expand Up @@ -312,7 +315,7 @@ abstract contract IncentivizedMessageEscrow is IIncentivizedMessageEscrow, Bytes
bytes1(CTX_DESTINATION_TO_SOURCE), // This is a sendPacket
messageIdentifier, // message identifier
fromApplication,
feeRecipitent,
feeRecipient,
uint48(gasLimit - gasleft()), // Delay the gas limit computation until as late as possible. This should include the majority of gas spent.
uint64(block.timestamp), // If this overflows, it is fine. It is used in conjunction with a delta.
acknowledgement
Expand All @@ -333,7 +336,7 @@ abstract contract IncentivizedMessageEscrow is IIncentivizedMessageEscrow, Bytes
/**
* @notice Handles ack messages.
*/
function _handleAck(bytes32 destinationIdentifier, bytes memory destinationImplementationIdentifier, bytes calldata message, bytes32 feeRecipitent, uint256 gasLimit) internal {
function _handleAck(bytes32 destinationIdentifier, bytes memory destinationImplementationIdentifier, bytes calldata message, bytes32 feeRecipient, uint256 gasLimit) internal {
// Ensure the bounty can only be claimed once.
bytes32 messageIdentifier = bytes32(message[MESSAGE_IDENTIFIER_START:MESSAGE_IDENTIFIER_END]);

Expand Down Expand Up @@ -401,11 +404,11 @@ 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_RECIPIENT_START:CTX1_RELAYER_RECIPITENT_END]))));
address sourceFeeRecipitent = address(uint160(uint256(feeRecipitent)));
address destinationFeeRecipient = address(uint160(uint256(bytes32(message[CTX1_RELAYER_RECIPIENT_START:CTX1_RELAYER_RECIPIENT_END]))));
address sourceFeeRecipient = address(uint160(uint256(feeRecipient)));
// 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(actualFee); // If this reverts, then the relayer that is executing this tx provided a bad input.
if (destinationFeeRecipient == sourceFeeRecipient) {
payable(sourceFeeRecipient).transfer(actualFee); // If this reverts, then the relayer that is executing this tx provided a bad input.
emit MessageAcked(messageIdentifier);
emit BountyClaimed(
messageIdentifier,
Expand All @@ -420,11 +423,11 @@ abstract contract IncentivizedMessageEscrow is IIncentivizedMessageEscrow, Bytes
// If targetDelta is 0, then distribute exactly the rewards.
if (targetDelta == 0) {
// ".send" is used to ensure this doesn't revert. ".transfer" could revert and block the ack from ever being delivered.
if(!payable(destinationFeeRecipitent).send(deliveryFee)) { // If this returns false, it implies that the transfer failed.
if(!payable(destinationFeeRecipient).send(deliveryFee)) { // If this returns false, it implies that the transfer failed.
// The result is that this contract still has deliveryFee. As a result, send it somewhere else.
payable(SEND_LOST_GAS_TO).transfer(deliveryFee); // If we don't send the gas somewhere, the gas is lost forever.
}
payable(sourceFeeRecipitent).transfer(ackFee); // If this reverts, then the relayer that is executing this tx provided a bad input.
payable(sourceFeeRecipient).transfer(ackFee); // If this reverts, then the relayer that is executing this tx provided a bad input.
emit MessageAcked(messageIdentifier);
emit BountyClaimed(
messageIdentifier,
Expand Down Expand Up @@ -458,21 +461,21 @@ abstract contract IncentivizedMessageEscrow is IIncentivizedMessageEscrow, Bytes
forDestinationRelayer += ackFee * uint256(- timeBetweenTargetAndExecution) / targetDelta;
} else {
// More time than target passed and the ack relayer should get a larger chunk.
// If more time than the target passed, the ack relayer should get everything.
// If more time than double the target passed, the ack relayer should get everything
if (uint256(timeBetweenTargetAndExecution) < targetDelta) {
// targetDelta != 0, we checked for that.
// max abs timeBetweenTargetAndExecution = targetDelta since we have the above check
// => 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.
// As a result, this only encorages delivery of the ack.
// This doesn't discourage relaying, since executionTime first begins counting once the destination call has been executed.
// As a result, this only encourages delivery of the ack.
forDestinationRelayer = 0;
}
}
}
// send is used to ensure this doesn't revert. Transfer could revert and block the ack from ever being delivered.
if(!payable(destinationFeeRecipitent).send(forDestinationRelayer)) {
if(!payable(destinationFeeRecipient).send(forDestinationRelayer)) {
payable(SEND_LOST_GAS_TO).transfer(forDestinationRelayer); // If we don't send the gas somewhere, the gas is lost forever.
}
uint256 forSourceRelayer;
Expand All @@ -481,7 +484,7 @@ abstract contract IncentivizedMessageEscrow is IIncentivizedMessageEscrow, Bytes
// 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.
payable(sourceFeeRecipient).transfer(forSourceRelayer); // If this reverts, then the relayer that is executing this tx provided a bad input.

emit MessageAcked(messageIdentifier);
emit BountyClaimed(
Expand Down
4 changes: 2 additions & 2 deletions src/MessagePayload.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pragma solidity ^0.8.13;
// => MESSAGE_START 169 (remainder)
//
// CTX1 - 0x01 - Destination to Source
// + RELAYER_RECIPITENT 98 (32 bytes)
// + RELAYER_RECIPIENT 98 (32 bytes)
// + GAS_SPENT 130 (6 bytes)
// + EXECUTION_TIME 136 (8 bytes)
// => MESSAGE_START 144 (remainder)
Expand Down Expand Up @@ -58,7 +58,7 @@ uint constant CTX0_MESSAGE_START = 169;
// CTX1 Destination to Source **************************************************************************************************

uint constant CTX1_RELAYER_RECIPIENT_START = 98;
uint constant CTX1_RELAYER_RECIPITENT_END = 130;
uint constant CTX1_RELAYER_RECIPIENT_END = 130;

uint constant CTX1_GAS_SPENT_START = 130;
uint constant CTX1_GAS_SPENT_END = 136;
Expand Down
6 changes: 3 additions & 3 deletions src/TimeoutExtension.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ abstract contract IMETimeoutExtension is IncentivizedMessageEscrow {
* @notice Handles timeout messages.
* @dev Is very similar to _handleAck
*/
function _handleTimeout(bytes32 destinationIdentifier, bytes calldata message, bytes32 feeRecipitent, uint256 gasLimit) internal {
function _handleTimeout(bytes32 destinationIdentifier, bytes calldata message, bytes32 feeRecipient, uint256 gasLimit) internal {
// Ensure the bounty can only be claimed once.
bytes32 messageIdentifier = bytes32(message[MESSAGE_IDENTIFIER_START:MESSAGE_IDENTIFIER_END]);

Expand Down Expand Up @@ -70,14 +70,14 @@ abstract contract IMETimeoutExtension is IncentivizedMessageEscrow {
uint256 maxSum = maxDeliveryGas + maxAckGas;
refund = maxSum - sumFee;
}
address sourceFeeRecipitent = address(uint160(uint256(feeRecipitent)));
address sourceFeeRecipient = address(uint160(uint256(feeRecipient)));

// ".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)) { // If this returns false, it implies that the transfer failed.
// The result is that this contract still has deliveryFee. As a result, send it somewhere else.
payable(SEND_LOST_GAS_TO).transfer(refund); // If we don't send the gas somewhere, the gas is lost forever.
}
payable(sourceFeeRecipitent).transfer(ackFee + deliveryFee); // If this reverts, then the relayer that is executing this tx provided a bad input.
payable(sourceFeeRecipient).transfer(ackFee + deliveryFee); // If this reverts, then the relayer that is executing this tx provided a bad input.
emit MessageTimedout(messageIdentifier);
emit BountyClaimed(
messageIdentifier,
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 @@ -12,7 +12,7 @@ contract IncentivizedMockEscrow is IncentivizedMessageEscrow, Ownable2Step {
uint256 public costOfMessages;
uint256 public accumulator = 1;

event Message(bytes32 destinationIdentifier, bytes recipitent, bytes message);
event Message(bytes32 destinationIdentifier, bytes recipient, bytes message);

constructor(address sendLostGasTo, bytes32 uniqueChainIndex, address signer, uint256 costOfMessages_) IncentivizedMessageEscrow(sendLostGasTo) {
UNIQUE_SOURCE_IDENTIFIER = uniqueChainIndex;
Expand Down
16 changes: 8 additions & 8 deletions src/apps/mock/OnRecvIncentivizedMockEscrow.sol
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ contract OnRecvIncentivizedMockEscrow is IMETimeoutExtension {
function processPacket(
bytes calldata /* messagingProtocolContext */,
bytes calldata /* rawMessage */,
bytes32 /* feeRecipitent */
bytes32 /* feeRecipient */
) external override payable {
revert NotImplemented();
}
Expand All @@ -77,11 +77,11 @@ contract OnRecvIncentivizedMockEscrow is IMETimeoutExtension {
bytes32 chainIdentifier,
bytes calldata sourceImplementationIdentifier,
bytes calldata rawMessage,
bytes32 feeRecipitent
bytes32 feeRecipient
) onlyMessagingProtocol external {
// _onReceive(chainIdentifier, rawMessage, feeRecipitent);
// _onReceive(chainIdentifier, rawMessage, feeRecipient);
uint256 gasLimit = gasleft();
bytes memory receiveAck = _handleMessage(chainIdentifier, sourceImplementationIdentifier, rawMessage, feeRecipitent, gasLimit);
bytes memory receiveAck = _handleMessage(chainIdentifier, sourceImplementationIdentifier, rawMessage, feeRecipient, gasLimit);

// Send ack:
_sendPacket(chainIdentifier, sourceImplementationIdentifier, receiveAck);
Expand All @@ -94,24 +94,24 @@ contract OnRecvIncentivizedMockEscrow is IMETimeoutExtension {
bytes32 chainIdentifier,
bytes calldata destinationImplementationIdentifier,
bytes calldata rawMessage,
bytes32 feeRecipitent
bytes32 feeRecipient
) onlyMessagingProtocol external {
uint256 gasLimit = gasleft();
isVerifiedMessageHash[keccak256(rawMessage)] = VerifiedMessageHashContext({
chainIdentifier: chainIdentifier,
implementationIdentifier: destinationImplementationIdentifier
});
_handleAck(chainIdentifier, destinationImplementationIdentifier, rawMessage, feeRecipitent, gasLimit);
_handleAck(chainIdentifier, destinationImplementationIdentifier, rawMessage, feeRecipient, gasLimit);
}

// For timeouts, we need to construct the message.
function onTimeout(
bytes32 chainIdentifier,
bytes calldata rawMessage,
bytes32 feeRecipitent
bytes32 feeRecipient
) onlyMessagingProtocol external {
uint256 gasLimit = gasleft();
_handleTimeout(chainIdentifier, rawMessage, feeRecipitent, gasLimit);
_handleTimeout(chainIdentifier, rawMessage, feeRecipient, gasLimit);
}

// * Send to messaging_protocol
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 @@ -13,7 +13,7 @@ contract IncentivizedWormholeEscrow is IncentivizedMessageEscrow, WormholeVerifi

event WormholeMessage(
bytes32 destinationIdentifier,
bytes recipitent
bytes recipient
);

IWormhole public immutable WORMHOLE;
Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/IIncentivizedMessageEscrow.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ interface IIncentivizedMessageEscrow is IMessageEscrowStructs, IMessageEscrowErr
IncentiveDescription calldata incentive
) external payable returns(uint256 gasRefund, bytes32 messageIdentifier);

function processPacket(bytes calldata messagingProtocolContext, bytes calldata message, bytes32 feeRecipitent) payable external;
function processPacket(bytes calldata messagingProtocolContext, bytes calldata message, bytes32 feeRecipient) payable external;

function setRemoteImplementation(bytes32 chainIdentifier, bytes calldata implementation) external;

Expand Down
Loading

0 comments on commit a47f437

Please sign in to comment.