Skip to content

Commit

Permalink
Merge pull request #397 from ava-labs/upgradeable-poc-merge
Browse files Browse the repository at this point in the history
Upgradeability for TeleporterUpgradeable and TeleporterOwnerUpgradeable
  • Loading branch information
minghinmatthewlam authored Jul 25, 2024
2 parents c6c6117 + 9ce49e8 commit 556103f
Show file tree
Hide file tree
Showing 64 changed files with 526 additions and 347 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/abi_bindings_checker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
go-version-file: "go.mod"

- name: Install Foundry
run: ./scripts/install_foundry.sh
Expand Down
7 changes: 4 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
branch = v1.3.0
[submodule "contracts/lib/openzeppelin-contracts"]
path = contracts/lib/openzeppelin-contracts
url = https://github.com/openzeppelin/openzeppelin-contracts
[submodule "lib/openzeppelin-contracts"]
branch = v4.8.1
url = https://github.com/OpenZeppelin/openzeppelin-contracts
[submodule "contracts/lib/subnet-evm"]
path = contracts/lib/subnet-evm
url = https://github.com/ava-labs/subnet-evm
[submodule "contracts/lib/openzeppelin-contracts-upgradeable"]
path = contracts/lib/openzeppelin-contracts-upgradeable
url = https://github.com/OpenZeppelin/openzeppelin-contracts-upgradeable
9 changes: 4 additions & 5 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@
run:
timeout: 3m
tests: true
# skip auto-generated files.
skip-dirs:
- "abi-bindings/go"
skip-files:
- ".*mock.*"

issues:
# Maximum count of issues with the same text. Set to 0 to disable. Default is 3.
max-same-issues: 0
exclude-dirs:
- "abi-bindings/go"
exclude-files:
- ".*mock.*"

linters:
disable-all: true
Expand Down
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Setup

To start developing on Teleporter, you'll need Solidity >= v0.8.18. [Foundry](https://book.getfoundry.sh/getting-started/installation) is the recommended development toolkit for working with Teleporter, and it comes bundled with the required Solidity version. To run the tests and linter locally, you'll need the dependencies described in [Setup](./README.md#setup), as well as [npm](https://docs.npmjs.com/downloading-and-installing-node-js-and-npm)
To start developing on Teleporter, you'll need Solidity >= v0.8.23. [Foundry](https://book.getfoundry.sh/getting-started/installation) is the recommended development toolkit for working with Teleporter, and it comes bundled with the required Solidity version. To run the tests and linter locally, you'll need the dependencies described in [Setup](./README.md#setup), as well as [npm](https://docs.npmjs.com/downloading-and-installing-node-js-and-npm)

## Issues

Expand All @@ -13,7 +13,7 @@ To start developing on Teleporter, you'll need Solidity >= v0.8.18. [Foundry](ht
### Making an Issue

- Check that the issue you're filing doesn't already exist by searching under [issues](https://github.com/ava-labs/teleporter/issues).
- If you're unable to find an open issue addressing the problem, [open a new one](https://github.com/ava-labs/teleporter/issues/new/choose). Be sure to include a *title and clear description* with as much relevant information as possible.
- If you're unable to find an open issue addressing the problem, [open a new one](https://github.com/ava-labs/teleporter/issues/new/choose). Be sure to include a _title and clear description_ with as much relevant information as possible.

## Features

Expand Down
4 changes: 2 additions & 2 deletions abi-bindings/go/governance/ValidatorSetSig/ValidatorSetSig.go

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion abi-bindings/go/governance/ValidatorSetSig/packing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,4 @@ func TestPackUnpackValidatorSetSigMessage(t *testing.T) {
require.NoError(t, err)

require.Equal(t, msg, unpackedMsg)

}
136 changes: 47 additions & 89 deletions abi-bindings/go/mocks/ExampleERC20/ExampleERC20.go

Large diffs are not rendered by default.

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion abi-bindings/go/teleporter/TeleporterMessenger/packing.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ func PackRetryMessageExecution(sourceBlockchainID ids.ID, message TeleporterMess
return abi.Pack("retryMessageExecution", sourceBlockchainID, message)
}

// PackReceiveCrossChainMessage packs a ReceiveCrossChainMessageInput to form a call to the receiveCrossChainMessage function
// PackReceiveCrossChainMessage packs a ReceiveCrossChainMessageInput to form
// a call to the receiveCrossChainMessage function
func PackReceiveCrossChainMessage(messageIndex uint32, relayerRewardAddress common.Address) ([]byte, error) {
abi, err := TeleporterMessengerMetaData.GetAbi()
if err != nil {
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ func UnpackTeleporterRegistryWarpPayload(entryBytes []byte) (ProtocolRegistryEnt
unpacked, err := args.Unpack(entryBytes)
fmt.Println("unpacked: ", unpacked)
if err != nil {
return ProtocolRegistryEntry{}, common.Address{}, fmt.Errorf("failed to unpack to Teleporter registry entry with err: %v", err)
return ProtocolRegistryEntry{}, common.Address{},
fmt.Errorf("failed to unpack to Teleporter registry entry with err: %v", err)
}
type teleporterRegistryWarpPayload struct {
ProtocolRegistryEntry ProtocolRegistryEntry `json:"protocolRegistryEntry"`
Expand Down
169 changes: 136 additions & 33 deletions abi-bindings/go/teleporter/tests/TestMessenger/TestMessenger.go

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion contracts/foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
src = 'src'
out = 'out'
libs = ['lib']
solc_version = '0.8.18'
solc_version = '0.8.23'
test = 'tests'
bytecode_hash = "none"

[fmt]
line_length = 100
Expand Down
2 changes: 1 addition & 1 deletion contracts/lib/openzeppelin-contracts
1 change: 1 addition & 0 deletions contracts/lib/openzeppelin-contracts-upgradeable
3 changes: 2 additions & 1 deletion contracts/remappings.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
@avalabs/[email protected]/=lib/subnet-evm/contracts/
@openzeppelin/[email protected]=lib/openzeppelin-contracts/contracts/
@openzeppelin/[email protected]=lib/openzeppelin-contracts/contracts/
@openzeppelin/[email protected]=lib/openzeppelin-contracts-upgradeable/contracts/
@teleporter/=src/teleporter/
@mocks/=src/mocks/
@utilities/=src/utilities/
72 changes: 33 additions & 39 deletions contracts/src/.solhint.json
Original file line number Diff line number Diff line change
@@ -1,41 +1,35 @@
{
"extends": "solhint:recommended",
"rules": {
"compiler-version": [
"error",
"0.8.18"
],
"no-unused-vars": "error",
"func-visibility": [
"error",
{
"ignoreConstructors": true
}
],
"private-vars-leading-underscore": [
"warn",
{
"strict": true
}
],
"reason-string": [
"warn",
{
"maxLength": 75
}
],
"gas-custom-errors": "off",
"ordering": "error",
"immutable-vars-naming": [
"warn",
{
"immutablesAsConstants": false
}
],
"func-named-parameters": [
"error",
5
],
"one-contract-per-file": "off"
}
"extends": "solhint:recommended",
"rules": {
"compiler-version": ["error", "0.8.23"],
"no-unused-vars": "error",
"func-visibility": [
"error",
{
"ignoreConstructors": true
}
],
"private-vars-leading-underscore": [
"warn",
{
"strict": true
}
],
"reason-string": [
"warn",
{
"maxLength": 75
}
],
"gas-custom-errors": "off",
"ordering": "error",
"immutable-vars-naming": [
"warn",
{
"immutablesAsConstants": false
}
],
"func-named-parameters": ["error", 5],
"one-contract-per-file": "off"
}
}
4 changes: 2 additions & 2 deletions contracts/src/governance/ValidatorSetSig.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@

// SPDX-License-Identifier: Ecosystem

pragma solidity 0.8.18;
pragma solidity 0.8.23;

import {
WarpMessage,
IWarpMessenger
} from "@avalabs/[email protected]/contracts/interfaces/IWarpMessenger.sol";
import {ReentrancyGuard} from "@openzeppelin/contracts@4.8.1/security/ReentrancyGuard.sol";
import {ReentrancyGuard} from "@openzeppelin/contracts@5.0.2/utils/ReentrancyGuard.sol";

/**
* THIS IS AN EXAMPLE CONTRACT THAT USES UN-AUDITED CODE.
Expand Down
2 changes: 1 addition & 1 deletion contracts/src/governance/tests/ValidatorSetSigTests.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

// SPDX-License-Identifier: Ecosystem

pragma solidity 0.8.18;
pragma solidity 0.8.23;

import {Test} from "forge-std/Test.sol";
import {
Expand Down
5 changes: 2 additions & 3 deletions contracts/src/mocks/ExampleERC20.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,16 @@

// SPDX-License-Identifier: Ecosystem

pragma solidity 0.8.18;
pragma solidity 0.8.23;

/**
* THIS IS AN EXAMPLE CONTRACT THAT USES UN-AUDITED CODE.
* DO NOT USE THIS CODE IN PRODUCTION.
*/

import {
ERC20Burnable,
ERC20
} from "@openzeppelin/contracts@4.8.1/token/ERC20/extensions/ERC20Burnable.sol";
} from "@openzeppelin/contracts@5.0.2/token/ERC20/extensions/ERC20Burnable.sol";

contract ExampleERC20 is ERC20Burnable {
string private constant _TOKEN_NAME = "Mock Token";
Expand Down
2 changes: 1 addition & 1 deletion contracts/src/mocks/UnitTestMockERC20.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

// SPDX-License-Identifier: Ecosystem

pragma solidity 0.8.18;
pragma solidity 0.8.23;

/**
* THIS IS AN EXAMPLE CONTRACT THAT USES UN-AUDITED CODE.
Expand Down
2 changes: 1 addition & 1 deletion contracts/src/teleporter/ITeleporterMessenger.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

// SPDX-License-Identifier: Ecosystem

pragma solidity 0.8.18;
pragma solidity 0.8.23;

// A message receipt identifies the message that was delivered by its nonce,
// and the address that can redeem the reward for that message.
Expand Down
2 changes: 1 addition & 1 deletion contracts/src/teleporter/ITeleporterReceiver.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

// SPDX-License-Identifier: Ecosystem

pragma solidity 0.8.18;
pragma solidity 0.8.23;

/**
* @dev Interface that cross-chain applications must implement to receive messages from Teleporter.
Expand Down
4 changes: 2 additions & 2 deletions contracts/src/teleporter/ReceiptQueue.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

// SPDX-License-Identifier: Ecosystem

pragma solidity 0.8.18;
pragma solidity 0.8.23;

import {Math} from "@openzeppelin/contracts@4.8.1/utils/math/Math.sol";
import {Math} from "@openzeppelin/contracts@5.0.2/utils/math/Math.sol";
import {TeleporterMessageReceipt} from "./ITeleporterMessenger.sol";

/**
Expand Down
11 changes: 5 additions & 6 deletions contracts/src/teleporter/TeleporterMessenger.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@

// SPDX-License-Identifier: Ecosystem

pragma solidity 0.8.18;
pragma solidity 0.8.23;

import {IERC20} from "@openzeppelin/contracts@4.8.1/token/ERC20/IERC20.sol";
import {SafeERC20} from "@openzeppelin/contracts@4.8.1/token/ERC20/utils/SafeERC20.sol";
import {IERC20} from "@openzeppelin/contracts@5.0.2/token/ERC20/IERC20.sol";
import {SafeERC20} from "@openzeppelin/contracts@5.0.2/token/ERC20/utils/SafeERC20.sol";
import {
WarpMessage,
IWarpMessenger
Expand Down Expand Up @@ -424,9 +424,8 @@ contract TeleporterMessenger is ITeleporterMessenger, ReentrancyGuards {
bytes32 blockchainID_ = blockchainID;

// Iterate through the specified message IDs and create teleporter receipts to send back.
TeleporterMessageReceipt[] memory receiptsToSend = new TeleporterMessageReceipt[](
messageIDs.length
);
TeleporterMessageReceipt[] memory receiptsToSend =
new TeleporterMessageReceipt[](messageIDs.length);
uint256 length = messageIDs.length;
for (uint256 i; i < length; ++i) {
bytes32 receivedMessageID = messageIDs[i];
Expand Down
18 changes: 12 additions & 6 deletions contracts/src/teleporter/registry/TeleporterOwnerUpgradeable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,31 @@

// SPDX-License-Identifier: Ecosystem

pragma solidity 0.8.18;
pragma solidity 0.8.23;

import {TeleporterUpgradeable} from "./TeleporterUpgradeable.sol";
import {Ownable} from "@openzeppelin/[email protected]/access/Ownable.sol";
import {OwnableUpgradeable} from
"@openzeppelin/[email protected]/access/OwnableUpgradeable.sol";

/**
* @dev Contract that inherits {TeleporterUpgradeable} and allows
* only owners of the contract to update the minimum Teleporter version.
*
* @custom:security-contact https://github.com/ava-labs/teleporter/blob/main/SECURITY.md
*/
abstract contract TeleporterOwnerUpgradeable is TeleporterUpgradeable, Ownable {
constructor(
abstract contract TeleporterOwnerUpgradeable is TeleporterUpgradeable, OwnableUpgradeable {
// solhint-disable-next-line func-name-mixedcase
function __TeleporterOwnerUpgradeable_init(
address teleporterRegistryAddress,
address initialOwner
) TeleporterUpgradeable(teleporterRegistryAddress) {
transferOwnership(initialOwner);
) internal onlyInitializing {
__TeleporterUpgradeable_init(teleporterRegistryAddress);
__Ownable_init(initialOwner);
}

// solhint-disable-next-line func-name-mixedcase, no-empty-blocks, func-name-mixedcase
function _TeleporterOwnerUpgradeable_init_unchained() internal onlyInitializing {}

/**
* @dev See {TeleporterUpgradeable-_checkTeleporterUpgradeAccess}
*
Expand Down
2 changes: 1 addition & 1 deletion contracts/src/teleporter/registry/TeleporterRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

// SPDX-License-Identifier: Ecosystem

pragma solidity 0.8.18;
pragma solidity 0.8.23;

import {ITeleporterMessenger} from "@teleporter/ITeleporterMessenger.sol";
import {
Expand Down
Loading

0 comments on commit 556103f

Please sign in to comment.