Skip to content

Commit bacbe82

Browse files
CCTP-support + Remove Replay Protection (#18)
* CCTP support * remove replay protection --------- Co-authored-by: Joe Howarth <[email protected]>
1 parent 5b6e2dd commit bacbe82

26 files changed

+2888
-568
lines changed

README.md

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,24 @@ forge install wormhole-foundation/wormhole-solidity-sdk
1414

1515
[HelloWormhole - Simple cross-chain message sending application](https://github.com/wormhole-foundation/hello-wormhole)
1616

17-
[HelloToken - Simple cross-chain token sending application](https://github.com/wormhole-foundation/hello-token)
17+
[HelloToken - Simple cross-chain token sending application](https://github.com/wormhole-foundation/hello-tokens)
18+
19+
[HelloUSDC - Simple cross-chain USDC sending application using CCTP](https://github.com/wormhole-foundation/hello-usdc)
1820

1921
### SDK Summary
2022

2123
- Includes interfaces to interact with contracts in the Wormhole ecosystem ([src/interfaces](https://github.com/wormhole-foundation/wormhole-solidity-sdk/tree/main/src/interfaces))
2224
- Includes the base class ‘Base’ with helpers for common actions that will typically need to be done within ‘receiveWormholeMessages’:
23-
- [`onlyWormholeRelayer()`](https://github.com/wormhole-foundation/wormhole-solidity-sdk/blob/main/src/WormholeRelayerSDK.sol#L26): Checking that msg.sender is the wormhole relayer contract
24-
- [`replayProtect(bytes32 deliveryHash)`](https://github.com/wormhole-foundation/wormhole-solidity-sdk/blob/main/src/WormholeRelayerSDK.sol#L31): Checking that the current delivery has not already been processed (via the hash)
25+
- [`onlyWormholeRelayer()`](https://github.com/wormhole-foundation/wormhole-solidity-sdk/blob/main/src/Base.sol#L24): Checking that msg.sender is the wormhole relayer contract
2526
Sometimes, Cross-chain applications may be set up such that there is one ‘spoke’ contract on every chain, which sends messages to the ‘hub’ contract. If so, we’d ideally only want to allow messages to be sent from these spoke contracts. Included are helpers for this:
26-
- [`setRegisteredSender(uint16 sourceChain, bytes32 sourceAddress)`](https://github.com/wormhole-foundation/wormhole-solidity-sdk/blob/main/src/WormholeRelayerSDK.sol#L49): Setting the specified sender for ‘sourceChain’ to be ‘sourceAddress’
27-
- [`isRegisteredSender(uint16 sourceChain, bytes32 sourceAddress)`](https://github.com/wormhole-foundation/wormhole-solidity-sdk/blob/main/src/WormholeRelayerSDK.sol#L37): Checking that the sender who requested the delivery is the registered address for that chain
28-
Look at [test/Fork.t.sol](https://github.com/wormhole-foundation/wormhole-solidity-sdk/blob/main/test/Fork.t.sol#L16) for an example usage of Base
29-
- Included are also the ‘[TokenSender](https://github.com/wormhole-foundation/wormhole-solidity-sdk/blob/main/src/WormholeRelayerSDK.sol#L79)’ and ‘[TokenReceiver](https://github.com/wormhole-foundation/wormhole-solidity-sdk/blob/main/src/WormholeRelayerSDK.sol#L186)’ base classes with helpers for smart contracts that wish to send and receive tokens using Wormhole’s TokenBridge. See ‘[HelloToken](https://github.com/wormhole-foundation/hello-token)’ for example usage.
27+
28+
- [`setRegisteredSender(uint16 sourceChain, bytes32 sourceAddress)`](https://github.com/wormhole-foundation/wormhole-solidity-sdk/blob/main/src/Base.sol#L47): Setting the specified sender for ‘sourceChain’ to be ‘sourceAddress’
29+
- [`isRegisteredSender(uint16 sourceChain, bytes32 sourceAddress)`](https://github.com/wormhole-foundation/wormhole-solidity-sdk/blob/main/src/Base.sol#L35): Checking that the sender who requested the delivery is the registered address for that chain
30+
31+
Look at test/Counter.t.sol for an example usage of Base
32+
33+
- Included are also the ‘[TokenSender](https://github.com/wormhole-foundation/wormhole-solidity-sdk/blob/main/src/TokenBase#L36)’ and ‘[TokenReceiver](https://github.com/wormhole-foundation/wormhole-solidity-sdk/blob/main/src/TokenBase.sol#L126)’ base classes with helpers for smart contracts that wish to send and receive tokens using Wormhole’s TokenBridge. See ‘[HelloToken](https://github.com/wormhole-foundation/hello-token)’ for example usage.
34+
- Included are also the ‘[CCTPSender](https://github.com/wormhole-foundation/wormhole-solidity-sdk/blob/main/src/CCTPBase#L70)’ and ‘[CCTPReceiver](https://github.com/wormhole-foundation/wormhole-solidity-sdk/blob/main/src/CCTPBase.sol#L134)’ base classes with helpers for smart contracts that wish to send and receive both tokens using Wormhole’s TokenBridge as well as USDC using CCTP. See ‘[HelloUSDC](https://github.com/wormhole-foundation/hello-usdc)’ for example usage.
3035
- Included are helpers that help set up a local forge testing environment. See ‘[HelloWormhole](https://github.com/wormhole-foundation/hello-wormhole)’ for example usage.
31-
**Note: This code is meant to be used as starter / reference code. Feel free to modify for use in your contracts, and also make sure to audit any code used from here as part of your contracts before deploying to mainnet.**
36+
37+
**Note: This code is meant to be used as starter / reference code. Feel free to modify for use in your contracts, and also make sure to audit any code used from here as part of your contracts before deploying to mainnet.**

foundry.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@ solc_version = "0.8.13"
33
src = "src"
44
out = "out"
55
libs = ["lib"]
6+
via_ir = true
67

78
# See more config options https://github.com/foundry-rs/foundry/tree/master/config

src/Base.sol

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
pragma solidity ^0.8.13;
2+
3+
import "./interfaces/IWormholeReceiver.sol";
4+
import "./interfaces/IWormholeRelayer.sol";
5+
import "./interfaces/IWormhole.sol";
6+
import "./Utils.sol";
7+
8+
abstract contract Base {
9+
IWormholeRelayer public immutable wormholeRelayer;
10+
IWormhole public immutable wormhole;
11+
12+
address registrationOwner;
13+
mapping(uint16 => bytes32) registeredSenders;
14+
15+
constructor(address _wormholeRelayer, address _wormhole) {
16+
wormholeRelayer = IWormholeRelayer(_wormholeRelayer);
17+
wormhole = IWormhole(_wormhole);
18+
registrationOwner = msg.sender;
19+
}
20+
21+
modifier onlyWormholeRelayer() {
22+
require(
23+
msg.sender == address(wormholeRelayer),
24+
"Msg.sender is not Wormhole Relayer"
25+
);
26+
_;
27+
}
28+
29+
modifier isRegisteredSender(uint16 sourceChain, bytes32 sourceAddress) {
30+
require(
31+
registeredSenders[sourceChain] == sourceAddress,
32+
"Not registered sender"
33+
);
34+
_;
35+
}
36+
37+
/**
38+
* Sets the registered address for 'sourceChain' to 'sourceAddress'
39+
* So that for messages from 'sourceChain', only ones from 'sourceAddress' are valid
40+
*
41+
* Assumes only one sender per chain is valid
42+
* Sender is the address that called 'send' on the Wormhole Relayer contract on the source chain)
43+
*/
44+
function setRegisteredSender(
45+
uint16 sourceChain,
46+
bytes32 sourceAddress
47+
) public {
48+
require(
49+
msg.sender == registrationOwner,
50+
"Not allowed to set registered sender"
51+
);
52+
registeredSenders[sourceChain] = sourceAddress;
53+
}
54+
}

0 commit comments

Comments
 (0)