From 27cbbc78041dc1062b0e6ef7d12c60498aad5053 Mon Sep 17 00:00:00 2001 From: derpy-duck <115193320+derpy-duck@users.noreply.github.com> Date: Wed, 1 Mar 2023 23:22:44 +0000 Subject: [PATCH] forge fmt' --- .../contracts/coreRelayer/CoreRelayer.sol | 4 +- .../coreRelayer/CoreRelayerDelivery.sol | 79 ++++++++----------- .../coreRelayer/CoreRelayerMessages.sol | 8 +- ethereum/contracts/interfaces/IDelivery.sol | 37 +++++---- 4 files changed, 58 insertions(+), 70 deletions(-) diff --git a/ethereum/contracts/coreRelayer/CoreRelayer.sol b/ethereum/contracts/coreRelayer/CoreRelayer.sol index 2756281..78730ec 100644 --- a/ethereum/contracts/coreRelayer/CoreRelayer.sol +++ b/ethereum/contracts/coreRelayer/CoreRelayer.sol @@ -196,7 +196,7 @@ contract CoreRelayer is CoreRelayerDelivery { if (nonce == 0) { revert IWormholeRelayer.NonceIsZero(); } - if(sendContainer.requests.length == 0) { + if (sendContainer.requests.length == 0) { revert IWormholeRelayer.MultichainSendEmpty(); } @@ -255,7 +255,7 @@ contract CoreRelayer is CoreRelayerDelivery { if (msg.sender != lockedTargetAddress()) { revert IWormholeRelayer.ForwardRequestFromWrongAddress(); } - if(sendContainer.requests.length == 0) { + if (sendContainer.requests.length == 0) { revert IWormholeRelayer.MultichainSendEmpty(); } diff --git a/ethereum/contracts/coreRelayer/CoreRelayerDelivery.sol b/ethereum/contracts/coreRelayer/CoreRelayerDelivery.sol index 8eeb1c6..4a64566 100644 --- a/ethereum/contracts/coreRelayer/CoreRelayerDelivery.sol +++ b/ethereum/contracts/coreRelayer/CoreRelayerDelivery.sol @@ -27,14 +27,14 @@ contract CoreRelayerDelivery is CoreRelayerGovernance { /** * - Checks if enough funds were passed into a forward - * - Increases the maxTransactionFee of the first forward in the MultichainSend container + * - Increases the maxTransactionFee of the first forward in the MultichainSend container * in order to use all of the funds * - Publishes the DeliveryInstruction, with a 'sufficientlyFunded' flag indicating whether the forward had enough funds * - If the forward was funded, pay the relayer's reward address to deliver the forward - * + * * @param transactionFeeRefundAmount amount of maxTransactionFee that was unused * @param forwardInstruction A struct containing information about the user's forward/multichainForward request - * + * * @return forwardIsFunded whether or not the funds for the forward were enough */ function emitForward(uint256 transactionFeeRefundAmount, ForwardInstruction memory forwardInstruction) @@ -43,18 +43,17 @@ contract CoreRelayerDelivery is CoreRelayerGovernance { { DeliveryInstructionsContainer memory container = forwardInstruction.container; - // Add any additional funds which were passed in to the forward as msg.value + // Add any additional funds which were passed in to the forward as msg.value transactionFeeRefundAmount = transactionFeeRefundAmount + forwardInstruction.msgValue; // Checks if enough funds were passed into the forward forwardIsFunded = (transactionFeeRefundAmount >= forwardInstruction.totalFee); - IRelayProvider relayProvider = IRelayProvider(forwardInstruction.relayProvider); IWormhole wormhole = wormhole(); uint256 wormholeMessageFee = wormhole.messageFee(); - // Increases the maxTransactionFee of the first forward in the MultichainSend container + // Increases the maxTransactionFee of the first forward in the MultichainSend container // in order to use all of the funds if (forwardIsFunded) { uint256 amountUnderMaximum = relayProvider.quoteMaximumBudget(container.instructions[0].targetChain) @@ -92,16 +91,16 @@ contract CoreRelayerDelivery is CoreRelayerGovernance { * Performs the following actions: * - Calls the 'receiveWormholeMessages' endpoint on the contract 'internalInstruction.targetAddress' * (with the gas limit and value specified in internalInstruction, and 'encodedVMs' as the input) - * + * * - Calculates how much of 'maxTransactionFee' is left * - If the call succeeded and during execution of 'receiveWormholeMessages' there was a forward/multichainForward, then: * if there is enough 'maxTransactionFee' left to execute the forward, then execute the forward * else emit the forward instruction but with a flag (sufficientlyFunded = false) indicating that it wasn't paid for - * - else: + * - else: * refund any of the 'maxTransactionFee' not used to internalInstruction.refundAddress * if the call reverted, refund the 'receiverValue' to internalInstruction.refundAddress * - refund anything leftover to the relayer - * + * * @param internalInstruction instruction to execute * @param encodedVMs list of signed wormhole messages (VAAs) * @param deliveryVaaHash hash of delivery VAA @@ -117,7 +116,6 @@ contract CoreRelayerDelivery is CoreRelayerGovernance { uint16 sourceChain, uint64 sourceSequence ) internal { - // lock the contract to prevent reentrancy if (isContractLocked()) { revert IDelivery.ReentrantCall(); @@ -204,14 +202,14 @@ contract CoreRelayerDelivery is CoreRelayerGovernance { /** * @notice The relay provider calls 'redeliverSingle' to relay messages as described by one redelivery instruction - * + * * The instruction specifies, among other things, the target chain (must be this chain), refund address, new maximum refund (in this chain's currency), * new receiverValue (in this chain's currency), new upper bound on gas - * + * * The relay provider must pass in the original signed wormhole messages from the source chain of the same nonce * (the wormhole message with the original delivery instructions (the delivery VAA) must be one of these messages) * as well as the wormhole message with the new redelivery instruction (the redelivery VAA) - * + * * The messages will be relayed to the target address (with the specified gas limit and receiver value) iff the following checks are met: * - the redelivery VAA (targetParams.redeliveryVM) has a valid signature * - the redelivery VAA's emitter is one of these CoreRelayer contracts @@ -221,14 +219,13 @@ contract CoreRelayerDelivery is CoreRelayerGovernance { * - the new redelivery instruction's 'receiver value' amount >= the original instruction's 'receiver value' amount * - the redelivery instruction's target chain = this chain * - the original instruction's target chain = this chain - * - for the redelivery instruction, the relay provider passed in at least [(one wormhole message fee) + instruction.newMaximumRefundTarget + instruction.newReceiverValueTarget] of this chain's currency as msg.value + * - for the redelivery instruction, the relay provider passed in at least [(one wormhole message fee) + instruction.newMaximumRefundTarget + instruction.newReceiverValueTarget] of this chain's currency as msg.value * - msg.sender is the permissioned address allowed to execute this redelivery instruction - * - the permissioned address allowed to execute this redelivery instruction is the permissioned address allowed to execute the old instruction - * + * - the permissioned address allowed to execute this redelivery instruction is the permissioned address allowed to execute the old instruction + * * @param targetParams struct containing the signed wormhole messages and encoded redelivery instruction (and other information) */ function redeliverSingle(IDelivery.TargetRedeliveryByTxHashParamsSingle memory targetParams) public payable { - IWormhole wormhole = wormhole(); (IWormhole.VM memory redeliveryVM, bool valid, string memory reason) = @@ -246,7 +243,7 @@ contract CoreRelayerDelivery is CoreRelayerGovernance { RedeliveryByTxHashInstruction memory redeliveryInstruction = decodeRedeliveryInstruction(redeliveryVM.payload); - // Obtain the original delivery VAA + // Obtain the original delivery VAA IWormhole.VM memory originalDeliveryVM; (originalDeliveryVM, valid, reason) = wormhole.parseAndVerifyVM(targetParams.sourceEncodedVMs[redeliveryInstruction.deliveryIndex]); @@ -264,20 +261,18 @@ contract CoreRelayerDelivery is CoreRelayerGovernance { // Obtain the specific old instruction that was originally executed (and is meant to be re-executed with new parameters) // specifying the the target chain (must be this chain), target address, refund address, old maximum refund (in this chain's currency), // old receiverValue (in this chain's currency), old upper bound on gas, and the permissioned address allowed to execute this instruction - DeliveryInstruction memory originalInstruction = decodeDeliveryInstructionsContainer(originalDeliveryVM.payload).instructions[redeliveryInstruction - .multisendIndex]; - + DeliveryInstruction memory originalInstruction = decodeDeliveryInstructionsContainer(originalDeliveryVM.payload) + .instructions[redeliveryInstruction.multisendIndex]; + // Perform the following checks: // - the new redelivery instruction's upper bound on gas >= the original instruction's upper bound on gas // - the new redelivery instruction's 'receiver value' amount >= the original instruction's 'receiver value' amount // - the redelivery instruction's target chain = this chain // - the original instruction's target chain = this chain - // - for the redelivery instruction, the relay provider passed in at least [(one wormhole message fee) + instruction.newMaximumRefundTarget + instruction.newReceiverValueTarget] of this chain's currency as msg.value + // - for the redelivery instruction, the relay provider passed in at least [(one wormhole message fee) + instruction.newMaximumRefundTarget + instruction.newReceiverValueTarget] of this chain's currency as msg.value // - msg.sender is the permissioned address allowed to execute this redelivery instruction - // - the permissioned address allowed to execute this redelivery instruction is the permissioned address allowed to execute the old instruction - valid = checkRedeliveryInstructionTarget( - redeliveryInstruction, originalInstruction - ); + // - the permissioned address allowed to execute this redelivery instruction is the permissioned address allowed to execute the old instruction + valid = checkRedeliveryInstructionTarget(redeliveryInstruction, originalInstruction); // Emit an 'Invalid Redelivery' event if one of the following five checks failed: // - msg.sender is the permissioned address allowed to execute this redelivery instruction @@ -297,7 +292,7 @@ contract CoreRelayerDelivery is CoreRelayerGovernance { return; } - // Replace maximumRefund, receiverValue, and the gasLimit on the original request + // Replace maximumRefund, receiverValue, and the gasLimit on the original request originalInstruction.maximumRefundTarget = redeliveryInstruction.newMaximumRefundTarget; originalInstruction.receiverValueTarget = redeliveryInstruction.newReceiverValueTarget; originalInstruction.executionParameters = redeliveryInstruction.executionParameters; @@ -318,9 +313,9 @@ contract CoreRelayerDelivery is CoreRelayerGovernance { * - the new redelivery instruction's 'receiver value' amount >= the original instruction's 'receiver value' amount * - the redelivery instruction's target chain = this chain * - the original instruction's target chain = this chain - * - for the redelivery instruction, the relay provider passed in at least [(one wormhole message fee) + instruction.newMaximumRefundTarget + instruction.newReceiverValueTarget] of this chain's currency as msg.value + * - for the redelivery instruction, the relay provider passed in at least [(one wormhole message fee) + instruction.newMaximumRefundTarget + instruction.newReceiverValueTarget] of this chain's currency as msg.value * - msg.sender is the permissioned address allowed to execute this redelivery instruction - * - the permissioned address allowed to execute this redelivery instruction is the permissioned address allowed to execute the old instruction + * - the permissioned address allowed to execute this redelivery instruction is the permissioned address allowed to execute the old instruction * @param redeliveryInstruction redelivery instruction * @param originalInstruction old instruction */ @@ -328,17 +323,16 @@ contract CoreRelayerDelivery is CoreRelayerGovernance { RedeliveryByTxHashInstruction memory redeliveryInstruction, DeliveryInstruction memory originalInstruction ) internal view returns (bool isValid) { - address providerAddress = fromWormholeFormat(redeliveryInstruction.executionParameters.providerDeliveryAddress); - // Check that the permissioned address allowed to execute this redelivery instruction is the permissioned address allowed to execute the old instruction + // Check that the permissioned address allowed to execute this redelivery instruction is the permissioned address allowed to execute the old instruction if ((providerAddress != fromWormholeFormat(originalInstruction.executionParameters.providerDeliveryAddress))) { revert IDelivery.MismatchingRelayProvidersInRedelivery(); } uint256 wormholeMessageFee = wormhole().messageFee(); - // Check that for the redelivery instruction, the relay provider passed in at least [(one wormhole message fee) + instruction.newMaximumRefundTarget + instruction.newReceiverValueTarget] of this chain's currency as msg.value + // Check that for the redelivery instruction, the relay provider passed in at least [(one wormhole message fee) + instruction.newMaximumRefundTarget + instruction.newReceiverValueTarget] of this chain's currency as msg.value if ( msg.value < redeliveryInstruction.newMaximumRefundTarget + redeliveryInstruction.newReceiverValueTarget @@ -348,48 +342,43 @@ contract CoreRelayerDelivery is CoreRelayerGovernance { } uint16 whChainId = chainId(); - + // Check that msg.sender is the permissioned address allowed to execute this redelivery instruction isValid = msg.sender == providerAddress - // Check that the redelivery instruction's target chain = this chain && whChainId == redeliveryInstruction.targetChain - // Check that the original instruction's target chain = this chain && whChainId == originalInstruction.targetChain - // Check that the new redelivery instruction's 'receiver value' amount >= the original instruction's 'receiver value' amount && originalInstruction.receiverValueTarget <= redeliveryInstruction.newReceiverValueTarget - // Check that the new redelivery instruction's upper bound on gas >= the original instruction's upper bound on gas && originalInstruction.executionParameters.gasLimit <= redeliveryInstruction.executionParameters.gasLimit; } /** * @notice The relay provider calls 'deliverSingle' to relay messages as described by one delivery instruction - * + * * The instruction specifies the target chain (must be this chain), target address, refund address, maximum refund (in this chain's currency), * receiver value (in this chain's currency), upper bound on gas, and the permissioned address allowed to execute this instruction - * + * * The relay provider must pass in the signed wormhole messages (VAAs) from the source chain of the same nonce * (the wormhole message with the delivery instructions (the delivery VAA) must be one of these messages) - * as well as identify which of these messages is the delivery VAA and which of the many instructions in the multichainSend container is meant to be executed - * + * as well as identify which of these messages is the delivery VAA and which of the many instructions in the multichainSend container is meant to be executed + * * The messages will be relayed to the target address (with the specified gas limit and receiver value) iff the following checks are met: * - the delivery VAA has a valid signature * - the delivery VAA's emitter is one of these CoreRelayer contracts * - the delivery instruction container in the delivery VAA was fully funded * - the instruction's target chain is this chain - * - the relay provider passed in at least [(one wormhole message fee) + instruction.maximumRefundTarget + instruction.receiverValueTarget] of this chain's currency as msg.value + * - the relay provider passed in at least [(one wormhole message fee) + instruction.maximumRefundTarget + instruction.receiverValueTarget] of this chain's currency as msg.value * - msg.sender is the permissioned address allowed to execute this instruction - * + * * @param targetParams struct containing the signed wormhole messages and encoded delivery instruction container (and other information) */ function deliverSingle(IDelivery.TargetDeliveryParametersSingle memory targetParams) public payable { - IWormhole wormhole = wormhole(); - // Obtain the delivery VAA + // Obtain the delivery VAA (IWormhole.VM memory deliveryVM, bool valid, string memory reason) = wormhole.parseAndVerifyVM(targetParams.encodedVMs[targetParams.deliveryIndex]); diff --git a/ethereum/contracts/coreRelayer/CoreRelayerMessages.sol b/ethereum/contracts/coreRelayer/CoreRelayerMessages.sol index d0b90a5..7d94c52 100644 --- a/ethereum/contracts/coreRelayer/CoreRelayerMessages.sol +++ b/ethereum/contracts/coreRelayer/CoreRelayerMessages.sol @@ -131,10 +131,10 @@ contract CoreRelayerMessages is CoreRelayerStructs, CoreRelayerGetters { * @param instruction A RedeliveryByTxHashInstruction * @param relayProvider The relayProvider whos maximum budget we are checking against */ - function checkRedeliveryInstruction( - RedeliveryByTxHashInstruction memory instruction, - IRelayProvider relayProvider - ) internal view { + function checkRedeliveryInstruction(RedeliveryByTxHashInstruction memory instruction, IRelayProvider relayProvider) + internal + view + { if (instruction.executionParameters.gasLimit == 0) { revert IWormholeRelayer.MaxTransactionFeeNotEnough(0); } diff --git a/ethereum/contracts/interfaces/IDelivery.sol b/ethereum/contracts/interfaces/IDelivery.sol index ed5cbe8..1a9313e 100644 --- a/ethereum/contracts/interfaces/IDelivery.sol +++ b/ethereum/contracts/interfaces/IDelivery.sol @@ -4,11 +4,10 @@ pragma solidity ^0.8.0; interface IDelivery { - /** * @notice TargetDeliveryParametersSingle is the struct that the relay provider passes into 'deliverSingle' * containing an array of the signed wormhole messages that are to be relayed - * + * * @custom:member encodedVMs An array of signed wormhole messages (all of the same nonce, and from the same source chain transaction) * @custom:member deliveryIndex index such that encodedVMs[deliveryIndex] is the signed wormhole message from the source chain's CoreRelayer contract with payload being the encoded delivery instruction container * @custom:member multisendIndex The delivery instruction container at 'encodedVMs[deliveryIndex]' contains many delivery instructions, each specifying a different destination address @@ -21,33 +20,33 @@ interface IDelivery { uint8 multisendIndex; address payable relayerRefundAddress; } - + /** * @notice The relay provider calls 'deliverSingle' to relay messages as described by one delivery instruction - * + * * The instruction specifies the target chain (must be this chain), target address, refund address, maximum refund (in this chain's currency), * receiver value (in this chain's currency), upper bound on gas, and the permissioned address allowed to execute this instruction - * + * * The relay provider must pass in the signed wormhole messages (VAAs) from the source chain of the same nonce * (the wormhole message with the delivery instructions (the delivery VAA) must be one of these messages) - * as well as identify which of these messages is the delivery VAA and which of the many instructions in the multichainSend container is meant to be executed - * + * as well as identify which of these messages is the delivery VAA and which of the many instructions in the multichainSend container is meant to be executed + * * The messages will be relayed to the target address (with the specified gas limit and receiver value) iff the following checks are met: * - the delivery VAA has a valid signature * - the delivery VAA's emitter is one of these CoreRelayer contracts * - the delivery instruction container in the delivery VAA was fully funded * - the instruction's target chain is this chain - * - the relay provider passed in at least [(one wormhole message fee) + instruction.maximumRefundTarget + instruction.receiverValueTarget] of this chain's currency as msg.value + * - the relay provider passed in at least [(one wormhole message fee) + instruction.maximumRefundTarget + instruction.receiverValueTarget] of this chain's currency as msg.value * - msg.sender is the permissioned address allowed to execute this instruction - * + * * @param targetParams struct containing the signed wormhole messages and encoded delivery instruction container (and other information) */ function deliverSingle(TargetDeliveryParametersSingle memory targetParams) external payable; - /** + /** * @notice TargetRedeliveryByTxHashParamsSingle is the struct that the relay provider passes into 'redeliverSingle' * containing an array of the signed wormhole messages that are to be relayed - * + * * @custom:member redeliveryVM The signed wormhole message from the source chain's CoreRelayer contract with payload being the encoded redelivery instruction * @custom:member sourceEncodedVMs An array of signed wormhole messages (all of the same nonce, and from the same source chain transaction), which are the original messages that are meant to be redelivered * @custom:member relayerRefundAddress The address to which any refunds to the relay provider should be sent @@ -60,14 +59,14 @@ interface IDelivery { /** * @notice The relay provider calls 'redeliverSingle' to relay messages as described by one redelivery instruction - * + * * The instruction specifies, among other things, the target chain (must be this chain), refund address, new maximum refund (in this chain's currency), * new receiverValue (in this chain's currency), new upper bound on gas - * + * * The relay provider must pass in the original signed wormhole messages from the source chain of the same nonce * (the wormhole message with the original delivery instructions (the delivery VAA) must be one of these messages) * as well as the wormhole message with the new redelivery instruction (the redelivery VAA) - * + * * The messages will be relayed to the target address (with the specified gas limit and receiver value) iff the following checks are met: * - the redelivery VAA (targetParams.redeliveryVM) has a valid signature * - the redelivery VAA's emitter is one of these CoreRelayer contracts @@ -76,23 +75,23 @@ interface IDelivery { * - the new redelivery instruction's upper bound on gas >= the original instruction's upper bound on gas * - the new redelivery instruction's 'receiver value' amount >= the original instruction's 'receiver value' amount * - the redelivery instruction's target chain = the original instruction's target chain = this chain - * - for the redelivery instruction, the relay provider passed in at least [(one wormhole message fee) + instruction.newMaximumRefundTarget + instruction.newReceiverValueTarget] of this chain's currency as msg.value + * - for the redelivery instruction, the relay provider passed in at least [(one wormhole message fee) + instruction.newMaximumRefundTarget + instruction.newReceiverValueTarget] of this chain's currency as msg.value * - msg.sender is the permissioned address allowed to execute this redelivery instruction - * - msg.sender is the permissioned address allowed to execute the old instruction - * + * - msg.sender is the permissioned address allowed to execute the old instruction + * * @param targetParams struct containing the signed wormhole messages and encoded redelivery instruction (and other information) */ function redeliverSingle(TargetRedeliveryByTxHashParamsSingle memory targetParams) external payable; error InvalidEmitterInRedeliveryVM(); // The redelivery VAA (signed wormhole message with redelivery instructions) has an invalid sender error InvalidEmitterInOriginalDeliveryVM(uint8 index); // The original delivery VAA (original signed wormhole message with delivery instructions) has an invalid sender - error InvalidRedeliveryVM(string reason); // The redelivery VAA is not valid + error InvalidRedeliveryVM(string reason); // The redelivery VAA is not valid error InvalidVaa(uint8 index, string reason); // The VAA is not valid error MismatchingRelayProvidersInRedelivery(); // The relay provider specified for the redelivery is different from the relay provider specified for the original delivery error UnexpectedRelayer(); // msg.sender must be the delivery address of the specified relay provider error InvalidEmitter(); // The delivery VAA (signed wormhole message with delivery instructions) has an invalid sender error SendNotSufficientlyFunded(); // The container of delivery instructions (for which this current delivery was in) was not fully funded on the source chain error InsufficientRelayerFunds(); // The relay provider didn't pass in sufficient funds (msg.value does not cover the necessary budget fees) - error TargetChainIsNotThisChain(uint16 targetChainId); // The specified target chain is not the current chain + error TargetChainIsNotThisChain(uint16 targetChainId); // The specified target chain is not the current chain error ReentrantCall(); // A delivery cannot occur during another delivery }