Skip to content
This repository was archived by the owner on Jun 16, 2025. It is now read-only.

Commit 3879b3c

Browse files
authored
evm: use messageFee > 0 (#217)
1 parent d0228f0 commit 3879b3c

File tree

7 files changed

+56
-10
lines changed

7 files changed

+56
-10
lines changed

evm/env/testing.env

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export AVALANCHE_RPC=https://api.avax.network/ext/bc/C/rpc
2-
export ETHEREUM_RPC=https://rpc.ankr.com/eth
2+
export ETHEREUM_RPC=https://eth.llamarpc.com
33

44

55
export AVAX_USDC_ADDRESS=0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E

evm/forge/tests/MatchingEngine.t.sol

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ contract MatchingEngineTest is Test {
5555
uint32 constant ARB_DOMAIN = 3;
5656
uint32 constant ETH_DOMAIN = 0;
5757
uint32 constant AVAX_DOMAIN = 1;
58+
uint256 constant WORMHOLE_MESSAGE_FEE = 1;
59+
uint256 constant WORMHOLE_MESSAGE_FEE_STORAGE_SLOT = 7;
5860

5961
// Environment variables.
6062
uint256 immutable TESTING_SIGNER = uint256(vm.envBytes32("TESTING_DEVNET_GUARDIAN"));
@@ -128,6 +130,8 @@ contract MatchingEngineTest is Test {
128130
}
129131

130132
function setUp() public {
133+
// Set core bridge messageFee > 0
134+
vm.store(address(wormhole), bytes32(uint256(WORMHOLE_MESSAGE_FEE_STORAGE_SLOT)), bytes32(uint256(WORMHOLE_MESSAGE_FEE)));
131135
vm.startPrank(makeAddr("owner"));
132136
engine = deployProxy(USDC_ADDRESS, address(wormhole), CIRCLE_BRIDGE.fromUniversalAddress());
133137

@@ -1794,9 +1798,10 @@ contract MatchingEngineTest is Test {
17941798
// Record logs for placeMarketOrder.
17951799
vm.recordLogs();
17961800

1801+
vm.deal(caller, WORMHOLE_MESSAGE_FEE);
17971802
// Place the order.
17981803
vm.prank(caller);
1799-
engine.executeFastOrder(fastMessage);
1804+
engine.executeFastOrder{value: WORMHOLE_MESSAGE_FEE}(fastMessage);
18001805

18011806
// Fetch the logs for Wormhole message. There should be two messages.
18021807
Vm.Log[] memory logs = vm.getRecordedLogs();
@@ -1816,9 +1821,10 @@ contract MatchingEngineTest is Test {
18161821
// Record logs for placeMarketOrder.
18171822
vm.recordLogs();
18181823

1824+
vm.deal(caller, WORMHOLE_MESSAGE_FEE);
18191825
// Place the order.
18201826
vm.prank(caller);
1821-
engine.executeFastOrder(fastMessage);
1827+
engine.executeFastOrder{value: WORMHOLE_MESSAGE_FEE}(fastMessage);
18221828

18231829
// Fetch the logs for Wormhole message. There should be two messages.
18241830
Vm.Log[] memory logs = vm.getRecordedLogs();
@@ -1837,8 +1843,10 @@ contract MatchingEngineTest is Test {
18371843
// Record logs for placeMarketOrder.
18381844
vm.recordLogs();
18391845

1846+
vm.deal(caller, WORMHOLE_MESSAGE_FEE);
1847+
18401848
vm.prank(caller);
1841-
engine.executeSlowOrderAndRedeem(fastTransferVaa, params);
1849+
engine.executeSlowOrderAndRedeem{value: WORMHOLE_MESSAGE_FEE}(fastTransferVaa, params);
18421850

18431851
// Fetch the logs for Wormhole message. There should be two messages.
18441852
Vm.Log[] memory logs = vm.getRecordedLogs();

evm/forge/tests/TokenRouter.t.sol

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ contract TokenRouterTest is Test, ITokenRouterEvents {
7676
ITokenRouter router;
7777
SigningWormholeSimulator wormholeSimulator;
7878
CircleSimulator circleSimulator;
79+
80+
// Core bridge.
81+
uint256 immutable WORMHOLE_MESSAGE_FEE_STORAGE_SLOT = 7;
82+
uint256 immutable WORMHOLE_MESSAGE_FEE = 1;
7983

8084
function deployProxy(address _token, address _wormhole, address _tokenMessenger)
8185
internal
@@ -128,6 +132,9 @@ contract TokenRouterTest is Test, ITokenRouterEvents {
128132

129133
circleSimulator = new CircleSimulator(TESTING_SIGNER, MESSAGE_TRANSMITTER);
130134
circleSimulator.setupCircleAttester();
135+
136+
// Set core bridge messageFee > 0
137+
vm.store(address(wormhole), bytes32(uint256(WORMHOLE_MESSAGE_FEE_STORAGE_SLOT)), bytes32(uint256(WORMHOLE_MESSAGE_FEE)));
131138
}
132139

133140
/**
@@ -1607,7 +1614,9 @@ contract TokenRouterTest is Test, ITokenRouterEvents {
16071614
vm.recordLogs();
16081615

16091616
// Place the order.
1610-
_router.placeMarketOrder(
1617+
_router.placeMarketOrder{
1618+
value: WORMHOLE_MESSAGE_FEE
1619+
}(
16111620
amountIn, minAmountOut, targetChain, redeemer, redeemerMessage, refundAddress
16121621
);
16131622

@@ -1637,7 +1646,7 @@ contract TokenRouterTest is Test, ITokenRouterEvents {
16371646
vm.recordLogs();
16381647

16391648
// Place the order.
1640-
_router.placeMarketOrder(amountIn, targetChain, redeemer, redeemerMessage);
1649+
_router.placeMarketOrder{value: WORMHOLE_MESSAGE_FEE}(amountIn, targetChain, redeemer, redeemerMessage);
16411650

16421651
// Fetch the logs for Wormhole message.
16431652
Vm.Log[] memory logs = vm.getRecordedLogs();
@@ -1663,7 +1672,9 @@ contract TokenRouterTest is Test, ITokenRouterEvents {
16631672
vm.recordLogs();
16641673

16651674
// Place the order.
1666-
_router.placeFastMarketOrder(
1675+
_router.placeFastMarketOrder{
1676+
value: WORMHOLE_MESSAGE_FEE * 2
1677+
}(
16671678
expectedOrder.amountIn,
16681679
expectedOrder.minAmountOut,
16691680
expectedOrder.targetChain,
@@ -1708,7 +1719,9 @@ contract TokenRouterTest is Test, ITokenRouterEvents {
17081719
vm.recordLogs();
17091720

17101721
// Place the order.
1711-
_router.placeFastMarketOrder(
1722+
_router.placeFastMarketOrder{
1723+
value: WORMHOLE_MESSAGE_FEE * 2
1724+
}(
17121725
amountIn, targetChain, redeemer, redeemerMessage, maxFee, deadline
17131726
);
17141727

evm/ts/src/TokenRouter/evm.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ export class EvmTokenRouter implements TokenRouter<ethers.ContractTransaction> {
4242
redeemerMessage: Buffer | Uint8Array,
4343
minAmountOut?: bigint,
4444
refundAddress?: string,
45+
transactionValue?: bigint,
4546
) {
4647
if (minAmountOut !== undefined && refundAddress !== undefined) {
4748
return this.contract["placeMarketOrder(uint64,uint64,uint16,bytes32,bytes,address)"](
@@ -51,13 +52,19 @@ export class EvmTokenRouter implements TokenRouter<ethers.ContractTransaction> {
5152
redeemer,
5253
redeemerMessage,
5354
refundAddress,
55+
{
56+
value: transactionValue,
57+
}
5458
);
5559
} else {
5660
return this.contract["placeMarketOrder(uint64,uint16,bytes32,bytes)"](
5761
amountIn,
5862
targetChain,
5963
redeemer,
6064
redeemerMessage,
65+
{
66+
value: transactionValue,
67+
}
6168
);
6269
}
6370
}
@@ -71,6 +78,7 @@ export class EvmTokenRouter implements TokenRouter<ethers.ContractTransaction> {
7178
deadline: number,
7279
minAmountOut?: bigint,
7380
refundAddress?: string,
81+
transactionValue?: bigint,
7482
) {
7583
if (minAmountOut !== undefined && refundAddress !== undefined) {
7684
return this.contract[
@@ -84,6 +92,9 @@ export class EvmTokenRouter implements TokenRouter<ethers.ContractTransaction> {
8492
refundAddress,
8593
maxFee,
8694
deadline,
95+
{
96+
value: transactionValue,
97+
}
8798
);
8899
} else {
89100
return this.contract["placeFastMarketOrder(uint64,uint16,bytes32,bytes,uint64,uint32)"](
@@ -93,6 +104,9 @@ export class EvmTokenRouter implements TokenRouter<ethers.ContractTransaction> {
93104
redeemerMessage,
94105
maxFee,
95106
deadline,
107+
{
108+
value: transactionValue,
109+
}
96110
);
97111
}
98112
}

evm/ts/src/testing/consts.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export const USDC_DECIMALS: NetworkVars<number> = {
1919
Base: 6,
2020
};
2121

22-
export const WORMHOLE_MESSAGE_FEE = 0;
22+
export const WORMHOLE_MESSAGE_FEE = 100000000000000n;
2323
export const WORMHOLE_GUARDIAN_SET_INDEX = 4;
2424
export const GUARDIAN_PRIVATE_KEY =
2525
"cfb12303a19cde580bb4dd771639b0d26bc68353645571a8cff516ab2ee113a0";

evm/ts/tests/00__environment.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,15 @@ describe("Environment", () => {
5959
const actualChainId = await coreBridge.chainId();
6060
expect(actualChainId).to.equal(chainId);
6161

62+
{
63+
// set message fee
64+
const messageFeeSlot = 7;
65+
await provider.send("anvil_setStorageAt", [
66+
coreBridge.address,
67+
messageFeeSlot,
68+
ethers.utils.hexZeroPad(`0x${WORMHOLE_MESSAGE_FEE.toString(16)}`, 32),
69+
]);
70+
}
6271
// fetch current coreBridge protocol fee
6372
const messageFee = await coreBridge.messageFee();
6473
expect(messageFee.eq(WORMHOLE_MESSAGE_FEE)).to.be.true;
@@ -243,7 +252,7 @@ describe("Environment", () => {
243252
const scripts = `${__dirname}/../../sh`;
244253
const cmd =
245254
`bash ${scripts}/deploy_matching_engine.sh ` +
246-
`-n localnet -c ${chainName} -u ${localhost} -k ${owner.privateKey} ` +
255+
`-n localnet -c ${chainName} -u ${localhost} -k ${owner.privateKey}` +
247256
`> /dev/null 2>&1`;
248257
const out = execSync(cmd, { encoding: "utf8" });
249258

evm/ts/tests/03__marketOrder.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
ChainType,
1515
parseLiquidityLayerEnvFile,
1616
tryNativeToUint8Array,
17+
WORMHOLE_MESSAGE_FEE,
1718
} from "../src/testing";
1819
import { toChainId } from "@wormhole-foundation/sdk-base";
1920

@@ -113,6 +114,7 @@ describe("Market Order Business Logic -- CCTP to CCTP", () => {
113114
Buffer.from("All your base are belong to us."),
114115
minAmountOut,
115116
fromWallet.address,
117+
WORMHOLE_MESSAGE_FEE,
116118
)
117119
.then((tx) => mineWait(fromProvider, tx))
118120
.catch((err) => {

0 commit comments

Comments
 (0)