Skip to content

Commit

Permalink
Merge pull request #62 from 0xPolygon/dev/foundry
Browse files Browse the repository at this point in the history
Merge Foundry migration to main
  • Loading branch information
QEDK authored Jun 26, 2023
2 parents f6184e2 + 0fb2e12 commit 494ff62
Show file tree
Hide file tree
Showing 99 changed files with 17,640 additions and 31,481 deletions.
76 changes: 59 additions & 17 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,42 +4,84 @@ on:
push:
branches: [main]
pull_request:
branches: [main]
branches: [main, dev/foundry]
workflow_dispatch:

jobs:
tests:
forge-tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
submodules: recursive
- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly
- name: Build
run: forge build
- name: Run tests
run: forge test -vvv
hardhat-tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
submodules: recursive
- name: Get node.js
uses: actions/setup-node@v3
with:
node-version: "18.x"
cache: "npm"
- run: npm ci
- run: npx hardhat compile --show-stack-traces
- run: npx hardhat test --parallel
lint:
node-version: "16.x"
cache: "yarn"
- name: Setup
run: yarn
- name: Build
run: yarn build
- name: Run tests
run: yarn test
coverage:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
submodules: recursive
- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly
- name: Build
run: forge build
- name: Get node.js
uses: actions/setup-node@v3
with:
node-version: "18.x"
cache: "npm"
- run: npm ci
- run: npx solhint "contracts/**/*.sol"
- run: npx prettier -c .
slither:
node-version: "16.x"
cache: "yarn"
- name: Setup
run: yarn && sudo apt-get install lcov
- name: Get coverage
run: yarn coverage
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Get node.js
uses: actions/setup-node@v3
with:
node-version: "18.x"
cache: "npm"
- run: rm foundry.toml # force hardhat https://github.com/foundry-rs/foundry/issues/3827
- uses: crytic/[email protected]
cache: "yarn"
- run: yarn
- run: yarn lint
slither:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
submodules: recursive
- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly
- name: Build
run: forge build
- name: Slither
uses: crytic/[email protected]
14 changes: 14 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ lib-cov
# Coverage directory used by tools like istanbul
coverage
*.lcov
*lcov.info
coverage.json

# nyc test coverage
.nyc_output
Expand Down Expand Up @@ -110,3 +112,15 @@ node_modules
cache
artifacts
internal

# Foundry files
forge-cache/
out/
# Ignores development broadcast logs
!/broadcast
/broadcast/*
/broadcast/*/31337/

lcov.info

types/
7 changes: 7 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[submodule "lib/forge-std"]
path = lib/forge-std
url = https://github.com/foundry-rs/forge-std
[submodule "lib/openzeppelin-contracts"]
path = lib/openzeppelin-contracts
url = https://github.com/openzeppelin/openzeppelin-contracts
branch = v4.8.3
3 changes: 1 addition & 2 deletions .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
"tabWidth": 4,
"useTabs": false,
"singleQuote": false,
"bracketSpacing": false,
"explicitTypes": "always"
"bracketSpacing": false
}
}
]
Expand Down
22 changes: 20 additions & 2 deletions .solhint.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,25 @@
{
"extends": "solhint:recommended",
"rules": {
"compiler-version": ["error", "^0.8.0"],
"func-visibility": ["warn", { "ignoreConstructors": true }]
"compiler-version": [
"error",
"^0.8.0"
],
"func-visibility": [
"warn",
{
"ignoreConstructors": true
}
],
"no-console": "off",
"no-global-import": "off",
"reason-string": [
"warn",
{
"maxLength": 64
}
],
"func-name-mixedcase": "off",
"no-inline-assembly": "off"
}
}
1 change: 1 addition & 0 deletions .solhintignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules
lib
6 changes: 1 addition & 5 deletions contracts/FxChild.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@ interface IStateReceiver {

// IFxMessageProcessor represents interface to process message
interface IFxMessageProcessor {
function processMessageFromRoot(
uint256 stateId,
address rootMessageSender,
bytes calldata data
) external;
function processMessageFromRoot(uint256 stateId, address rootMessageSender, bytes calldata data) external;
}

/**
Expand Down
1 change: 1 addition & 0 deletions contracts/FxRoot.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ contract FxRoot is IFxStateSender {
fxChild = _fxChild;
}

// @custom:security non-reentrant
function sendMessageToChild(address _receiver, bytes calldata _data) public override {
bytes memory data = abi.encode(msg.sender, _receiver, _data);
stateSender.syncState(fxChild, data);
Expand Down
26 changes: 5 additions & 21 deletions contracts/examples/erc1155-transfer/FxERC1155ChildTunnel.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,11 @@ contract FxERC1155ChildTunnel is FxBaseChildTunnel, Create2, ERC1155Holder {
require(_isContract(_tokenTemplate), "Token template is not contract");
}

function withdraw(
address childToken,
uint256 id,
uint256 amount,
bytes memory data
) public {
function withdraw(address childToken, uint256 id, uint256 amount, bytes memory data) public {
_withdraw(childToken, msg.sender, id, amount, data);
}

function withdrawTo(
address childToken,
address receiver,
uint256 id,
uint256 amount,
bytes memory data
) public {
function withdrawTo(address childToken, address receiver, uint256 id, uint256 amount, bytes memory data) public {
_withdraw(childToken, receiver, id, amount, data);
}

Expand All @@ -63,7 +52,7 @@ contract FxERC1155ChildTunnel is FxBaseChildTunnel, Create2, ERC1155Holder {
}

function _processMessageFromRoot(
uint256, /* stateId */
uint256 /* stateId */,
address sender,
bytes memory data
) internal override validateSender(sender) {
Expand All @@ -88,6 +77,7 @@ contract FxERC1155ChildTunnel is FxBaseChildTunnel, Create2, ERC1155Holder {

bytes32 salt = keccak256(abi.encodePacked(rootToken));
childToken = createClone(salt, tokenTemplate);
// slither-disable-next-line reentrancy-no-eth,reentrancy-events
IFxERC1155(childToken).initialize(address(this), rootToken, string(abi.encodePacked(uri)));

rootToChildToken[rootToken] = childToken;
Expand Down Expand Up @@ -122,13 +112,7 @@ contract FxERC1155ChildTunnel is FxBaseChildTunnel, Create2, ERC1155Holder {
childTokenContract.mintBatch(user, ids, amounts, data);
}

function _withdraw(
address childToken,
address receiver,
uint256 id,
uint256 amount,
bytes memory data
) internal {
function _withdraw(address childToken, address receiver, uint256 id, uint256 amount, bytes memory data) internal {
IFxERC1155 childTokenContract = IFxERC1155(childToken);
address rootToken = childTokenContract.connectedToken();

Expand Down
10 changes: 3 additions & 7 deletions contracts/examples/erc1155-transfer/FxERC1155RootTunnel.sol
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ contract FxERC1155RootTunnel is FxBaseRootTunnel, Create2, ERC1155Holder {
mapping(address => address) public rootToChildTokens;
bytes32 public immutable childTokenTemplateCodeHash;

// slither-disable-next-line missing-zero-check
constructor(
address _checkpointManager,
address _fxRoot,
Expand All @@ -61,6 +62,7 @@ contract FxERC1155RootTunnel is FxBaseRootTunnel, Create2, ERC1155Holder {

// MAP_TOKEN, encode(rootToken,uri)
bytes memory message = abi.encode(MAP_TOKEN, abi.encode(rootToken, uri));
// slither-disable-next-line reentrancy-no-eth
_sendMessageToChild(message);

// compute child token address before deployment using create2
Expand All @@ -72,13 +74,7 @@ contract FxERC1155RootTunnel is FxBaseRootTunnel, Create2, ERC1155Holder {
emit TokenMappedERC1155(rootToken, childToken);
}

function deposit(
address rootToken,
address user,
uint256 id,
uint256 amount,
bytes memory data
) public {
function deposit(address rootToken, address user, uint256 id, uint256 amount, bytes memory data) public {
// map token if not mapped
if (rootToChildTokens[rootToken] == address(0x0)) {
mapToken(rootToken);
Expand Down
16 changes: 5 additions & 11 deletions contracts/examples/erc20-transfer/FxERC20ChildTunnel.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ contract FxERC20ChildTunnel is FxBaseChildTunnel, Create2 {
// token template
address public immutable tokenTemplate;

// slither-disable-next-line missing-zero-check
constructor(address _fxChild, address _tokenTemplate) FxBaseChildTunnel(_fxChild) {
tokenTemplate = _tokenTemplate;
require(_isContract(_tokenTemplate), "Token template is not contract");
Expand All @@ -30,11 +31,7 @@ contract FxERC20ChildTunnel is FxBaseChildTunnel, Create2 {
_withdraw(childToken, msg.sender, amount);
}

function withdrawTo(
address childToken,
address receiver,
uint256 amount
) public {
function withdrawTo(address childToken, address receiver, uint256 amount) public {
_withdraw(childToken, receiver, amount);
}

Expand All @@ -43,7 +40,7 @@ contract FxERC20ChildTunnel is FxBaseChildTunnel, Create2 {
//

function _processMessageFromRoot(
uint256, /* stateId */
uint256 /* stateId */,
address sender,
bytes memory data
) internal override validateSender(sender) {
Expand Down Expand Up @@ -74,6 +71,7 @@ contract FxERC20ChildTunnel is FxBaseChildTunnel, Create2 {
// deploy new child token
bytes32 salt = keccak256(abi.encodePacked(rootToken));
childToken = createClone(salt, tokenTemplate);
// slither-disable-next-line reentrancy-no-eth
IFxERC20(childToken).initialize(
address(this),
rootToken,
Expand Down Expand Up @@ -121,11 +119,7 @@ contract FxERC20ChildTunnel is FxBaseChildTunnel, Create2 {
}
}

function _withdraw(
address childToken,
address receiver,
uint256 amount
) internal {
function _withdraw(address childToken, address receiver, uint256 amount) internal {
IFxERC20 childTokenContract = IFxERC20(childToken);
// child token contract will have root token
address rootToken = childTokenContract.connectedToken();
Expand Down
8 changes: 2 additions & 6 deletions contracts/examples/erc20-transfer/FxERC20RootTunnel.sol
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ contract FxERC20RootTunnel is FxBaseRootTunnel, Create2 {

// MAP_TOKEN, encode(rootToken, name, symbol, decimals)
bytes memory message = abi.encode(MAP_TOKEN, abi.encode(rootToken, name, symbol, decimals));
// slither-disable-next-line reentrancy-no-eth
_sendMessageToChild(message);

// compute child token address before deployment using create2
Expand All @@ -68,12 +69,7 @@ contract FxERC20RootTunnel is FxBaseRootTunnel, Create2 {
emit TokenMappedERC20(rootToken, childToken);
}

function deposit(
address rootToken,
address user,
uint256 amount,
bytes memory data
) public {
function deposit(address rootToken, address user, uint256 amount, bytes memory data) public {
// map token if not mapped
if (rootToChildTokens[rootToken] == address(0x0)) {
mapToken(rootToken);
Expand Down
Loading

0 comments on commit 494ff62

Please sign in to comment.