Skip to content

Commit

Permalink
evm: target -> destination
Browse files Browse the repository at this point in the history
  • Loading branch information
a5-pickle committed Jan 3, 2024
1 parent 47cda1d commit fb9460c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 23 deletions.
6 changes: 3 additions & 3 deletions evm/src/contracts/CircleIntegration/Logic.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ abstract contract Logic is ICircleIntegration, Governance {
bytes calldata payload
) public payable returns (uint64 wormholeSequence) {
// Is the foreign Wormhole Circle Integration registered?
bytes32 targetCaller = getRegisteredEmitters()[transferParams.targetChain];
require(targetCaller != 0, "target contract not registered");
bytes32 destinationCaller = getRegisteredEmitters()[transferParams.targetChain];
require(destinationCaller != 0, "target contract not registered");

// Approve the Token Messenger to spend tokens.
setTokenMessengerApproval(transferParams.token, transferParams.amount);

// Invoke Token Messenger to burn tokens and emit a CCTP token burn message.
(wormholeSequence,) = burnAndPublish(
targetCaller,
destinationCaller,
getChainToDomain()[transferParams.targetChain],
transferParams.token,
transferParams.amount,
Expand Down
43 changes: 23 additions & 20 deletions evm/src/contracts/WormholeCctpTokenMessenger.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@ import {WormholeCctpMessages} from "src/libraries/WormholeCctpMessages.sol";
/**
* @notice A way to associate a CCTP token burn message with a Wormhole message.
* @dev To construct the contract, the addresses to the Wormhole Core Bridge and CCTP Token
* Messenger must be provided. Using the CCTP Token Messenger, the Message Transmitter and Token
* Minter are derived.
* Messenger must be provided. Using the CCTP Token Messenger, the Message Transmitter and Token
* Minter are derived.
*
* NOTE: For more information on CCTP message formats, please refer to the following:
* https://developers.circle.com/stablecoins/docs/message-format.
*/
abstract contract WormholeCctpTokenMessenger {
using Utils for address;
Expand All @@ -35,7 +38,7 @@ abstract contract WormholeCctpTokenMessenger {
error CallerNotMintRecipient(bytes32, bytes32);

/**
* @dev The CCTP message's source domain, target domain and nonce must match the VAA's.
* @dev The CCTP message's source domain, destination domain and nonce must match the VAA's.
* NOTE: This nonce is the one acting as the CCTP message sequence (and not the arbitrary one
* specified when publishing Wormhole messages).
*/
Expand Down Expand Up @@ -98,16 +101,16 @@ abstract contract WormholeCctpTokenMessenger {
/**
* @dev Method to burn tokens via CCTP Token Messenger and publish a Wormhole message associated
* with the CCTP Token Burn message. The Wormhole message encodes a `Deposit` (ID == 1), which
* has the same source domain, target domain and nonce as the CCTP Token Burn message.
* has the same source domain, destination domain and nonce as the CCTP Token Burn message.
*
* NOTE: This method does not protect against re-entrancy here because it relies on the CCTP
* Token Messenger to protect against any possible re-entrancy. We are leaning on the fact that
* the Token Messenger keeps track of its local tokens, which are the only tokens it allows to
* burn (and in turn, mint on another network).
*/
function burnAndPublish(
bytes32 targetCaller,
uint32 targetCctpDomain,
bytes32 destinationCaller,
uint32 destinationCctpDomain,
address token,
uint256 amount,
bytes32 mintRecipient,
Expand All @@ -120,7 +123,7 @@ abstract contract WormholeCctpTokenMessenger {

// Invoke Token Messenger to burn tokens and emit a CCTP token burn message.
cctpNonce = _tokenMessenger.depositForBurnWithCaller(
amount, targetCctpDomain, mintRecipient, token, targetCaller
amount, destinationCctpDomain, mintRecipient, token, destinationCaller
);

// Publish deposit message via Wormhole Core Bridge.
Expand All @@ -129,7 +132,7 @@ abstract contract WormholeCctpTokenMessenger {
token.encodeDeposit(
amount,
_localCctpDomain, // sourceCctpDomain
targetCctpDomain,
destinationCctpDomain,
cctpNonce,
msg.sender.toUniversalAddress(), // burnSource
mintRecipient,
Expand Down Expand Up @@ -167,14 +170,14 @@ abstract contract WormholeCctpTokenMessenger {

// Decode the deposit message so we can match the Wormhole message with the CCTP message.
uint32 sourceCctpDomain;
uint32 targetCctpDomain;
uint32 destinationCctpDomain;
uint64 cctpNonce;
bytes32 mintRecipient;
(
token,
amount,
sourceCctpDomain,
targetCctpDomain,
destinationCctpDomain,
cctpNonce,
burnSource,
mintRecipient,
Expand All @@ -187,7 +190,7 @@ abstract contract WormholeCctpTokenMessenger {
cctpAttestation,
mintRecipient,
sourceCctpDomain,
targetCctpDomain,
destinationCctpDomain,
cctpNonce,
token,
true // revertCustomErrors
Expand All @@ -212,7 +215,7 @@ abstract contract WormholeCctpTokenMessenger {
bytes32 token,
uint256 amount,
uint32 sourceCctpDomain,
uint32 targetCctpDomain,
uint32 destinationCctpDomain,
uint64 cctpNonce,
bytes32 burnSource,
bytes32 mintRecipient,
Expand All @@ -230,7 +233,7 @@ abstract contract WormholeCctpTokenMessenger {
token,
amount,
sourceCctpDomain,
targetCctpDomain,
destinationCctpDomain,
cctpNonce,
burnSource,
mintRecipient,
Expand All @@ -243,7 +246,7 @@ abstract contract WormholeCctpTokenMessenger {
cctpAttestation,
mintRecipient,
sourceCctpDomain,
targetCctpDomain,
destinationCctpDomain,
cctpNonce,
token,
false // revertCustomErrors
Expand Down Expand Up @@ -289,7 +292,7 @@ abstract contract WormholeCctpTokenMessenger {
bytes calldata cctpAttestation,
bytes32 mintRecipient,
uint32 vaaSourceCctpDomain,
uint32 vaaTargetCctpDomain,
uint32 vaaDestinationCctpDomain,
uint64 vaaCctpNonce,
bytes32 burnToken,
bool revertCustomErrors
Expand All @@ -306,7 +309,7 @@ abstract contract WormholeCctpTokenMessenger {
// Confirm that the caller passed the correct message pair.
{
uint32 sourceDomain;
uint32 targetDomain;
uint32 destinationDomain;
uint64 nonce;

assembly ("memory-safe") {
Expand All @@ -318,18 +321,18 @@ abstract contract WormholeCctpTokenMessenger {

// Source domain is bytes 4..8, so shift 24 bytes to the right.
sourceDomain := shr(192, ptr)
// Target domain is bytes 8..12, so shift 20 bytes to the right.
targetDomain := shr(160, ptr)
// Destination domain is bytes 8..12, so shift 20 bytes to the right.
destinationDomain := shr(160, ptr)
// Nonce is bytes 12..20, so shift 12 bytes to the right.
nonce := shr(96, ptr)
}

if (
vaaSourceCctpDomain != sourceDomain || vaaTargetCctpDomain != targetDomain
vaaSourceCctpDomain != sourceDomain || vaaDestinationCctpDomain != destinationDomain
|| vaaCctpNonce != nonce
) {
if (revertCustomErrors) {
revert CctpVaaMismatch(sourceDomain, targetDomain, nonce);
revert CctpVaaMismatch(sourceDomain, destinationDomain, nonce);
} else {
Utils.revertBuiltIn("invalid message pair");
}
Expand Down

0 comments on commit fb9460c

Please sign in to comment.