Skip to content

Commit

Permalink
feat: further types
Browse files Browse the repository at this point in the history
  • Loading branch information
reednaa committed Jun 21, 2024
1 parent 15bdf09 commit db0c96e
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 38 deletions.
38 changes: 19 additions & 19 deletions src/IncentivizedMessageEscrow.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ import "./MessagePayload.sol";
* and verify messages. There are 4 functions that an integration has to implement.
* Any implementation of this contract, allows applications to deliver a message to ::submitMessage
* along with the respective incentives.
* The integration (this contract) will handle transfering the message to the destination and
* The integration (this contract) will handle transferring the message to the destination and
* returning an ack from the destination to the integrating application.
*
* The incentive is released when an ack from the destination chain is delivered to this contract.
*
* Beyond making relayer incentives stronger, this contract also implements several quality of life features:
* - Refund unused gas.
* - Seperate gas payments for call and ack.
* - Separate gas payments for call and ack.
* - Simple implementation of new messaging protocols.
*
* Applications integration with Generalised Incentives have to be aware that Acks are replayable.
Expand Down Expand Up @@ -94,7 +94,7 @@ abstract contract IncentivizedMessageEscrow is IIncentivizedMessageEscrow, Bytes
* @notice Verifies the authenticity of a message.
* @dev Should be overwritten by the specific messaging protocol verification structure.
* onRecv. implementations should collect acks so _verifyPacket returns true after acks have been executed once.
* @param messagingProtocolContext Some context that is useful for verifing the message.
* @param messagingProtocolContext Some context that is useful for verifying the message.
* It should not contain the message but instead verification context like signatures, header, etc.
* Context may not be needed for verifying the message and can be prepended to rawMessage.
* @param rawMessage Some kind of package, initially untrusted. Should contain the message as a slice
Expand Down Expand Up @@ -123,7 +123,7 @@ abstract contract IncentivizedMessageEscrow is IIncentivizedMessageEscrow, Bytes
* @param destinationIdentifier The destination chain for the message.
* @param destinationImplementation The destination escrow contract.
* @param message The message. Contains relevant escrow context.
* @param deadline A timestamp that the message should be delivered before. If the AMB does not nativly
* @param deadline A timestamp that the message should be delivered before. If the AMB does not natively
* support a timeout on their messages this parameter should be ignored. If 0 is provided, parse it as MAX.
* @return costOfsendPacketInNativeToken An additional cost to emitting messages in NATIVE tokens.
*/
Expand Down Expand Up @@ -334,8 +334,8 @@ abstract contract IncentivizedMessageEscrow is IIncentivizedMessageEscrow, Bytes
* @param destinationIdentifier 32 bytes that identifies the destination chain.
* @param destinationAddress The destination application encoded in 65 bytes: First byte is the length and last 64 is the destination application.
* @param message The message to be sent to the destination. Please ensure the message is block-unique.
* This means that you don't send the same message twice in a single block. If you need to do that, add a nonce or noice.
* @param incentive The incentive to attatch to the bounty. The price of this incentive has to be paid,
* This means that you don't send the same message twice in a single block. If you need to do that, add a nonce or noise.
* @param incentive The incentive to attach to the bounty. The price of this incentive has to be paid,
* any excess is refunded to refundGasTo. (not msg.sender)
* @param deadline After this date, do not allow relayers to execute the message on the destination chain. If set to 0, disable timeouts.
* Not all AMBs may support disabling the deadline. If acks are required it is recommended to set the deadline sometime in the future.
Expand Down Expand Up @@ -477,7 +477,7 @@ abstract contract IncentivizedMessageEscrow is IIncentivizedMessageEscrow, Bytes
revert NotImplementedError();
}

// Check if there is a mis-match between the cost and the value of the message.
// Check if there is a mismatch between the cost and the value of the message.
if (uint128(msg.value) != cost) {
if (uint128(msg.value) > cost) {
// Send the unused gas back to the the user.
Expand Down Expand Up @@ -670,7 +670,7 @@ abstract contract IncentivizedMessageEscrow is IIncentivizedMessageEscrow, Bytes
// First check if the application trusts the implementation on the destination chain.
bytes32 expectedDestinationImplementationHash = implementationAddressHash[fromApplication][destinationIdentifier];
// Check that the application approves the source implementation
// For acks, this should always be the case except when a fradulent applications sends a message to this contract.
// For acks, this should always be the case except when a fraudulent applications sends a message to this contract.
if (expectedDestinationImplementationHash != keccak256(destinationImplementationIdentifier)) revert InvalidImplementationAddress();

// Deliver the ack to the application.
Expand Down Expand Up @@ -825,7 +825,7 @@ abstract contract IncentivizedMessageEscrow is IIncentivizedMessageEscrow, Bytes
}

/**
* @notice Verifies the input parameters are contained messageIdentfier and that the other arguments are valid.
* @notice Verifies the input parameters are contained messageIdentifier and that the other arguments are valid.
* The usage of this function is intended when no parameters of a message can be trusted and we have to verify them.
* This is the case when we receive a timeout, as the timeout had to be emitted without any verification
* on the remote chain, for us to then verify since we know when a message identifier is good AND how to compute it.
Expand All @@ -851,7 +851,7 @@ abstract contract IncentivizedMessageEscrow is IIncentivizedMessageEscrow, Bytes
fromApplication = address(uint160(bytes20(message[FROM_APPLICATION_START_EVM:FROM_APPLICATION_END])));
bytes32 expectedDestinationImplementationHash = implementationAddressHash[fromApplication][destinationIdentifier];
// Check that the application approves of the remote implementation.
// For timeouts, this could fail because of fradulent sender or bad data.
// For timeouts, this could fail because of fraudulent sender or bad data.
if (expectedDestinationImplementationHash != keccak256(implementationIdentifier)) revert InvalidImplementationAddress();

// Do we need to check deadline again?
Expand Down Expand Up @@ -926,7 +926,7 @@ abstract contract IncentivizedMessageEscrow is IIncentivizedMessageEscrow, Bytes
ackFee = gasSpentOnSource * priceOfAckGas;
// deliveryFee + ackFee < 2**144 + 2**144 = 2**145
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
// (priceOfDeliveryGas * maxGasDelivery + priceOfDeliveryGas * maxGasAck) has been calculated before (escrowBounty) < (2**48 * 2**96) + (2**48 * 2**96) = 2**144 + 2**144 = 2**145
uint256 maxDeliveryFee = maxGasDelivery * priceOfDeliveryGas;
uint256 maxAckFee = maxGasAck * priceOfAckGas;
uint256 maxFee = maxDeliveryFee + maxAckFee;
Expand Down Expand Up @@ -1018,7 +1018,7 @@ abstract contract IncentivizedMessageEscrow is IIncentivizedMessageEscrow, Bytes

/**
* @notice Sets a bounty for a message
* @dev Does not check if enough incentives have been provided, this is delegated as responsiblity
* @dev Does not check if enough incentives have been provided, this is delegated as responsibility
* of the caller of this function.
* @param fromApplication The application that called the contract. Should generally be msg.sender. Is used to separate storage between applications.
* @param destinationIdentifier The destination chain. Combined with fromApplication, this specifics a unique remote escrow implementation.
Expand All @@ -1044,7 +1044,7 @@ abstract contract IncentivizedMessageEscrow is IIncentivizedMessageEscrow, Bytes

/**
* @notice Allows anyone to re-execute an ack which didn't properly execute.
* @dev No applciation should rely on this function. It should only be used incase an application has faulty logic.
* @dev No application should rely on this function. It should only be used incase an application has faulty logic.
* Example: Faulty logic results in wrong enforcement on gas limit => out of gas?
*
* This function allows replaying acks.
Expand Down Expand Up @@ -1094,21 +1094,21 @@ abstract contract IncentivizedMessageEscrow is IIncentivizedMessageEscrow, Bytes
bytes calldata implementationIdentifier,
bytes calldata receiveAckWithContext
) external payable virtual {
// Has the package previously been executed? (otherwise timeout might be more appropiate)
// Has the package previously been executed? (otherwise timeout might be more appropriate)

// Load the messageIdentifier from receiveAckWithContext.
// This makes it slighly easier to retry messages.
// This makes it slightly easier to retry messages.
bytes32 messageIdentifier = bytes32(receiveAckWithContext[MESSAGE_IDENTIFIER_START:MESSAGE_IDENTIFIER_END]);

bytes32 storedAckHash = _messageDelivered[sourceIdentifier][implementationIdentifier][messageIdentifier];
// First, check if there is actually an appropiate hash at the message identifier.
// First, check if there is actually an appropriate hash at the message identifier.
// Then, check if the storedAckHash & the source target (sourceIdentifier & implementationIdentifier) matches the executed one.
if (storedAckHash == bytes32(0) || storedAckHash != keccak256(receiveAckWithContext)) revert CannotRetryWrongMessage(storedAckHash, keccak256(receiveAckWithContext));

// Send the package again.
uint128 cost = _sendPacket(sourceIdentifier, implementationIdentifier, receiveAckWithContext, 0);

// Check if there is a mis-match between the cost and the value of the message.
// Check if there is a mismatch between the cost and the value of the message.
if (uint128(msg.value) != cost) {
if (uint128(msg.value) > cost) {
// Send the unused gas back to the the user.
Expand Down Expand Up @@ -1166,7 +1166,7 @@ abstract contract IncentivizedMessageEscrow is IIncentivizedMessageEscrow, Bytes
// When the message arrives, the usual incentive check ensures only 1 message can arrive. Since the incentive check is based on
// messageIdentifier, we need to verify it.
// Remember, the messageIdentifier is actually untrusted. So it is trivial to pass the above check. However, any way to pass
// the above check fradulently would result in messageIdentifier being wrong and unable to be reproduced on the source chain.
// the above check fraudulently would result in messageIdentifier being wrong and unable to be reproduced on the source chain.

// Load the deadline from the message.
uint64 deadline = uint64(bytes8(message[CTX0_DEADLINE_START:CTX0_DEADLINE_END]));
Expand Down Expand Up @@ -1197,7 +1197,7 @@ abstract contract IncentivizedMessageEscrow is IIncentivizedMessageEscrow, Bytes
0
);

// Check if there is a mis-match between the cost and the value of the message.
// Check if there is a mismatch between the cost and the value of the message.
if (uint128(msg.value) != cost) {
if (uint128(msg.value) > cost) {
// Send the unused gas back to the the user.
Expand Down
6 changes: 3 additions & 3 deletions src/apps/mock/OnRecvIncentivizedMockEscrow.sol
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@ contract OnRecvIncentivizedMockEscrow is IncentivizedMessageEscrow {
bytes32 feeRecipient
) onlyMessagingProtocol external {
uint256 gasLimit = gasleft();
VerifiedMessageHashContext storage _verfiedMessageHashContext = isVerifiedMessageHash[keccak256(rawMessage)];
_verfiedMessageHashContext.chainIdentifier = chainIdentifier;
_verfiedMessageHashContext.implementationIdentifier = destinationImplementationIdentifier;
VerifiedMessageHashContext storage _verifiedMessageHashContext = isVerifiedMessageHash[keccak256(rawMessage)];
_verifiedMessageHashContext.chainIdentifier = chainIdentifier;
_verifiedMessageHashContext.implementationIdentifier = destinationImplementationIdentifier;

_handleAck(chainIdentifier, destinationImplementationIdentifier, rawMessage, feeRecipient, gasLimit);
}
Expand Down
4 changes: 2 additions & 2 deletions src/apps/polymer/vIBCEscrow.sol
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ contract IncentivizedPolymerEscrow is APolymerEscrow, IbcReceiverBase, IbcReceiv
}

function onCloseIbcChannel(bytes32 channelId, string calldata, bytes32) external virtual onlyIbcDispatcher {
// logic to determin if the channel should be closed
// logic to determine if the channel should be closed
bool channelFound = false;
for (uint256 i = 0; i < connectedChannels.length; i++) {
if (connectedChannels[i] == channelId) {
Expand Down Expand Up @@ -158,7 +158,7 @@ contract IncentivizedPolymerEscrow is APolymerEscrow, IbcReceiverBase, IbcReceiv
// Get the payload by removing the implementation identifier.
bytes calldata rawMessage = ack.data[POLYMER_PACKAGE_PAYLOAD_START:];

// Set a verificaiton context so we can recover the ack.
// Set a verification context so we can recover the ack.
isVerifiedMessageHash[keccak256(rawMessage)] = VerifiedMessageHashContext({
chainIdentifier: packet.src.channelId,
implementationIdentifier: destinationImplementationIdentifier
Expand Down
4 changes: 2 additions & 2 deletions src/apps/wormhole/IncentivizedWormholeEscrow.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { IWormhole } from "./interfaces/IWormhole.sol";
/**
* @title Incentivized Wormhole Message Escrow
* @notice Incentivizes Wormhole messages through Generalised Incentives.
* Wormhole does not have any native way of relaying messages, this implemention adds one.
* Wormhole does not have any native way of relaying messages, this implementation adds one.
*
* When using Wormhole with Generalised Incentives and you don't want to lose message, be very careful regarding
* emitting messages to destinationChainIdentifiers that does not exist. Wormhole has no way to verify if a
Expand Down Expand Up @@ -50,7 +50,7 @@ contract IncentivizedWormholeEscrow is IncentivizedMessageEscrow, WormholeVerifi
amount = WORMHOLE.messageFee();
}

/** @notice Wormhole proofs are valid until the guardian set is changed. The new guradian set may sign a new VAA */
/** @notice Wormhole proofs are valid until the guardian set is changed. The new guardian set may sign a new VAA */
function _proofValidPeriod(bytes32 /* destinationIdentifier */) override internal pure returns(uint64) {
return 0;
}
Expand Down
6 changes: 3 additions & 3 deletions src/apps/wormhole/external/callworm/WormholeVerifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ contract WormholeVerifier is GettersGetter {

constructor(address wormholeState) payable GettersGetter(wormholeState) {}

/// @dev parseAndVerifyVM serves to parse an encodedVM and wholy validate it for consumption
/// @dev parseAndVerifyVM serves to parse an encodedVM and wholly validate it for consumption
function parseAndVerifyVM(bytes calldata encodedVM) public view returns (
SmallStructs.SmallVM memory vm,
bytes calldata payload,
Expand Down Expand Up @@ -91,7 +91,7 @@ contract WormholeVerifier is GettersGetter {


/**
* @dev verifySignatures serves to validate arbitrary sigatures against an arbitrary guardianSet
* @dev verifySignatures serves to validate arbitrary signatures against an arbitrary guardianSet
* - it intentionally does not solve for expectations within guardianSet (you should use verifyVM if you need these protections)
* - it intentioanlly does not solve for quorum (you should use verifyVM if you need these protections)
* - it intentionally returns true when signatures is an empty set (you should use verifyVM if you need these protections)
Expand Down Expand Up @@ -215,7 +215,7 @@ contract WormholeVerifier is GettersGetter {
}

/**
* @dev quorum serves solely to determine the number of signatures required to acheive quorum
* @dev quorum serves solely to determine the number of signatures required to achieve quorum
*/
function quorum(uint numGuardians) public pure virtual returns (uint numSignaturesRequiredForQuorum) {
unchecked {
Expand Down
6 changes: 3 additions & 3 deletions src/apps/wormhole/external/wormhole/Messages.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import "./libraries/external/BytesLib.sol";
contract Messages is Getters {
using BytesLib for bytes;

/// @dev parseAndVerifyVM serves to parse an encodedVM and wholy validate it for consumption
/// @dev parseAndVerifyVM serves to parse an encodedVM and wholly validate it for consumption
function parseAndVerifyVM(bytes calldata encodedVM) public view returns (Structs.VM memory vm, bool valid, string memory reason) {
vm = parseVM(encodedVM);
/// setting checkHash to false as we can trust the hash field in this case given that parseVM computes and then sets the hash field above
Expand Down Expand Up @@ -103,7 +103,7 @@ contract Messages is Getters {


/**
* @dev verifySignatures serves to validate arbitrary sigatures against an arbitrary guardianSet
* @dev verifySignatures serves to validate arbitrary signatures against an arbitrary guardianSet
* - it intentionally does not solve for expectations within guardianSet (you should use verifyVM if you need these protections)
* - it intentioanlly does not solve for quorum (you should use verifyVM if you need these protections)
* - it intentionally returns true when signatures is an empty set (you should use verifyVM if you need these protections)
Expand Down Expand Up @@ -208,7 +208,7 @@ contract Messages is Getters {
}

/**
* @dev quorum serves solely to determine the number of signatures required to acheive quorum
* @dev quorum serves solely to determine the number of signatures required to achieve quorum
*/
function quorum(uint numGuardians) public pure virtual returns (uint numSignaturesRequiredForQuorum) {
// The max number of guardians is 255
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -421,14 +421,14 @@ library BytesLib {
} {
// if any of these checks fails then arrays are not equal
if iszero(eq(mload(mc), mload(cc))) {
// unsuccess:
// unsuccessful:
success := 0
cb := 0
}
}
}
default {
// unsuccess:
// unsuccessful:
success := 0
}
}
Expand Down Expand Up @@ -466,7 +466,7 @@ library BytesLib {
fslot := mul(div(fslot, 0x100), 0x100)

if iszero(eq(fslot, mload(add(_postBytes, 0x20)))) {
// unsuccess:
// unsuccessful:
success := 0
}
}
Expand All @@ -491,7 +491,7 @@ library BytesLib {
mc := add(mc, 0x20)
} {
if iszero(eq(sload(sc), mload(mc))) {
// unsuccess:
// unsuccessful:
success := 0
cb := 0
}
Expand All @@ -500,7 +500,7 @@ library BytesLib {
}
}
default {
// unsuccess:
// unsuccessful:
success := 0
}
}
Expand Down
Loading

0 comments on commit db0c96e

Please sign in to comment.