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

Push the latest contracts #516

Merged
merged 27 commits into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
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
44 changes: 44 additions & 0 deletions .github/workflows/contracts-deployment-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Contracts Deployment Test

on:
push:
branches:
- main
- dev
pull_request:

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: '18' # Adjust this as needed for your project

- name: Install dependencies
run: cd contracts && npm install

- name: Install Foundry
run: |
cd contracts
curl -L https://foundry.paradigm.xyz | bash
export PATH="$PATH:/home/runner/.config/.foundry/bin"
foundryup
forge install
- name: Generate Ethereum Private Key and Create .env File and run make
run: |
cd contracts
PRIVATE_KEY=$(node -e "console.log(require('crypto').randomBytes(32).toString('hex'))")
echo "export PRIVATE_KEY=0x$PRIVATE_KEY" > .env
echo "export RPC_URL=http://127.0.0.1:1337" >> .env
echo "export CHAIN_ID=1337" >> .env
export PATH="$PATH:/home/runner/.config/.foundry/bin"
npx ganache-cli -g0 -p1337 --account 0x$PRIVATE_KEY,1001901919191919191 &
sleep 5
make deploy-ipc
2 changes: 1 addition & 1 deletion .github/workflows/contracts-npm-audit.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: NPM Audit
name: Contracts NPM Audit

# This workflow is triggered from the main CI workflow.
on:
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/contracts-prettier.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# .github/workflows/prettier.yml

name: Prettier
name: Contracts Prettier

# This workflow is triggered from the main CI workflow.
on:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/contracts-sast.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Static analysis
name: Contracts Static analysis

# This workflow is triggered from the main CI workflow.
on:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/contracts-storage.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Storage check
name: Contracts Storage check

# This workflow is triggered from the main CI workflow.
on:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/contracts-test.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Tests
name: Contracts Tests

# This workflow is triggered from the main CI workflow.
on:
Expand Down
7 changes: 6 additions & 1 deletion contracts/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ OUTPUT ?= out
deploy-ipc:
./ops/deploy.sh $(NETWORK)

deploy-subnet-registry:
./ops/deploy-subnet-registry.sh $(NETWORK)

deploy-subnet:
./ops/deploy-subnet.sh $(NETWORK)

upgrade-gw-diamond:
./ops/upgrade-gw-diamond.sh $(NETWORK)

Expand Down Expand Up @@ -106,7 +112,6 @@ coverage-for-mac: | forge

prepare: build-selector-library fmt lint test slither


build-selector-library: | forge
python scripts/python/build_selector_library.py
npx prettier -w test/helpers/SelectorLibrary.sol
Expand Down
42 changes: 42 additions & 0 deletions contracts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,48 @@ To deploy the contracts in some other network configured in the Hardhat config y
make deploy-ipc NETWORK=<network-name>
```

# Upgrading IPC Solidity Contracts

This repository's contracts use the Diamond pattern for upgradability, allowing new features to be added or issues to be corrected without a full redeployment. The upgrade process is automated and includes bytecode verification to ensure the integrity of the changes.

## Automated Upgrade and Bytecode Verification

When you run an upgrade command, the repository's scripts handle several tasks:

1. **Bytecode Verification**: The scripts fetch the bytecode of the currently deployed contracts on an FEVM-powered IPC network using the details stored in local JSON files in the root directory of the git repository. They compare this with the bytecode generated after applying the intended changes on a temporary Ganache network.

2. **Conditional Upgrades**: If the bytecode verification process detects changes that align with the intended upgrades, the `make` command conditionally triggers other scripts to perform the actual upgrade on the network.

## Upgrade Commands

To upgrade a contract, you may use the following commands. The NETWORK parameter is optional; if not specified, the scripts will default to "auto":

- **Gateway Diamond Upgrade**:

```bash
make upgrade-gw-diamond [NETWORK=<network-name>]
```

- **Subnet Actor Diamond Upgrade**:

```bash
make upgrade-sa-diamond [NETWORK=<network-name>]
```

- **Subnet Registry Diamond Upgrade**:
```bash
make upgrade-sr-diamond [NETWORK=<network-name>]
```

After running any of these commands, the scripts will provide transaction details for verification. Check the transaction on the appropriate block explorer to confirm the upgrade's success.

## Important Notes

- The upgrade commands are intended for use by authorized personnel with a deep understanding of the contracts' functionality.
- Ensure that your local repository is up to date with the latest contract code and JSON files before initiating an upgrade.
- Backup all contract data and thoroughly test any new code in a controlled environment prior to an upgrade.
- Monitor the output of the upgrade process carefully for transaction details and to verify its successful completion.

## Branching Strategy

### Production branch
Expand Down
7 changes: 5 additions & 2 deletions contracts/binding/build.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 8 additions & 2 deletions contracts/binding/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,18 @@ pub mod xnet_messaging_facet;
#[allow(clippy::all)]
pub mod gateway_messenger_facet;
#[allow(clippy::all)]
pub mod subnet_actor_checkpointing_facet;
#[allow(clippy::all)]
pub mod subnet_actor_diamond;
#[allow(clippy::all)]
pub mod subnet_actor_getter_facet;
#[allow(clippy::all)]
pub mod subnet_actor_manager_facet;
#[allow(clippy::all)]
pub mod subnet_actor_pause_facet;
#[allow(clippy::all)]
pub mod subnet_actor_reward_facet;
#[allow(clippy::all)]
pub mod subnet_registry_diamond;
#[allow(clippy::all)]
pub mod register_subnet_facet;
Expand All @@ -50,11 +56,11 @@ fvm_address_conversion!(gateway_getter_facet);
fvm_address_conversion!(bottom_up_router_facet);
fvm_address_conversion!(xnet_messaging_facet);
fvm_address_conversion!(gateway_messenger_facet);
fvm_address_conversion!(subnet_actor_manager_facet);
fvm_address_conversion!(subnet_actor_checkpointing_facet);
fvm_address_conversion!(subnet_actor_getter_facet);
fvm_address_conversion!(lib_gateway);

// The list of contracts that need to convert common types between each other
common_type_conversion!(gateway_getter_facet, subnet_actor_manager_facet);
common_type_conversion!(subnet_actor_getter_facet, bottom_up_router_facet);
common_type_conversion!(subnet_actor_getter_facet, checkpointing_facet);
common_type_conversion!(subnet_actor_getter_facet, xnet_messaging_facet);
33 changes: 5 additions & 28 deletions contracts/hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import { HardhatUserConfig, task } from 'hardhat/config'
import '@typechain/hardhat'
import 'hardhat-storage-layout-changes'

import '@nomicfoundation/hardhat-foundry'
import '@nomiclabs/hardhat-ethers'
import 'hardhat-deploy'
import 'hardhat-contract-sizer'

import '@typechain/hardhat'
import dotenv from 'dotenv'
import fs from 'fs'
import 'hardhat-contract-sizer'
import 'hardhat-deploy'
import 'hardhat-storage-layout-changes'
import { HardhatUserConfig, task } from 'hardhat/config'
import { HardhatRuntimeEnvironment } from 'hardhat/types'

dotenv.config()
Expand Down Expand Up @@ -193,27 +191,6 @@ task(
},
)

task(
'deploy-subnet',
'Builds and deploys the SubnetActor contract on the selected network',
async (args, hre: HardhatRuntimeEnvironment) => {
const network = hre.network.name

const deployments = await getDeployments(network)
const { deploy } = await lazyImport('./scripts/deploy-subnet')

// remove unused lib
delete deployments.libs['StorableMsgHelper']

const subnetDeployment = await deploy(
deployments.Gateway,
deployments.libs,
)

await saveDeployments(network, subnetDeployment)
},
)

task(
'deploy-gw-diamond-and-facets',
'Builds and deploys Gateway Actor diamond and its facets',
Expand Down
19 changes: 19 additions & 0 deletions contracts/ops/deploy-subnet-registry.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash
# Upgrades IPC Gateway Diamond Facets on an EVM-compatible subnet using hardhat
set -e

if [ $# -ne 1 ]
then
echo "Expected a single argument with the name of the network to deploy (localnet, calibrationnet, mainnet)"
exit 1
fi

NETWORK=$1

if [ "$NETWORK" = "auto" ]; then
echo "[*] Automatically getting chainID for network"
source ops/chain-id.sh
fi


npx hardhat deploy-subnet-registry --network ${NETWORK}
20 changes: 20 additions & 0 deletions contracts/ops/deploy-subnet.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash
# Upgrades IPC Gateway Diamond Facets on an EVM-compatible subnet using hardhat
set -e

if [ $# -ne 1 ]
then
echo "Expected a single argument with the name of the network to deploy (localnet, calibrationnet, mainnet)"
exit 1
fi

NETWORK=$1

if [ "$NETWORK" = "auto" ]; then
echo "[*] Automatically getting chainID for network"
source ops/chain-id.sh
fi


npx hardhat deploy-sa-diamond-and-facets --network ${NETWORK}

42 changes: 34 additions & 8 deletions contracts/scripts/deploy-registry.template.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ethers } from 'hardhat'
import { deployContractWithDeployer, getTransactionFees } from './util'
import { ethers } from 'hardhat'

const { getSelectors, FacetCutAction } = require('./js/diamond.js')

Expand All @@ -26,18 +26,38 @@ export async function deploy() {
txArgs,
)
const getterSelectors = getSelectors(getterFacet)
// console.log("getter address:", getterFacet.address);

const managerFacet = await deployContractWithDeployer(
deployer,
'SubnetActorManagerFacet',
{
LibStaking: LIBMAP['LibStaking'],
},
{},
txArgs,
)
const managerSelectors = getSelectors(managerFacet)
// console.log("manager address:", managerFacet.address);

const pauserFacet = await deployContractWithDeployer(
deployer,
'SubnetActorPauseFacet',
{},
txArgs,
)
const pauserSelectors = getSelectors(pauserFacet)

const rewarderFacet = await deployContractWithDeployer(
deployer,
'SubnetActorRewardFacet',
{ LibStaking: LIBMAP['LibStaking'] },
txArgs,
)
const rewarderSelectors = getSelectors(rewarderFacet)

const checkpointerFacet = await deployContractWithDeployer(
deployer,
'SubnetActorCheckpointingFacet',
{},
txArgs,
)
const checkpointerSelectors = getSelectors(checkpointerFacet)

//deploy subnet registry diamond
const registry = await ethers.getContractFactory('SubnetRegistryDiamond', {
Expand All @@ -48,8 +68,14 @@ export async function deploy() {
gateway: gatewayAddress,
getterFacet: getterFacet.address,
managerFacet: managerFacet.address,
subnetGetterSelectors: getterSelectors,
subnetManagerSelectors: managerSelectors,
rewarderFacet: rewarderFacet.address,
checkpointerFacet: checkpointerFacet.address,
pauserFacet: pauserFacet.address,
subnetActorGetterSelectors: getterSelectors,
subnetActorManagerSelectors: managerSelectors,
subnetActorRewarderSelectors: rewarderSelectors,
subnetActorCheckpointerSelectors: checkpointerSelectors,
subnetActorPauserSelectors: pauserSelectors,
}

const facetCuts = [] //TODO
Expand Down
Loading
Loading