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

Commit

Permalink
Renames functions and contracts in reentrancy negative test.
Browse files Browse the repository at this point in the history
  • Loading branch information
scnale committed Feb 14, 2023
1 parent 41936a7 commit 6b0e267
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
20 changes: 10 additions & 10 deletions ethereum/contracts/mock/AttackForwardIntegration.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import "@openzeppelin/contracts/token/ERC20/ERC20.sol";

import "../interfaces/IWormhole.sol";
import "../interfaces/IWormholeReceiver.sol";
import "../interfaces/ICoreRelayer.sol";
import "../interfaces/IWormholeRelayer.sol";

/**
* This contract is a malicious "integration" that attempts to attack the forward mechanism.
Expand All @@ -14,15 +14,15 @@ contract AttackForwardIntegration is IWormholeReceiver {
mapping(bytes32 => bool) consumedMessages;
address attackerReward;
IWormhole wormhole;
ICoreRelayer core_relayer;
IWormholeRelayer core_relayer;
uint32 nonce = 1;
uint16 targetChainId;

// Capture 30k gas for fees
// This just needs to be enough to pay for the call to the destination address.
uint32 SAFE_DELIVERY_GAS_CAPTURE = 30000;

constructor(IWormhole initWormhole, ICoreRelayer initCoreRelayer, uint16 chainId, address initAttackerReward) {
constructor(IWormhole initWormhole, IWormholeRelayer initCoreRelayer, uint16 chainId, address initAttackerReward) {
attackerReward = initAttackerReward;
wormhole = initWormhole;
core_relayer = initCoreRelayer;
Expand All @@ -39,25 +39,25 @@ contract AttackForwardIntegration is IWormholeReceiver {
// The core relayer could in principle accept the request due to this being the target of the message at the same time as being the refund address.
// Note that, if succesful, this forward request would be processed after the time for processing forwards is past.
// Thus, the request would "linger" in the forward request cache and be attended to in the next delivery.
requestForward(targetChainId, toWormholeFormat(attackerReward));
forward(targetChainId, toWormholeFormat(attackerReward));
}

function requestForward(uint16 targetChain, bytes32 attackerRewardAddress) internal {
uint256 computeBudget = core_relayer.quoteGasDeliveryFee(
function forward(uint16 targetChain, bytes32 attackerRewardAddress) internal {
uint256 maxTransactionFee = core_relayer.quoteGas(
targetChain, SAFE_DELIVERY_GAS_CAPTURE, core_relayer.getDefaultRelayProvider()
);

ICoreRelayer.DeliveryRequest memory request = ICoreRelayer.DeliveryRequest({
IWormholeRelayer.Send memory request = IWormholeRelayer.Send({
targetChain: targetChain,
targetAddress: attackerRewardAddress,
// All remaining funds will be returned to the attacker
refundAddress: attackerRewardAddress,
computeBudget: computeBudget,
applicationBudget: 0,
maxTransactionFee: maxTransactionFee,
receiverValue: 0,
relayParameters: core_relayer.getDefaultRelayParams()
});

core_relayer.requestForward{value: computeBudget}(request, nonce, core_relayer.getDefaultRelayProvider());
core_relayer.forward{value: maxTransactionFee}(request, nonce, core_relayer.getDefaultRelayProvider());
}

function toWormholeFormat(address addr) public pure returns (bytes32 whFormat) {
Expand Down
10 changes: 5 additions & 5 deletions ethereum/forge-test/CoreRelayer.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -527,18 +527,18 @@ contract TestCoreRelayer is Test {
);

vm.assume(
setup.source.coreRelayer.quoteGasDeliveryFee(
setup.targetChainId, gasParams.targetGasLimit, setup.source.relayProvider
setup.source.coreRelayer.quoteGas(
setup.targetChainId, gasParams.targetGasLimit, address(setup.source.relayProvider)
) < uint256(2) ** 222
);
vm.assume(
setup.target.coreRelayer.quoteGasDeliveryFee(setup.sourceChainId, 500000, setup.target.relayProvider)
setup.target.coreRelayer.quoteGas(setup.sourceChainId, 500000, address(setup.target.relayProvider))
< uint256(2) ** 222 / feeParams.targetNativePrice
);

// Estimate the cost based on the initialized values
uint256 computeBudget = setup.source.coreRelayer.quoteGasDeliveryFee(
setup.targetChainId, gasParams.targetGasLimit, setup.source.relayProvider
uint256 computeBudget = setup.source.coreRelayer.quoteGas(
setup.targetChainId, gasParams.targetGasLimit, address(setup.source.relayProvider)
);

{
Expand Down

0 comments on commit 6b0e267

Please sign in to comment.