Skip to content
This repository was archived by the owner on May 23, 2023. It is now read-only.

Commit db355a2

Browse files
authored
Revert if delivery address is 0, and add forge tests testing this (#115)
* Revert if delivery address is 0, and add forge tests testing this * Test passes
1 parent 11874c5 commit db355a2

File tree

3 files changed

+38
-4
lines changed

3 files changed

+38
-4
lines changed

ethereum/contracts/coreRelayer/CoreRelayer.sol

+3-3
Original file line numberDiff line numberDiff line change
@@ -265,19 +265,19 @@ contract CoreRelayer is CoreRelayerDelivery {
265265
// For each 'Send' request,
266266
// calculate how much gas the relay provider can pay for on 'request.targetChain' using 'request.newTransactionFee',
267267
// and calculate how much value the relay provider will pass into 'request.targetAddress'
268-
DeliveryInstructionsContainer memory container =
268+
DeliveryInstructionsContainer memory instructionsContainer =
269269
convertMultichainSendToDeliveryInstructionsContainer(sendContainer);
270270

271271
// For each 'Send' request,
272272
// Check that the total amount of value the relay provider needs to use for this send is <= the relayProvider's maximum budget for 'targetChain'
273273
// and check that the calculated gas is greater than 0
274-
checkInstructions(container, IRelayProvider(sendContainer.relayProviderAddress));
274+
checkInstructions(instructionsContainer, IRelayProvider(sendContainer.relayProviderAddress));
275275

276276
// Save information about the forward in state, so it can be processed after the execution of 'receiveWormholeMessages',
277277
// because we will then know how much of the 'maxTransactionFee' of the current delivery is still available for use in this forward
278278
setForwardInstruction(
279279
ForwardInstruction({
280-
container: container,
280+
container: instructionsContainer,
281281
nonce: nonce,
282282
msgValue: msg.value,
283283
totalFee: totalFee,

ethereum/contracts/coreRelayer/CoreRelayerMessages.sol

+5-1
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,18 @@ contract CoreRelayerMessages is CoreRelayerStructs, CoreRelayerGetters {
8585
instruction.targetChain = send.targetChain;
8686
instruction.targetAddress = send.targetAddress;
8787
instruction.refundAddress = send.refundAddress;
88+
bytes32 deliveryAddress = relayProvider.getDeliveryAddress(send.targetChain);
89+
if (deliveryAddress == bytes32(0x0)) {
90+
revert IWormholeRelayer.RelayProviderDoesNotSupportTargetChain();
91+
}
8892
instruction.maximumRefundTarget =
8993
calculateTargetDeliveryMaximumRefund(send.targetChain, send.maxTransactionFee, relayProvider);
9094
instruction.receiverValueTarget =
9195
convertReceiverValueAmount(send.receiverValue, send.targetChain, relayProvider);
9296
instruction.executionParameters = ExecutionParameters({
9397
version: 1,
9498
gasLimit: calculateTargetGasDeliveryAmount(send.targetChain, send.maxTransactionFee, relayProvider),
95-
providerDeliveryAddress: relayProvider.getDeliveryAddress(send.targetChain)
99+
providerDeliveryAddress: deliveryAddress
96100
});
97101
}
98102

ethereum/forge-test/CoreRelayer.t.sol

+30
Original file line numberDiff line numberDiff line change
@@ -1314,6 +1314,36 @@ contract TestCoreRelayer is Test {
13141314
);
13151315
}
13161316

1317+
function testRevertTargetNotSupported(
1318+
GasParameters memory gasParams,
1319+
FeeParameters memory feeParams,
1320+
bytes memory message
1321+
) public {
1322+
StandardSetupTwoChains memory setup = standardAssumeAndSetupTwoChains(gasParams, feeParams, 1000000);
1323+
1324+
vm.recordLogs();
1325+
1326+
// estimate the cost based on the intialized values
1327+
uint256 maxTransactionFee = setup.source.coreRelayer.quoteGas(
1328+
setup.targetChainId, gasParams.targetGasLimit, address(setup.source.relayProvider)
1329+
);
1330+
1331+
uint256 wormholeFee = setup.source.wormhole.messageFee();
1332+
1333+
vm.expectRevert(abi.encodeWithSignature("RelayProviderDoesNotSupportTargetChain()"));
1334+
setup.source.integration.sendMessageWithRefundAddress{value: maxTransactionFee + uint256(3) * wormholeFee}(
1335+
message, 32, address(setup.target.integration), address(setup.target.refundAddress)
1336+
);
1337+
1338+
setup.source.relayProvider.updateDeliveryAddress(
1339+
setup.targetChainId, setup.source.relayProvider.getDeliveryAddress(32)
1340+
);
1341+
vm.expectRevert(abi.encodeWithSignature("RelayProviderDoesNotSupportTargetChain()"));
1342+
setup.source.integration.sendMessageWithRefundAddress{value: maxTransactionFee + uint256(3) * wormholeFee}(
1343+
message, setup.targetChainId, address(setup.target.integration), address(setup.target.refundAddress)
1344+
);
1345+
}
1346+
13171347
/**
13181348
*
13191349
*

0 commit comments

Comments
 (0)