Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin' into dan/tokio-instrumentation
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-savu committed May 10, 2024
2 parents 03c6c9f + 69de68a commit 3675446
Show file tree
Hide file tree
Showing 33 changed files with 713 additions and 56 deletions.
2 changes: 1 addition & 1 deletion .changeset/green-ads-live.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
"@hyperlane-xyz/cli": minor
'@hyperlane-xyz/cli': minor
---

Default to home directory for local registry
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
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
6 changes: 5 additions & 1 deletion solidity/foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ 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
Expand Down
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',
},
},
};
5 changes: 3 additions & 2 deletions solidity/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,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 @@ -60,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
50 changes: 39 additions & 11 deletions solidity/test/isms/AggregationIsm.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,44 @@ pragma solidity ^0.8.13;

import "forge-std/Test.sol";

import "@openzeppelin/contracts/utils/Strings.sol";

import {IAggregationIsm} from "../../contracts/interfaces/isms/IAggregationIsm.sol";
import {StaticAggregationIsmFactory} from "../../contracts/isms/aggregation/StaticAggregationIsmFactory.sol";
import {AggregationIsmMetadata} from "../../contracts/isms/libs/AggregationIsmMetadata.sol";
import {TestIsm, ThresholdTestUtils} from "./IsmTestUtils.sol";

contract AggregationIsmTest is Test {
using Strings for uint256;
using Strings for uint8;

string constant fixtureKey = "fixture";

StaticAggregationIsmFactory factory;
IAggregationIsm ism;

function setUp() public {
factory = new StaticAggregationIsmFactory();
}

function fixtureAppendMetadata(
uint256 index,
bytes memory metadata
) internal {
vm.serializeBytes(fixtureKey, index.toString(), metadata);
}

function fixtureAppendNull(uint256 index) internal {
vm.serializeString(fixtureKey, index.toString(), "null");
}

function writeFixture(bytes memory metadata, uint8 m) internal {
string memory path = string(
abi.encodePacked("./fixtures/aggregation/", m.toString(), ".json")
);
vm.writeJson(vm.serializeBytes(fixtureKey, "encoded", metadata), path);
}

function deployIsms(
uint8 m,
uint8 n,
Expand All @@ -32,34 +57,37 @@ contract AggregationIsmTest is Test {
return isms;
}

function getMetadata(
uint8 m,
bytes32 seed
) private view returns (bytes memory) {
function getMetadata(uint8 m, bytes32 seed) private returns (bytes memory) {
(address[] memory choices, ) = ism.modulesAndThreshold("");
address[] memory chosen = ThresholdTestUtils.choose(m, choices, seed);
bytes memory offsets;
uint32 start = 8 * uint32(choices.length);
bytes memory metametadata;

for (uint256 i = 0; i < choices.length; i++) {
bool included = false;
for (uint256 j = 0; j < chosen.length; j++) {
included = included || choices[i] == chosen[j];
}
if (included) {
bytes memory requiredMetadata = TestIsm(choices[i])
.requiredMetadata();
uint32 end = start + uint32(requiredMetadata.length);
bytes memory metadata = TestIsm(choices[i]).requiredMetadata();
uint32 end = start + uint32(metadata.length);
uint64 offset = (uint64(start) << 32) | uint64(end);
offsets = bytes.concat(offsets, abi.encodePacked(offset));
start = end;
metametadata = abi.encodePacked(metametadata, requiredMetadata);
metametadata = abi.encodePacked(metametadata, metadata);
fixtureAppendMetadata(i, metadata);
} else {
uint64 offset = 0;
offsets = bytes.concat(offsets, abi.encodePacked(offset));
offsets = bytes.concat(offsets, abi.encodePacked(uint64(0)));
fixtureAppendNull(i);
}
}
return abi.encodePacked(offsets, metametadata);

bytes memory encoded = abi.encodePacked(offsets, metametadata);

writeFixture(encoded, m);

return encoded;
}

function testVerify(uint8 m, uint8 n, bytes32 seed) public {
Expand Down
Loading

0 comments on commit 3675446

Please sign in to comment.