Skip to content

Commit

Permalink
forge fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
derpy-duck committed Sep 27, 2023
1 parent 422ca4f commit 1639a14
Show file tree
Hide file tree
Showing 21 changed files with 267 additions and 511 deletions.
1 change: 0 additions & 1 deletion src/Base.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

pragma solidity ^0.8.13;

import "./interfaces/IWormholeReceiver.sol";
Expand Down
7 changes: 2 additions & 5 deletions src/CCTPBase.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

pragma solidity ^0.8.13;

import "./interfaces/IWormholeReceiver.sol";
Expand Down Expand Up @@ -94,9 +93,7 @@ abstract contract CCTPSender is CCTPBase {
USDC,
addressToBytes32CCTP(targetAddress)
);
return MessageKey(
CCTPMessageLib.CCTP_KEY_TYPE, abi.encodePacked(getCCTPDomain(wormhole.chainId()), nonce)
);
return MessageKey(CCTPMessageLib.CCTP_KEY_TYPE, abi.encodePacked(getCCTPDomain(wormhole.chainId()), nonce));
}

function sendUSDCWithPayloadToEvm(
Expand All @@ -114,7 +111,7 @@ abstract contract CCTPSender is CCTPBase {
address defaultDeliveryProvider = wormholeRelayer.getDefaultDeliveryProvider();

(uint256 cost,) = wormholeRelayer.quoteEVMDeliveryPrice(targetChain, receiverValue, gasLimit);

sequence = wormholeRelayer.sendToEvm{value: cost}(
targetChain,
targetAddress,
Expand Down
2 changes: 0 additions & 2 deletions src/TokenBase.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

pragma solidity ^0.8.13;

import "./interfaces/IWormholeReceiver.sol";
Expand Down Expand Up @@ -120,7 +119,6 @@ abstract contract TokenSender is TokenBase {
targetChain, targetAddress, payload, receiverValue, gasLimit, vaaKeys, refundChain, refundAddress
);
}

}

abstract contract TokenReceiver is TokenBase {
Expand Down
1 change: 0 additions & 1 deletion src/Utils.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

pragma solidity ^0.8.13;

import "./interfaces/IWormholeRelayer.sol";
Expand Down
1 change: 0 additions & 1 deletion src/WormholeRelayerSDK.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

pragma solidity ^0.8.13;

import "./interfaces/IWormholeReceiver.sol";
Expand Down
4 changes: 1 addition & 3 deletions src/interfaces/CCTPInterfaces/IMessageTransmitter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,4 @@ import "./IReceiver.sol";
* @title IMessageTransmitter
* @notice Interface for message transmitters, which both relay and receive messages.
*/
interface IMessageTransmitter is IRelayer, IReceiver {

}
interface IMessageTransmitter is IRelayer, IReceiver {}
4 changes: 1 addition & 3 deletions src/interfaces/CCTPInterfaces/IReceiver.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,5 @@ interface IReceiver {
* @param signature The message signature
* @return success bool, true if successful
*/
function receiveMessage(bytes calldata message, bytes calldata signature)
external
returns (bool success);
function receiveMessage(bytes calldata message, bytes calldata signature) external returns (bool success);
}
8 changes: 3 additions & 5 deletions src/interfaces/CCTPInterfaces/IRelayer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,9 @@ interface IRelayer {
* @param messageBody Raw bytes content of message
* @return nonce reserved by message
*/
function sendMessage(
uint32 destinationDomain,
bytes32 recipient,
bytes calldata messageBody
) external returns (uint64);
function sendMessage(uint32 destinationDomain, bytes32 recipient, bytes calldata messageBody)
external
returns (uint64);

/**
* @notice Sends an outgoing message from the source domain, with a specified caller on the
Expand Down
3 changes: 1 addition & 2 deletions src/interfaces/CCTPInterfaces/ITokenMessenger.sol
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@

pragma solidity ^0.8.0;

interface ITokenMessenger {
/**
/**
* @notice Deposits and burns tokens from sender to be minted on destination domain. The mint
* on the destination domain must be called by `destinationCaller`.
* WARNING: if the `destinationCaller` does not represent a valid address as bytes32, then it will not be possible
Expand Down
228 changes: 111 additions & 117 deletions src/interfaces/IWormholeRelayer.sol

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion src/testing/ERC20Mock.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

pragma solidity ^0.8.13;

import "../interfaces/IERC20.sol";
Expand Down
19 changes: 8 additions & 11 deletions src/testing/WormholeRelayerTest.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

pragma solidity ^0.8.13;

import "../../src/interfaces/IWormholeRelayer.sol";
Expand Down Expand Up @@ -145,7 +144,8 @@ abstract contract WormholeRelayerTest is Test {

ActiveFork memory firstFork = activeForks[activeForksList[0]];
vm.selectFork(firstFork.fork);
mockOffchainRelayer = new MockOffchainRelayer(address(firstFork.wormhole), address(firstFork.guardian), address(firstFork.circleAttester));
mockOffchainRelayer =
new MockOffchainRelayer(address(firstFork.wormhole), address(firstFork.guardian), address(firstFork.circleAttester));
// register all active forks with the 'offchain' relayer
for (uint256 i = 0; i < activeForksList.length; ++i) {
ActiveFork storage fork = activeForks[activeForksList[i]];
Expand Down Expand Up @@ -193,7 +193,7 @@ abstract contract WormholeRelayerTest is Test {
bytes memory attestation = home.guardian.fetchSignedMessageFromLogs(log, home.chainId);

for (uint256 i = 0; i < activeForksList.length; ++i) {
if(activeForksList[i] == home.chainId) {
if (activeForksList[i] == home.chainId) {
continue;
}
ActiveFork memory fork = activeForks[activeForksList[i]];
Expand All @@ -217,7 +217,6 @@ abstract contract WormholeRelayerTest is Test {
vm.selectFork(originalFork);
}


function logFork() public view {
uint256 fork = vm.activeFork();
for (uint256 i = 0; i < activeForksList.length; ++i) {
Expand Down Expand Up @@ -488,7 +487,6 @@ abstract contract WormholeRelayerBasicTest is WormholeRelayerTest {
CircleMessageTransmitterSimulator public circleAttesterSource;
CircleMessageTransmitterSimulator public circleAttesterTarget;


/*
* end activeForks aliases
*/
Expand Down Expand Up @@ -551,11 +549,10 @@ abstract contract WormholeRelayerBasicTest is WormholeRelayerTest {
}

function setForkChains(bool testnet, uint16 _sourceChain, uint16 _targetChain) public {
if (testnet) {
setTestnetForkChains(_sourceChain, _targetChain);
return;
}
setMainnetForkChains(_sourceChain, _targetChain);
if (testnet) {
setTestnetForkChains(_sourceChain, _targetChain);
return;
}
setMainnetForkChains(_sourceChain, _targetChain);
}

}
1 change: 0 additions & 1 deletion src/testing/helpers/BytesParsing.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

pragma solidity ^0.8.13;

library BytesParsing {
Expand Down
51 changes: 14 additions & 37 deletions src/testing/helpers/CircleCCTPSimulator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ contract CircleMessageTransmitterSimulator {
bool public valid;

// Taken from forge-std/Script.sol
address private constant VM_ADDRESS =
address(bytes20(uint160(uint256(keccak256("hevm cheat code")))));
address private constant VM_ADDRESS = address(bytes20(uint160(uint256(keccak256("hevm cheat code")))));
Vm public constant vm = Vm(VM_ADDRESS);

// Allow access to MessageTransmitter
Expand All @@ -48,16 +47,14 @@ contract CircleMessageTransmitterSimulator {
messageTransmitter = IMessageTransmitter(messageTransmitter_);
attesterPrivateKey = attesterPrivateKey_;
valid = messageTransmitter_ != address(0);
if(valid) overrideAttester(vm.addr(attesterPrivateKey));
if (valid) overrideAttester(vm.addr(attesterPrivateKey));
}

function overrideAttester(address attesterPublicKey) internal {
{
MessageTransmitterViewAttesterManager attesterManagerInterface = MessageTransmitterViewAttesterManager(
address(messageTransmitter)
);
address attesterManager = attesterManagerInterface
.attesterManager();
MessageTransmitterViewAttesterManager attesterManagerInterface =
MessageTransmitterViewAttesterManager(address(messageTransmitter));
address attesterManager = attesterManagerInterface.attesterManager();
vm.prank(attesterManager);
attesterManagerInterface.enableAttester(attesterPublicKey);

Expand All @@ -66,10 +63,7 @@ contract CircleMessageTransmitterSimulator {
}
}


function parseMessageFromMessageTransmitterLog(
Vm.Log memory log
) internal pure returns (bytes memory message) {
function parseMessageFromMessageTransmitterLog(Vm.Log memory log) internal pure returns (bytes memory message) {
uint256 index = 32;

// length of payload
Expand All @@ -82,25 +76,17 @@ contract CircleMessageTransmitterSimulator {
// trailing bytes (due to 32 byte slot overlap)
require(log.data.length - index < 32, "Too many extra bytes");
index += log.data.length - index;
require(
index == log.data.length,
"failed to parse MessageTransmitter message"
);
require(index == log.data.length, "failed to parse MessageTransmitter message");
}

/**
* @notice Finds published messageTransmitter events in forge logs
* @param logs The forge Vm.log captured when recording events during test execution
*/
function fetchMessageTransmitterLogsFromLogs(
Vm.Log[] memory logs
) public pure returns (Vm.Log[] memory) {
function fetchMessageTransmitterLogsFromLogs(Vm.Log[] memory logs) public pure returns (Vm.Log[] memory) {
uint256 count = 0;
for (uint256 i = 0; i < logs.length; i++) {
if (
logs[i].topics[0] ==
keccak256("MessageSent(bytes)")
) {
if (logs[i].topics[0] == keccak256("MessageSent(bytes)")) {
count += 1;
}
}
Expand All @@ -110,10 +96,7 @@ contract CircleMessageTransmitterSimulator {

uint256 publishedIndex = 0;
for (uint256 i = 0; i < logs.length; i++) {
if (
logs[i].topics[0] ==
keccak256("MessageSent(bytes)")
) {
if (logs[i].topics[0] == keccak256("MessageSent(bytes)")) {
published[publishedIndex] = logs[i];
publishedIndex += 1;
}
Expand All @@ -127,31 +110,25 @@ contract CircleMessageTransmitterSimulator {
* @param log The forge Vm.log captured when recording events during test execution
* @return attestation attested message
*/

function fetchSignedMessageFromLog(
Vm.Log memory log
) public view returns (CCTPMessageLib.CCTPMessage memory) {

function fetchSignedMessageFromLog(Vm.Log memory log) public view returns (CCTPMessageLib.CCTPMessage memory) {
// Parse messageTransmitter message from ethereum logs
bytes memory message = parseMessageFromMessageTransmitterLog(log);

return CCTPMessageLib.CCTPMessage(message, signMessage(message));
}

/**
* @notice Signs a simulated messageTransmitter message
* @param message The messageTransmitter message
* @return signedMessage signed messageTransmitter message
*/

function signMessage(
bytes memory message
) public view returns (bytes memory signedMessage) {

function signMessage(bytes memory message) public view returns (bytes memory signedMessage) {
bytes32 messageHash = keccak256(message);

// Sign the hash with the attester private key
(uint8 v, bytes32 r, bytes32 s) = vm.sign(attesterPrivateKey, messageHash);
return abi.encodePacked(r, s, v);
}

}
Loading

0 comments on commit 1639a14

Please sign in to comment.