Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 10 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,15 @@ jobs:
uses: actions/checkout@v4
with:
fetch-depth: 0
submodules: recursive
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: "go.mod"
- name: Set up solc
uses: ARR4N/setup-solc@v0.2.0
with:
versions: '0.8.30'
- name: Use Node.js
uses: actions/setup-node@v4
with:
Expand All @@ -87,6 +92,11 @@ jobs:
uses: actions/checkout@v4
with:
fetch-depth: 0
submodules: recursive
- name: Set up solc
uses: ARR4N/setup-solc@v0.2.0
with:
versions: '0.8.30'
- name: Use Node.js
uses: actions/setup-node@v4
with:
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,6 @@ diffs/
avalanchego/

.direnv

# Contract compilation artifacts (binary files are not committed)
contracts/artifacts/
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[submodule "contracts/lib/openzeppelin-contracts"]
path = contracts/lib/openzeppelin-contracts
url = https://github.com/OpenZeppelin/openzeppelin-contracts.git
branch = v5.4.0
5 changes: 4 additions & 1 deletion Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,15 @@ tasks:
- task: check-generate-rlp

setup-contracts:
desc: Set up contracts by installing NPM dependencies, cleaning Hardhat cache, and compiling contracts
desc: Set up contracts by compiling Solidity contracts and generating Go bindings
dir: ./contracts
cmds:
# Keep npm/Hardhat compilation for existing TypeScript tests (Phase 2-3 migration)
- cmd: npm ci
- cmd: npx hardhat clean
- cmd: npx hardhat compile
# New: Compile contracts with solc and generate Go bindings
- cmd: go generate ./...

shellcheck:
desc: Run shellcheck static analysis on all shell scripts with version management
Expand Down
60 changes: 56 additions & 4 deletions contracts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,76 @@ The goal of this guide is to lay out best practices regarding writing, testing a

## Prerequisites

### NodeJS and NPM
### Go

First, install the LTS (long-term support) version of [nodejs](https://nodejs.org/en). This is `18.16.0` at the time of writing. NodeJS bundles `npm`.
This project requires Go 1.21 or later. Install from [golang.org](https://golang.org/dl/).

### Solidity Compiler (solc)

The Solidity compiler version 0.8.30 is required to compile contracts. In CI, this is installed automatically via the [setup-solc](https://github.com/ARR4N/setup-solc) GitHub Action.

For local development, install solc 0.8.30:
- **macOS**: `brew install solidity`
- **Linux**: Follow instructions at [solidity docs](https://docs.soliditylang.org/en/latest/installing-solidity.html)
- **CI**: Automatically installed via GitHub Actions

After installation, create a version-specific alias or symlink:
```bash
# Option 1: Symlink (works in all contexts including go generate)
sudo ln -sf $(which solc) /usr/local/bin/solc-v0.8.30 # Linux
sudo ln -sf $(which solc) /opt/homebrew/bin/solc-v0.8.30 # macOS (Homebrew)

# Option 2: Shell alias (interactive shells only)
echo "alias solc-v0.8.30='solc'" >> ~/.bashrc # or ~/.zshrc
```

### Solidity and Avalanche

It is also helpful to have a basic understanding of [Solidity](https://docs.soliditylang.org) and [Avalanche](https://docs.avax.network).

## Dependencies

Clone the repo and install the necessary packages via `yarn`.
Clone the repo and install dependencies:

```bash
git clone https://github.com/ava-labs/subnet-evm.git
cd subnet-evm/contracts
npm ci # Installs OpenZeppelin and other Node.js dependencies
```

## Compiling Contracts

Contracts are compiled using `solc` directly, and Go bindings are generated using `abigen` from [libevm](https://github.com/ava-labs/libevm).

OpenZeppelin contracts are included as a git submodule at `contracts/lib/openzeppelin-contracts/` (pinned to v5.4.0).

From the repository root, run:

```bash
./scripts/run_task.sh setup-contracts
```

This will:
1. Compile all Solidity contracts in `contracts/contracts/` to ABIs and bytecode
2. Generate Go bindings in `contracts/bindings/`

The compilation artifacts (`.abi` and `.bin` files) are stored in `contracts/artifacts/` (gitignored).
The generated Go bindings in `contracts/bindings/` are committed to the repository.

### Manual Compilation

To manually compile contracts and generate bindings:

```bash
cd contracts
npm install
npm ci # Install dependencies if not already done
go generate ./... # Compile contracts and generate bindings
```

All compilation and code generation is configured in `contracts/contracts/compile.go` using `go:generate` directives. The directives execute in order:
1. First, `solc` compiles `.sol` files to `.abi` and `.bin` files in `artifacts/`
2. Then, `abigen` generates Go bindings from the artifacts to `bindings/*.go`

## Write Contracts

`AllowList.sol` is the base contract which provided AllowList precompile capabilities to inheriting contracts.
Expand Down
Loading
Loading