Skip to content

Commit

Permalink
Merge branch 'main' into noah/cli-submitter
Browse files Browse the repository at this point in the history
  • Loading branch information
nbayindirli committed May 10, 2024
2 parents c424ca3 + 89c4629 commit 5fdaf9a
Show file tree
Hide file tree
Showing 44 changed files with 1,319 additions and 72 deletions.
5 changes: 5 additions & 0 deletions .changeset/green-ads-live.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@hyperlane-xyz/cli': minor
---

Default to home directory for local registry
5 changes: 5 additions & 0 deletions .changeset/lemon-horses-swim.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@hyperlane-xyz/cli': patch
---

Improve defaults in chain config command
6 changes: 6 additions & 0 deletions .changeset/sour-bats-sort.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@hyperlane-xyz/utils': minor
'@hyperlane-xyz/sdk': minor
---

Implement aggregation and multisig ISM metadata encoding
3 changes: 0 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -346,9 +346,6 @@ jobs:
- environment: testnet4
chain: sepolia
module: core
- environment: mainnet3
chain: inevm
module: warp

steps:
- uses: actions/checkout@v3
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[submodule "solidity/lib/forge-std"]
path = solidity/lib/forge-std
url = https://github.com/foundry-rs/forge-std
[submodule "solidity/lib/fx-portal"]
path = solidity/lib/fx-portal
url = https://github.com/0xPolygon/fx-portal
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v20
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"prettier": "yarn workspaces foreach --since --parallel run prettier",
"lint": "yarn workspaces foreach --all --parallel run lint",
"test": "yarn workspaces foreach --all --parallel run test",
"test:ci": "yarn workspaces foreach --all --parallel run test:ci",
"test:ci": "yarn workspaces foreach --all --topological run test:ci",
"coverage": "yarn workspaces foreach --all --parallel run coverage",
"version:prepare": "yarn changeset version && yarn workspaces foreach --all --parallel run version:update && yarn install --no-immutable",
"version:check": "yarn changeset status",
Expand Down
1 change: 1 addition & 0 deletions solidity/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ forge-cache
docs
flattened/
buildArtifact.json
fixtures/
20 changes: 18 additions & 2 deletions solidity/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,30 @@ Hyperlane Core contains the contracts and typechain artifacts for the Hyperlane

```bash
# Install with NPM
npm install @hyperlane-xyz/utils
npm install @hyperlane-xyz/core

# Or with Yarn
yarn add @hyperlane-xyz/utils
yarn add @hyperlane-xyz/core
```

Note, this package uses [ESM Modules](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c#pure-esm-package)

## Build

```bash
yarn build
```

## Test

```bash
yarn test
```

### Fixtures

Some forge tests may generate fixtures in the [fixtures](./fixtures/) directory. This allows [SDK](../typescript/sdk) tests to leverage forge fuzzing. These are git ignored and should not be committed.

## License

Apache 2.0
83 changes: 83 additions & 0 deletions solidity/contracts/hooks/PolygonPosHook.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity >=0.8.0;

/*@@@@@@@ @@@@@@@@@
@@@@@@@@@ @@@@@@@@@
@@@@@@@@@ @@@@@@@@@
@@@@@@@@@ @@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@ HYPERLANE @@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@ @@@@@@@@@
@@@@@@@@@ @@@@@@@@@
@@@@@@@@@ @@@@@@@@@
@@@@@@@@@ @@@@@@@@*/

// ============ Internal Imports ============
import {AbstractMessageIdAuthHook} from "./libs/AbstractMessageIdAuthHook.sol";
import {StandardHookMetadata} from "./libs/StandardHookMetadata.sol";
import {TypeCasts} from "../libs/TypeCasts.sol";
import {Message} from "../libs/Message.sol";
import {IPostDispatchHook} from "../interfaces/hooks/IPostDispatchHook.sol";

// ============ External Imports ============
import {FxBaseRootTunnel} from "fx-portal/contracts/tunnel/FxBaseRootTunnel.sol";
import {Address} from "@openzeppelin/contracts/utils/Address.sol";

/**
* @title PolygonPosHook
* @notice Message hook to inform the PolygonPosIsm of messages published through
* the native PoS bridge.
*/
contract PolygonPosHook is AbstractMessageIdAuthHook, FxBaseRootTunnel {
using StandardHookMetadata for bytes;

// ============ Constructor ============

constructor(
address _mailbox,
uint32 _destinationDomain,
bytes32 _ism,
address _cpManager,
address _fxRoot
)
AbstractMessageIdAuthHook(_mailbox, _destinationDomain, _ism)
FxBaseRootTunnel(_cpManager, _fxRoot)
{
require(
Address.isContract(_cpManager),
"PolygonPosHook: invalid cpManager contract"
);
require(
Address.isContract(_fxRoot),
"PolygonPosHook: invalid fxRoot contract"
);
}

// ============ Internal functions ============
function _quoteDispatch(
bytes calldata,
bytes calldata
) internal pure override returns (uint256) {
return 0;
}

/// @inheritdoc AbstractMessageIdAuthHook
function _sendMessageId(
bytes calldata metadata,
bytes memory payload
) internal override {
require(
metadata.msgValue(0) == 0,
"PolygonPosHook: does not support msgValue"
);
require(msg.value == 0, "PolygonPosHook: does not support msgValue");
_sendMessageToChild(payload);
}

bytes public latestData;

function _processMessageFromChild(bytes memory data) internal override {
latestData = data;
}
}
58 changes: 58 additions & 0 deletions solidity/contracts/isms/hook/PolygonPosIsm.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity >=0.8.0;

/*@@@@@@@ @@@@@@@@@
@@@@@@@@@ @@@@@@@@@
@@@@@@@@@ @@@@@@@@@
@@@@@@@@@ @@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@ HYPERLANE @@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@ @@@@@@@@@
@@@@@@@@@ @@@@@@@@@
@@@@@@@@@ @@@@@@@@@
@@@@@@@@@ @@@@@@@@*/

// ============ Internal Imports ============

import {IInterchainSecurityModule} from "../../interfaces/IInterchainSecurityModule.sol";
import {Message} from "../../libs/Message.sol";
import {TypeCasts} from "../../libs/TypeCasts.sol";
import {AbstractMessageIdAuthorizedIsm} from "./AbstractMessageIdAuthorizedIsm.sol";

// ============ External Imports ============
import {CrossChainEnabledPolygonChild} from "@openzeppelin/contracts/crosschain/polygon/CrossChainEnabledPolygonChild.sol";
import {Address} from "@openzeppelin/contracts/utils/Address.sol";

/**
* @title PolygonPosIsm
* @notice Uses the native Polygon Pos Fx Portal Bridge to verify interchain messages.
*/
contract PolygonPosIsm is
CrossChainEnabledPolygonChild,
AbstractMessageIdAuthorizedIsm
{
// ============ Constants ============

uint8 public constant moduleType =
uint8(IInterchainSecurityModule.Types.NULL);

// ============ Constructor ============

constructor(address _fxChild) CrossChainEnabledPolygonChild(_fxChild) {
require(
Address.isContract(_fxChild),
"PolygonPosIsm: invalid FxChild contract"
);
}

// ============ Internal function ============

/**
* @notice Check if sender is authorized to message `verifyMessageId`.
*/
function _isAuthorized() internal view override returns (bool) {
return
_crossChainSender() == TypeCasts.bytes32ToAddress(authorizedHook);
}
}
10 changes: 7 additions & 3 deletions solidity/foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,20 @@ solc_version = '0.8.22'
evm_version= 'paris'
optimizer = true
optimizer_runs = 999_999
fs_permissions = [{ access = "read-write", path = "./"}]
fs_permissions = [
{ access = "read", path = "./script/avs/"},
{ access = "write", path = "./fixtures" }
]
ignored_warnings_from = ['fx-portal']

[profile.ci]
verbosity = 4

[rpc_endpoints]
mainnet = "https://eth.merkle.io"
optimism = "https://mainnet.optimism.io "

polygon = "https://rpc.ankr.com/polygon"

[fuzz]
runs = 50
dictionary_weight = 80
dictionary_weight = 80
7 changes: 7 additions & 0 deletions solidity/hardhat.config.cts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import '@nomiclabs/hardhat-ethers';
import '@nomiclabs/hardhat-waffle';
import '@typechain/hardhat';
import 'hardhat-gas-reporter';
import 'hardhat-ignore-warnings';
import 'solidity-coverage';

/**
Expand Down Expand Up @@ -30,4 +31,10 @@ module.exports = {
bail: true,
import: 'tsx',
},
warnings: {
// turn off all warnings for libs:
'fx-portal/**/*': {
default: 'off',
},
},
};
1 change: 1 addition & 0 deletions solidity/lib/fx-portal
Submodule fx-portal added at ebd046
8 changes: 5 additions & 3 deletions solidity/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"@hyperlane-xyz/utils": "3.11.1",
"@layerzerolabs/lz-evm-oapp-v2": "2.0.2",
"@openzeppelin/contracts": "^4.9.3",
"@openzeppelin/contracts-upgradeable": "^v4.9.3"
"@openzeppelin/contracts-upgradeable": "^v4.9.3",
"fx-portal": "^1.0.3"
},
"devDependencies": {
"@layerzerolabs/solidity-examples": "^1.1.0",
Expand All @@ -20,6 +21,7 @@
"ethers": "^5.7.2",
"hardhat": "^2.22.2",
"hardhat-gas-reporter": "^1.0.9",
"hardhat-ignore-warnings": "^0.2.11",
"prettier": "^2.8.8",
"prettier-plugin-solidity": "^1.1.3",
"solhint": "^4.5.4",
Expand Down Expand Up @@ -59,14 +61,14 @@
"scripts": {
"build": "yarn hardhat-esm compile && tsc && ./exportBuildArtifact.sh",
"lint": "solhint contracts/**/*.sol",
"clean": "yarn hardhat-esm clean && rm -rf ./dist ./cache ./types ./coverage ./out ./forge-cache",
"clean": "yarn hardhat-esm clean && rm -rf ./dist ./cache ./types ./coverage ./out ./forge-cache ./fixtures",
"coverage": "./coverage.sh",
"docs": "forge doc",
"hardhat-esm": "NODE_OPTIONS='--experimental-loader ts-node/esm/transpile-only --no-warnings=ExperimentalWarning' hardhat --config hardhat.config.cts",
"prettier": "prettier --write ./contracts ./test",
"test": "yarn hardhat-esm test && yarn test:forge",
"test:hardhat": "yarn hardhat-esm test",
"test:forge": "forge test -vvv",
"test:forge": "mkdir -p ./fixtures/aggregation ./fixtures/multisig && forge test -vvv",
"test:ci": "yarn test:hardhat && yarn test:forge --no-match-test testFork",
"gas": "forge snapshot",
"gas-ci": "yarn gas --check --tolerance 2 || (echo 'Manually update gas snapshot' && exit 1)",
Expand Down
1 change: 1 addition & 0 deletions solidity/remappings.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
@eth-optimism=../node_modules/@eth-optimism
ds-test/=lib/forge-std/lib/ds-test/src/
forge-std/=lib/forge-std/src/
fx-portal/=lib/fx-portal/
Loading

0 comments on commit 5fdaf9a

Please sign in to comment.