Skip to content

contracts: migrate contract to submodule#900

Open
hyunsooda wants to merge 24 commits into
kaiachain:devfrom
hyunsooda:feat/system-contracts-submodule-dev
Open

contracts: migrate contract to submodule#900
hyunsooda wants to merge 24 commits into
kaiachain:devfrom
hyunsooda:feat/system-contracts-submodule-dev

Conversation

@hyunsooda
Copy link
Copy Markdown
Contributor

@hyunsooda hyunsooda commented May 14, 2026

Proposed changes

Add kaia-system-contracts as git submodule — single source of truth for system contract .sol files and compiled artifacts

  • Add submodule: contracts/kaia-system-contracts/kaia-system-contracts pointing to main
  • Add --artifact mode to abigenw: generate Go bindings directly from pre-compiled Hardhat/Forge JSON artifacts instead of recompiling .sol from source. Permissionless contracts (v3.0) use Forge artifacts from the submodule.
  • Consolidate all Go bindings under contracts/bindings/: move generated .go files out of testing/, libs/, service_chain/, contracts/system_contracts/* into bindings/. All callers updated.
  • Flatten contracts/contracts/contracts/: remove the redundant nesting. hardhat.config.ts updated to use TASK_COMPILE_SOLIDITY_GET_SOURCE_PATHS subtask with explicit glob instead of paths.sources.
  • Activate go:generate directives: all non-WARNING // //go:generate lines uncommented. WARNING-guarded bindings (credit.go, SimpleBlsRegistry.go, Registry.go, proxyv4/Proxy.go) remain commented — BinRuntime must match mainnet-deployed bytecode.
  • Rewrite contracts/README.md for the new directory structure.

Types of changes

  • 🐛 Bug fix
  • ✨ Non-hardfork changes (node upgrade not required)
  • 💥 Hardfork / consensus-breaking changes
  • 🧪 Test improvements
  • 🧰 CI / build tool
  • ♻️ Chore / Refactor / Non-functional changes

Checklist

  • 📖 I have read the CONTRIBUTING GUIDELINES doc
  • 📝 I have signed in the PR comment I have read the CLA Document and I hereby sign the CLA in first time contribute after having read CLA
  • 🟢 Lint and unit tests pass locally with my changes ($ make test)

Related issues

Further comments

kaia-system-contracts submodule serves as the single source of truth. Going forward, system contract changes are managed by updating the submodule and running go generate to regenerate bindings.

bindings/multicall/ uses MultiCallContract from contracts-v3.0. No separate v2.2 binding is generated because the v3.0 MultiCallContract subsumes v2.2's MultiCall. It is pinned to solc 0.8.19 so its bytecode targets pre-Shanghai EVM (no PUSH0) — required since MultiCallContract is injected into state on every block.

hardhat.config.ts uses a TASK_COMPILE_SOLIDITY_GET_SOURCE_PATHS subtask override instead of paths.sources = "." because setting paths.sources = "." causes Hardhat to treat node_modules/ as a local source directory, breaking OpenZeppelin imports with HH1006.

Directory structure after this PR:

contracts/
├── abigenw                    # Go binding generator script
├── generate.go                # go generate directives
├── bindings/                  # Generated Go bindings (do not edit manually)
│   ├── abv2data/
│   ├── addressbookv2/
│   ├── auction/
│   ├── beacon/
│   ├── bridge/
│   ├── cnstakingv4/
│   ├── cnstakingv4factory/
│   ├── gov/
│   ├── kip113/
│   ├── kip149/
│   ├── kip247/
│   ├── kip13/
│   ├── misc/
│   ├── multicall/
│   ├── proxyv4/
│   ├── proxyv5/
│   ├── publicdelegation/
│   ├── rebalance/
│   ├── testing/               # Test-only bindings
│   └── uniswap/
├── kaia-system-contracts/     # Git submodule — upstream .sol + artifacts
├── libs/                      # Vendored Solidity libraries (.sol only)
├── service_chain/             # Service chain bridge contracts (.sol only)
└── testing/                   # Mock and testing contracts (.sol only)

TODO

  • kaia-system-contracts submodule currently points to a private repository. Switch to the public repo URL once it is released.
  • .gitmodules currently pins branch = main. Replace with the release tag once ksc cuts one so the submodule points to a stable, immutable ref instead of a moving branch head.

hyunsooda and others added 23 commits May 14, 2026 12:43
…ve contracts_permissionless

Move Go bindings from contracts_permissionless/contracts/ to contracts/bindings/
and update all import paths. Delete contracts_permissionless/ entirely.

Bindings moved:
- addressbookv2, abv2data, cnstakingv4, cnstakingv4factory
- multicall, proxy, beacon, publicdelegation, testing

Note: bindings are copied from prior generated output; will be regenerated
via contracts/generate.go once abigenw --artifact mode is implemented.

Constraint: abigenw --artifact mode not yet implemented; .sol source now lives in kaia-system-contracts submodule
Confidence: high
Scope-risk: moderate

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
… → abv2data pkg)

PR kaiachain#157 in kaia-system-contracts moved IABv2DataContractInitData from
AddressBookV2 to ABv2DataContract (initialize() now takes no params;
InitData passed to ABv2DataContract constructor instead). Updated all
callers to use abv2data.IABv2DataContractInitData. Also updates
ERC1967ProxyV5Code regression hash to match recompiled OZ 5.x bytecode
from ksc submodule.

Constraint: IABv2DataContractInitData is now in abv2data package, not addressbookv2
Confidence: high
Scope-risk: narrow

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Extract arg validation and two execution modes (artifact, sol) into
validate_args(), run_artifact_mode(), run_sol_mode() for clarity.

Confidence: high
Scope-risk: narrow

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Registers https://github.com/kaiachain/kaia-system-contract at
contracts/kaia-system-contracts (pinned to main branch).

Directive: When releasing, update .gitmodules branch from main to the release branch/tag before bumping the submodule
Confidence: high
Scope-risk: narrow

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Move all Go import paths from contracts/contracts/{system_contracts,testing,libs}
to the new contracts/{bindings,testing,libs} layout.
- system_contracts/* → contracts/bindings/*
- contracts/libs/uniswap → contracts/libs/uniswap (one level up)
- proxy → proxyv4 / proxyv5 (split by ERC1967 version)
- Remove contracts/bindings/proxy/Proxy.go (superseded by proxyv4/proxyv5)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Move libs/, service_chain/, testing/ up one level, removing the
redundant contracts/contracts/ nesting introduced before the ksc
submodule migration.

- contracts/contracts/libs/       → contracts/libs/
- contracts/contracts/service_chain/ → contracts/service_chain/
- contracts/contracts/testing/    → contracts/testing/
- Fix relative kaia-system-contracts import depth in
  testing/system_contracts/*.sol (../../../ → ../../)

Constraint: hardhat resolves node_modules imports relative to
paths.sources root; paths.sources="." triggers HH1006, so the
TASK_COMPILE_SOLIDITY_GET_SOURCE_PATHS subtask explicitly globs
{libs,service_chain,testing}/**/*.sol instead.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- hardhat.config.ts: override TASK_COMPILE_SOLIDITY_GET_SOURCE_PATHS
  to glob {libs,service_chain,testing}/**/*.sol; avoids HH1006 caused
  by node_modules/ falling under paths.sources="."
- generate.go: strip contracts/ prefix from commented-out directives
  (./contracts/testing/ → ./testing/, etc.) to match new paths

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Update string references to .sol files and Go import paths that still
pointed to the old contracts/contracts/ layout:
- contracts/contracts/testing/ → contracts/testing/
- contracts/contracts/service_chain/ → contracts/service_chain/
- contracts/contracts/libs/ → contracts/libs/

Affected: blockchain/, kaiax/, node/sc/, datasync/, tests/,
cmd/homi/, common/compiler/, contracts/test/

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Reflect the ksc submodule migration and contracts/contracts/ flattening:
- New directory layout (bindings/, kaia-system-contracts/, libs/, etc.)
- go generate workflow (artifact-based, no local solc needed for system contracts)
- Remove stale system_contracts/ section

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Generate Go bindings using abigenw --artifact mode from
kaia-system-contracts submodule artifacts (forge/hardhat output).

New packages: auction, gov, kip113, kip149, kip247, misc,
proxyv4, proxyv5, rebalance, testing (system_contracts)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Test directories now covered by kaia-system-contracts submodule tests.
Removed: Allocation, Auction, CLRegistry, CnV3, Gasless, GovParam,
KAIABridge, MultiCall, PublicDelegation, Registry, SimpleBlsRegistry,
StakingTracker, StakingTrackerV2, TreasuryRebalance/trv2, Voting,
common/, materials/

Also remove contracts/docs/ (stale, superseded by ksc repo docs).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
… to bindings/

All generated Go binding files are consolidated under contracts/bindings/:
- contracts/testing/{reward,sc_erc20,sc_erc721,sc_erc721_no_uri,extbridge,system_contracts}/*.go → bindings/testing/...
- contracts/libs/uniswap/{factory,router}/*.go → bindings/uniswap/...
- contracts/libs/kip13/*.go → bindings/kip13/
- contracts/service_chain/bridge/Bridge.go → bindings/bridge/

Update all callers across blockchain/system, node/sc, kaiax, tests, cmd, datasync.
Update generate.go --out paths to match new locations.

Constraint: .sol source files remain in their original dirs (testing/, service_chain/, libs/) — only the generated .go outputs move
Confidence: high
Scope-risk: moderate

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
… to bindings/

Uncomment all non-WARNING //go:generate directives so `go generate` regenerates
all local bindings (reward, bridge, sc_erc20/721, extbridge, WKAIA, uniswap, all.sol).
Update --out paths to match new bindings/ consolidation layout.

WARNING-guarded directives (credit.go, SimpleBlsRegistry.go, Registry.go, proxyv4/Proxy.go)
remain commented — BinRuntime must match mainnet-deployed bytecode.

Confidence: high
Scope-risk: narrow

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
all.go was moved to contracts/bindings/testing/reward/, making it a
separate Go package. Update test to package reward_test and import
the binding explicitly.

Confidence: high
Scope-risk: narrow

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
contracts/contracts/system_contracts/proxy was removed as part of
the contracts/ flattening; the binding now lives at contracts/bindings/proxyv4.

Confidence: high
Scope-risk: narrow

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
uniswap/* imports must follow testing/* alphabetically.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…attening

JSON was compiled with ../contracts/contracts/testing/ paths.
After contracts/contracts/ -> contracts/ flattening, test lookup
keys were updated but JSON keys were not, causing nil pointer
dereference in TestPrecompiledContract.

Confidence: high
Scope-risk: narrow

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Removed packages with no local usage after ksc submodule migration:
- @defi-wonderland/smock (ksc-only)
- @openzeppelin/contracts (no local .sol usage)
- @openzeppelin/hardhat-upgrades (no local upgrades.* usage)
- @types/lodash (ksc-only)
- bls-signatures (ksc-only)
- openzeppelin-contracts-5.0 (ksc-only)

Also removed the corresponding import from hardhat.config.ts.

Confidence: high
Scope-risk: narrow

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…em-contract

Align the submodule directory name with the actual GitHub repository name
(kaia-system-contract, without trailing 's') per reviewer feedback in PR kaiachain#885.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
DevOps renamed the GitHub repo to kaia-system-contracts (with 's') to
align with npm package naming convention. Update local submodule
directory, .gitmodules path/name, .gitmodules URL, and all source
references accordingly.

This reverts 7892a87 and updates the .gitmodules URL to the renamed
repository.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…ding

Restore the local .sol from permissionless branch so the binding becomes
regenerable via go:generate, instead of relying on a frozen copy.

- Add MultiCallContractMockPermissionless.sol with ksc import paths
  (IAddressBook from contracts-klaytn-v1.12, Profile/State from contracts-v3.0)
- Add go:generate directive in generate.go
- Rename binding type to MultiCallContractMockPermissionless to avoid
  collision with the legacy MultiCallContractMock in all.go
- Update blockchain/system/constant.go to use new symbol name
- Remove the obsolete "kept as copied binding" frozen file

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Regenerate Go bindings for v3.0 permissionless contracts from updated
ksc artifacts. The previous bindings were copied from contracts_permissionless/
during the bindings move and never regenerated, so they reflect older ksc
interfaces.

- abv2data, addressbookv2, beacon, cnstakingv4, cnstakingv4factory,
  multicall, publicdelegation

Net -67k / +5k lines: most deletions come from helper/interface bindings
(ABv2ConfigLib, Context, Address, IAddressBook etc.) that are no longer
included now that generate.go directives specify --type flag for the
target contract only.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Pull in kaia-system-contracts/pull/4 which pins MultiCallContract.sol
to solc 0.8.19 so its bytecode targets London EVM (no PUSH0).

Regenerate bindings/multicall/MultiCallContract.go from the updated
ksc artifact.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@hyunsooda hyunsooda self-assigned this May 14, 2026
@hyunsooda hyunsooda marked this pull request as draft May 14, 2026 04:03
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@hyunsooda hyunsooda marked this pull request as ready for review May 14, 2026 05:59
@hyunsooda hyunsooda changed the title Feat/system contracts submodule dev contracts: migrate contract to submodule May 14, 2026
@ian0371 ian0371 mentioned this pull request May 14, 2026
9 tasks
Comment thread contracts/bindings/gov/GovParam.go
Comment thread contracts/test/TreasuryRebalance/tr.test.js
Comment thread contracts/docs/abook.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants