Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrate subnetevm 0.5.7 #68

Closed
wants to merge 11 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions abi-bindings/go/Teleporter/TeleporterMessenger/packing.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ func init() {
teleporterMessageType, err = abi.NewType("tuple", "struct Overloader.F", []abi.ArgumentMarshaling{
{Name: "messageID", Type: "uint256"},
{Name: "senderAddress", Type: "address"},
{Name: "destinationChainID", Type: "bytes32"},
{Name: "sourceTeleporterAddress", Type: "address"},
{Name: "destinationAddress", Type: "address"},
{Name: "requiredGasLimit", Type: "uint256"},
{Name: "allowedRelayerAddresses", Type: "address[]"},
Expand Down
10 changes: 6 additions & 4 deletions abi-bindings/go/Teleporter/TeleporterMessenger/packing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ import (

func createTestTeleporterMessage(messageID int64) TeleporterMessage {
m := TeleporterMessage{
MessageID: big.NewInt(messageID),
SenderAddress: common.HexToAddress("0x0123456789abcdef0123456789abcdef01234567"),
DestinationAddress: common.HexToAddress("0x0123456789abcdef0123456789abcdef01234567"),
RequiredGasLimit: big.NewInt(2),
MessageID: big.NewInt(messageID),
SenderAddress: common.HexToAddress("0x0123456789abcdef0123456789abcdef01234567"),
DestinationChainID: [32]byte{1, 2, 3, 4},
SourceTeleporterAddress: common.HexToAddress("0x0123456789abcdef0123456789abcdef01234567"),
DestinationAddress: common.HexToAddress("0x0123456789abcdef0123456789abcdef01234567"),
RequiredGasLimit: big.NewInt(2),
AllowedRelayerAddresses: []common.Address{
common.HexToAddress("0x0123456789abcdef0123456789abcdef01234567"),
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ contract ERC20Bridge is IERC20Bridge, ITeleporterReceiver, ReentrancyGuard {
);

teleporterMessenger = ITeleporterMessenger(teleporterMessengerAddress);
currentChainID = WarpMessenger(WARP_PRECOMPILE_ADDRESS)
currentChainID = IWarpMessenger(WARP_PRECOMPILE_ADDRESS)
.getBlockchainID();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ contract ERC20BridgeTest is Test {
function setUp() public virtual {
vm.mockCall(
WARP_PRECOMPILE_ADDRESS,
abi.encodeWithSelector(WarpMessenger.getBlockchainID.selector),
abi.encodeWithSelector(IWarpMessenger.getBlockchainID.selector),
abi.encode(_MOCK_BLOCKCHAIN_ID)
);

Expand Down
2 changes: 2 additions & 0 deletions contracts/src/Teleporter/ITeleporterMessenger.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ struct TeleporterMessageInput {
struct TeleporterMessage {
uint256 messageID;
address senderAddress;
bytes32 destinationChainID;
address sourceTeleporterAddress;
address destinationAddress;
uint256 requiredGasLimit;
address[] allowedRelayerAddresses;
Expand Down
41 changes: 19 additions & 22 deletions contracts/src/Teleporter/TeleporterMessenger.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import "./ReentrancyGuards.sol";
/**
* @dev Implementation of the {ITeleporterMessenger} interface.
*
* This implementation is used to send messages cross chain using the WarpMessenger precompile,
* This implementation is used to send messages cross chain using the IWarpMessenger precompile,
* and to receive messages sent from other chains. Teleporter contracts should be deployed through Nick's method
* of universal deployer, such that the same contract is deployed at the same address on all chains.
*/
Expand All @@ -30,8 +30,8 @@ contract TeleporterMessenger is ITeleporterMessenger, ReentrancyGuards {
TeleporterFeeInfo feeInfo;
}

WarpMessenger public constant WARP_MESSENGER =
WarpMessenger(0x0200000000000000000000000000000000000005);
IWarpMessenger public constant WARP_MESSENGER =
IWarpMessenger(0x0200000000000000000000000000000000000005);

// Tracks the latest message ID used for a given destination subnet.
// Key is the destination subnet ID, and the value is the last message ID used for that subnet.
Expand Down Expand Up @@ -148,11 +148,7 @@ contract TeleporterMessenger is ITeleporterMessenger, ReentrancyGuards {

// Resubmit the message to the warp message precompile now that we know the exact message was
// already submitted in the past.
WARP_MESSENGER.sendWarpMessage(
destinationChainID,
address(this),
messageBytes
);
WARP_MESSENGER.sendWarpMessage(messageBytes);
}

/**
Expand Down Expand Up @@ -268,20 +264,23 @@ contract TeleporterMessenger is ITeleporterMessenger, ReentrancyGuards {
blockchainID = WARP_MESSENGER.getBlockchainID();
}

// Parse the payload of the message.
TeleporterMessage memory teleporterMessage = abi.decode(
warpMessage.payload,
(TeleporterMessage)
);

// Require that the message was intended for this blockchain and teleporter contract.
require(
warpMessage.destinationChainID == blockchainID,
teleporterMessage.destinationChainID == blockchainID,
"TeleporterMessenger: invalid destination chain ID"
);
require(
warpMessage.destinationAddress == address(this),
"TeleporterMessenger: invalid destination address"
);

// Parse the payload of the message.
TeleporterMessage memory teleporterMessage = abi.decode(
warpMessage.payload,
(TeleporterMessage)
// Require the source teleporter address matches this contract.
// It is previously encoded as destinationAddress in WarpMessage before [email protected]
require(
teleporterMessage.sourceTeleporterAddress == address(this),
"TeleporterMessenger: invalid source teleporter address"
);

// Check the message has not been delivered before by checking that there is no relayer reward
Expand Down Expand Up @@ -601,6 +600,8 @@ contract TeleporterMessenger is ITeleporterMessenger, ReentrancyGuards {
TeleporterMessage memory teleporterMessage = TeleporterMessage({
messageID: messageID,
senderAddress: msg.sender,
destinationChainID: destinationChainID,
sourceTeleporterAddress: address(this),
destinationAddress: destinationAddress,
requiredGasLimit: requiredGasLimit,
allowedRelayerAddresses: allowedRelayerAddresses,
Expand Down Expand Up @@ -652,11 +653,7 @@ contract TeleporterMessenger is ITeleporterMessenger, ReentrancyGuards {
// The Teleporter contract only allows for sending messages to other instances of the same
// contract at the same address on other EVM chains, which is why we set the destination adress
// as the address of this contract.
WARP_MESSENGER.sendWarpMessage(
destinationChainID,
address(this),
teleporterMessageBytes
);
WARP_MESSENGER.sendWarpMessage(teleporterMessageBytes);

return messageID;
}
Expand Down
2 changes: 2 additions & 0 deletions contracts/src/Teleporter/tests/GetMessageHashTests.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ contract GetMessageHashTest is TeleporterMessengerTest {
TeleporterMessage memory expectedMessage = TeleporterMessage({
messageID: messageID,
senderAddress: address(this),
destinationChainID: DEFAULT_DESTINATION_CHAIN_ID,
sourceTeleporterAddress: address(teleporterMessenger),
destinationAddress: DEFAULT_DESTINATION_ADDRESS,
requiredGasLimit: DEFAULT_REQUIRED_GAS_LIMIT,
allowedRelayerAddresses: new address[](0),
Expand Down
8 changes: 4 additions & 4 deletions contracts/src/Teleporter/tests/GetNextMessageIdTests.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ contract GetNextMessageIDTest is TeleporterMessengerTest {

vm.mockCall(
WARP_PRECOMPILE_ADDRESS,
abi.encode(WarpMessenger.sendWarpMessage.selector),
new bytes(0)
abi.encode(IWarpMessenger.sendWarpMessage.selector),
abi.encode(bytes32(0))
);
TeleporterMessageInput memory messageInput = TeleporterMessageInput({
destinationChainID: chainID,
Expand Down Expand Up @@ -62,8 +62,8 @@ contract GetNextMessageIDTest is TeleporterMessengerTest {

vm.mockCall(
WARP_PRECOMPILE_ADDRESS,
abi.encode(WarpMessenger.sendWarpMessage.selector),
new bytes(0)
abi.encode(IWarpMessenger.sendWarpMessage.selector),
abi.encode(bytes32(0))
);
TeleporterMessageInput memory messageInput = TeleporterMessageInput({
destinationChainID: chainID,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,26 +59,29 @@ contract GetOutstandingReceiptsToSendTest is TeleporterMessengerTest {
hex"deadbeef"
);
expectedMessage.receipts = expectedReceipts;
expectedMessage.destinationChainID = chainID;
TeleporterFeeInfo memory feeInfo = TeleporterFeeInfo(address(0), 0);
TeleporterMessageInput memory messageInput = TeleporterMessageInput({
destinationChainID: hex"11223344556677889900aabbccddeeff11223344556677889900aabbccddeeff",
destinationChainID: expectedMessage.destinationChainID,
destinationAddress: expectedMessage.destinationAddress,
feeInfo: feeInfo,
requiredGasLimit: expectedMessage.requiredGasLimit,
allowedRelayerAddresses: expectedMessage.allowedRelayerAddresses,
message: expectedMessage.message
});

vm.mockCall(
WARP_PRECOMPILE_ADDRESS,
abi.encode(IWarpMessenger.sendWarpMessage.selector),
abi.encode(bytes32(0))
);

// Expect the exact message to be passed to the precompile.
vm.expectCall(
WARP_PRECOMPILE_ADDRESS,
abi.encodeCall(
WarpMessenger.sendWarpMessage,
(
messageInput.destinationChainID,
address(teleporterMessenger),
abi.encode(expectedMessage)
)
IWarpMessenger.sendWarpMessage,
(abi.encode(expectedMessage))
)
);

Expand All @@ -100,15 +103,12 @@ contract GetOutstandingReceiptsToSendTest is TeleporterMessengerTest {
2,
hex"deadbeef"
);
nextExpectedMessage.destinationChainID = chainID;
vm.expectCall(
WARP_PRECOMPILE_ADDRESS,
abi.encodeCall(
WarpMessenger.sendWarpMessage,
(
messageInput.destinationChainID,
address(teleporterMessenger),
abi.encode(nextExpectedMessage)
)
IWarpMessenger.sendWarpMessage,
(abi.encode(nextExpectedMessage))
)
);
vm.expectEmit(true, true, true, true, address(teleporterMessenger));
Expand Down Expand Up @@ -192,26 +192,29 @@ contract GetOutstandingReceiptsToSendTest is TeleporterMessengerTest {
hex"deadbeef"
);
expectedMessage.receipts = expectedReceiptsBatch1;
expectedMessage.destinationChainID = chainID;
TeleporterFeeInfo memory feeInfo = TeleporterFeeInfo(address(0), 0);
TeleporterMessageInput memory messageInput = TeleporterMessageInput({
destinationChainID: hex"11223344556677889900aabbccddeeff11223344556677889900aabbccddeeff",
destinationChainID: expectedMessage.destinationChainID,
destinationAddress: expectedMessage.destinationAddress,
feeInfo: feeInfo,
requiredGasLimit: expectedMessage.requiredGasLimit,
allowedRelayerAddresses: expectedMessage.allowedRelayerAddresses,
message: expectedMessage.message
});

vm.mockCall(
WARP_PRECOMPILE_ADDRESS,
abi.encode(IWarpMessenger.sendWarpMessage.selector),
abi.encode(bytes32(0))
);

// Expect the exact message to be passed to the precompile.
vm.expectCall(
WARP_PRECOMPILE_ADDRESS,
abi.encodeCall(
WarpMessenger.sendWarpMessage,
(
messageInput.destinationChainID,
address(teleporterMessenger),
abi.encode(expectedMessage)
)
IWarpMessenger.sendWarpMessage,
(abi.encode(expectedMessage))
)
);

Expand All @@ -234,15 +237,12 @@ contract GetOutstandingReceiptsToSendTest is TeleporterMessengerTest {
hex"deadbeef"
);
nextExpectedMessage.receipts = expectedReceiptsBatch2;
nextExpectedMessage.destinationChainID = chainID;
vm.expectCall(
WARP_PRECOMPILE_ADDRESS,
abi.encodeCall(
WarpMessenger.sendWarpMessage,
(
messageInput.destinationChainID,
address(teleporterMessenger),
abi.encode(nextExpectedMessage)
)
IWarpMessenger.sendWarpMessage,
(abi.encode(nextExpectedMessage))
)
);
vm.expectEmit(true, true, true, true, address(teleporterMessenger));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ contract HandleInitialMessageExecutionTest is TeleporterMessengerTest {
TeleporterMessage memory messageToReceive = TeleporterMessage({
messageID: 42,
senderAddress: address(this),
destinationChainID: MOCK_BLOCK_CHAIN_ID,
sourceTeleporterAddress: address(teleporterMessenger),
destinationAddress: address(destinationContract),
requiredGasLimit: DEFAULT_REQUIRED_GAS_LIMIT,
allowedRelayerAddresses: new address[](0),
Expand Down Expand Up @@ -166,6 +168,8 @@ contract HandleInitialMessageExecutionTest is TeleporterMessengerTest {
TeleporterMessage memory messageToReceive = TeleporterMessage({
messageID: 42,
senderAddress: address(this),
destinationChainID: MOCK_BLOCK_CHAIN_ID,
sourceTeleporterAddress: address(teleporterMessenger),
destinationAddress: address(destinationContract),
requiredGasLimit: uint256(
bytes32(
Expand Down Expand Up @@ -201,6 +205,8 @@ contract HandleInitialMessageExecutionTest is TeleporterMessengerTest {
TeleporterMessage memory messageToReceive = TeleporterMessage({
messageID: 42,
senderAddress: address(this),
destinationChainID: MOCK_BLOCK_CHAIN_ID,
sourceTeleporterAddress: address(teleporterMessenger),
destinationAddress: address(destinationContract),
requiredGasLimit: DEFAULT_REQUIRED_GAS_LIMIT,
allowedRelayerAddresses: new address[](0),
Expand Down Expand Up @@ -266,6 +272,8 @@ contract HandleInitialMessageExecutionTest is TeleporterMessengerTest {
TeleporterMessage memory messageToReceive = TeleporterMessage({
messageID: 42,
senderAddress: address(this),
destinationChainID: MOCK_BLOCK_CHAIN_ID,
sourceTeleporterAddress: address(teleporterMessenger),
destinationAddress: address(destinationContract),
requiredGasLimit: DEFAULT_REQUIRED_GAS_LIMIT,
allowedRelayerAddresses: new address[](0),
Expand Down
15 changes: 3 additions & 12 deletions contracts/src/Teleporter/tests/MarkReceiptTests.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,8 @@ contract MarkReceiptTest is TeleporterMessengerTest {
new bytes(0)
);
messageToReceive.receipts = receipts;
WarpMessage memory warpMessage = WarpMessage(
WarpMessage memory warpMessage = _createDefaultWarpMessage(
DEFAULT_ORIGIN_CHAIN_ID,
address(teleporterMessenger),
MOCK_BLOCK_CHAIN_ID,
address(teleporterMessenger),
abi.encode(messageToReceive)
);

Expand Down Expand Up @@ -137,11 +134,8 @@ contract MarkReceiptTest is TeleporterMessengerTest {
new bytes(0)
);
messageToReceive.receipts = receipts;
WarpMessage memory warpMessage = WarpMessage(
WarpMessage memory warpMessage = _createDefaultWarpMessage(
DEFAULT_ORIGIN_CHAIN_ID,
address(teleporterMessenger),
MOCK_BLOCK_CHAIN_ID,
address(teleporterMessenger),
abi.encode(messageToReceive)
);

Expand Down Expand Up @@ -196,11 +190,8 @@ contract MarkReceiptTest is TeleporterMessengerTest {
new bytes(0)
);
messageToReceive.receipts = receipts;
WarpMessage memory warpMessage = WarpMessage(
WarpMessage memory warpMessage = _createDefaultWarpMessage(
DEFAULT_ORIGIN_CHAIN_ID,
address(teleporterMessenger),
MOCK_BLOCK_CHAIN_ID,
address(teleporterMessenger),
abi.encode(messageToReceive)
);

Expand Down
Loading