Skip to content

Commit

Permalink
Merge testing refactor (#52)
Browse files Browse the repository at this point in the history
* refactor and enhance testing utilities

* fix WormholeOverride.sign() by using provided params

* enable decodeDeposit from bytes directly

* further cleanup refactor and extend README

* fix formating
  • Loading branch information
nonergodic authored Aug 28, 2024
1 parent fa2dc15 commit 189fd62
Show file tree
Hide file tree
Showing 30 changed files with 1,285 additions and 1,370 deletions.
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,18 @@ forge install wormhole-foundation/[email protected]

**EVM Version**

One hazard of developing EVM contracts in a cross-chain environment is that different chains have varying levels EVM-equivalence. This means you have to ensure that all chains that you are planning to deploy to support all EIPs/opcodes that you rely on.
One hazard of developing EVM contracts in a cross-chain environment is that different chains have varying levels of "EVM-equivalence". This means you have to ensure that all chains that you are planning to deploy to support all EIPs/opcodes that you rely on.

For example, if you are using a solc version newer than `0.8.19` and are planning to deploy to a chain that does not support [PUSH0 opcode](https://eips.ethereum.org/EIPS/eip-3855) (introduced as part of the Shanghai hardfork), you should set `evm_version = "paris"` in your `foundry.toml`, since the default EVM version of solc was advanced from Paris to Shanghai as part of solc's `0.8.20` release.

**Testing**

It is strongly recommended that you run the forge test suite of this SDK with your own compiler version to catch potential errors that stem from differences in compiler versions early. Yes, strictly speaking the Solidity version pragma should prevent these issues, but better to be safe than sorry, especially given that some components make extensive use of inline assembly.

**IERC20 Remapping**

This SDK comes with its own IERC20 interface. Given that projects tend to combine different SDKs, there's often this annoying issue of clashes of IERC20 interfaces, even though the are effectively the same. We handle this issue by importing `IERC20/IERC20.sol` which allows remapping the `IERC20/` prefix to whatever directory contains `IERC20.sol` in your project, thus providing an override mechanism that should allow dealing with this problem seamlessly until forge allows remapping of individual files.

## Philosophy/Creeds

In This House We Believe:
Expand Down
6 changes: 6 additions & 0 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,16 @@ out = "out"
libs = ["lib"]
via_ir = true

#currently, forge does not allow remapping of individual files
# (see here: https://github.com/foundry-rs/foundry/issues/7527#issuecomment-2269444829)
#so for now we are using the IERC20 prefix as a workaround that allows users
# to override the IERC20 interface with whatever they use in their project
# (well, as long as their file is also called IERC20.sol and is interface compatible)
remappings = [
"ds-test/=lib/forge-std/lib/ds-test/src/",
"forge-std/=lib/forge-std/src/",
"wormhole-sdk/=src/",
"IERC20/=src/interfaces/token/",
]

# See more config options https://github.com/foundry-rs/foundry/tree/master/config
2 changes: 1 addition & 1 deletion src/WormholeRelayer/CCTPAndTokenBase.sol
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// SPDX-License-Identifier: Apache 2
pragma solidity ^0.8.19;

import "IERC20/IERC20.sol";
import "wormhole-sdk/interfaces/IWormholeReceiver.sol";
import "wormhole-sdk/interfaces/IWormholeRelayer.sol";
import "wormhole-sdk/interfaces/ITokenBridge.sol";
import "wormhole-sdk/interfaces/token/IERC20.sol";
import "wormhole-sdk/interfaces/cctp/ITokenMessenger.sol";
import "wormhole-sdk/interfaces/cctp/IMessageTransmitter.sol";
import "wormhole-sdk/Utils.sol";
Expand Down
2 changes: 1 addition & 1 deletion src/WormholeRelayer/CCTPBase.sol
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// SPDX-License-Identifier: Apache 2
pragma solidity ^0.8.19;

import "IERC20/IERC20.sol";
import "wormhole-sdk/interfaces/IWormholeReceiver.sol";
import "wormhole-sdk/interfaces/IWormholeRelayer.sol";
import "wormhole-sdk/interfaces/token/IERC20.sol";
import "wormhole-sdk/interfaces/cctp/ITokenMessenger.sol";
import "wormhole-sdk/interfaces/cctp/IMessageTransmitter.sol";
import "wormhole-sdk/Utils.sol";
Expand Down
2 changes: 1 addition & 1 deletion src/WormholeRelayer/TokenBase.sol
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// SPDX-License-Identifier: Apache 2
pragma solidity ^0.8.19;

import "IERC20/IERC20.sol";
import "wormhole-sdk/interfaces/IWormholeReceiver.sol";
import "wormhole-sdk/interfaces/IWormholeRelayer.sol";
import "wormhole-sdk/interfaces/ITokenBridge.sol";
import "wormhole-sdk/interfaces/token/IERC20.sol";
import "wormhole-sdk/Utils.sol";

import {Base} from "./Base.sol";
Expand Down
3 changes: 1 addition & 2 deletions src/interfaces/ITokenBridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

pragma solidity ^0.8.0;

import "./token/IWETH.sol";
import "./IWormhole.sol";

interface ITokenBridge {
Expand Down Expand Up @@ -149,7 +148,7 @@ interface ITokenBridge {

function tokenImplementation() external view returns (address);

function WETH() external view returns (IWETH);
function WETH() external view returns (address);

function outstandingBridged(address token) external view returns (uint256);

Expand Down
93 changes: 71 additions & 22 deletions src/interfaces/cctp/IMessageTransmitter.sol
Original file line number Diff line number Diff line change
@@ -1,27 +1,76 @@
/*
* Copyright (c) 2022, Circle Internet Financial Limited.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// SPDX-License-Identifier: Apache 2
// Copyright (c) 2022, Circle Internet Financial Limited.
//
// stripped, flattened version of:
// https://github.com/circlefin/evm-cctp-contracts/blob/master/src/MessageTransmitter.sol

pragma solidity ^0.8.0;

import "./IRelayer.sol";
import "./IReceiver.sol";
import {IOwnable2Step} from "./shared/IOwnable2Step.sol";
import {IPausable} from "./shared/IPausable.sol";

interface IAttestable {
event AttesterEnabled(address indexed attester);
event AttesterDisabled(address indexed attester);

event SignatureThresholdUpdated(uint256 oldSignatureThreshold, uint256 newSignatureThreshold);
event AttesterManagerUpdated(
address indexed previousAttesterManager,
address indexed newAttesterManager
);

function attesterManager() external view returns (address);
function isEnabledAttester(address attester) external view returns (bool);
function getNumEnabledAttesters() external view returns (uint256);
function getEnabledAttester(uint256 index) external view returns (address);

function updateAttesterManager(address newAttesterManager) external;
function setSignatureThreshold(uint256 newSignatureThreshold) external;
function enableAttester(address attester) external;
function disableAttester(address attester) external;
}

interface IMessageTransmitter is IAttestable, IPausable, IOwnable2Step {
event MessageSent(bytes message);

event MessageReceived(
address indexed caller,
uint32 sourceDomain,
uint64 indexed nonce,
bytes32 sender,
bytes messageBody
);

function localDomain() external view returns (uint32);
function version() external view returns (uint32);
function maxMessageBodySize() external view returns (uint256);
function nextAvailableNonce() external view returns (uint64);
function usedNonces(bytes32 nonce) external view returns (bool);

function sendMessage(
uint32 destinationDomain,
bytes32 recipient,
bytes calldata messageBody
) external returns (uint64);

function sendMessageWithCaller(
uint32 destinationDomain,
bytes32 recipient,
bytes32 destinationCaller,
bytes calldata messageBody
) external returns (uint64);

function replaceMessage(
bytes calldata originalMessage,
bytes calldata originalAttestation,
bytes calldata newMessageBody,
bytes32 newDestinationCaller
) external;

/**
* @title IMessageTransmitter
* @notice Interface for message transmitters, which both relay and receive messages.
*/
interface IMessageTransmitter is IRelayer, IReceiver {
function receiveMessage(
bytes calldata message,
bytes calldata attestation
) external returns (bool success);

function setMaxMessageBodySize(uint256 newMaxMessageBodySize) external;
}
33 changes: 0 additions & 33 deletions src/interfaces/cctp/IReceiver.sol

This file was deleted.

71 changes: 0 additions & 71 deletions src/interfaces/cctp/IRelayer.sol

This file was deleted.

Loading

0 comments on commit 189fd62

Please sign in to comment.