Fix BLS12-381 precompile activation and harden dev-support scripts#3426
Merged
Pana merged 1 commit intoConflux-Chain:masterfrom Apr 15, 2026
Merged
Conversation
…eight Introduce `ActivateAt` enum to distinguish block-number-based and epoch-height-based builtin activation, fixing a type mismatch where `transition_heights.eip2537` (an epoch height) was stored as `activate_at` but compared against `env.number` (a DAG block number) in `is_active`. Because DAG block numbers grow ~5x faster than epoch heights, BLS12-381 was activating roughly 5x earlier than configured. Add private extension traits `ActivateByNumbers` / `ActivateByHeights` on `TransitionsBlockNumber` / `TransitionsEpochHeight` in `machine/mod.rs`. These accept a field-selector closure typed against the concrete struct, making `transition_numbers.activate_at(|t| t.eip2537)` a compile error and eliminating the class of mismatches at the source.
9868f35 to
af404f0
Compare
peilun-conflux
approved these changes
Apr 14, 2026
Contributor
peilun-conflux
left a comment
There was a problem hiding this comment.
@peilun-conflux reviewed 4 files and all commit messages.
Reviewable status:complete! all files reviewed, all discussions resolved (waiting on ChenxingLi).
ChenxingLi
added a commit
to ChenxingLi/conflux-rust
that referenced
this pull request
Apr 14, 2026
Remaining items from PR Conflux-Chain#3426 after PRs Conflux-Chain#3441 and Conflux-Chain#3442: - test.sh: `rm -f target` → `rm -rf target` — rm -f silently fails on real directories, causing ln -s to create a link inside the directory instead of replacing it - tools/consensus_bench/Cargo.toml: add [workspace] to prevent Cargo from resolving upward to the parent repo's workspace when the worktree is nested inside it - tools/evm-spec-tester/Cargo.toml: same fix, same root cause New: add fmt check to test.sh as a pre-phase before the build. Jenkins Master lacks the nightly toolchain so fmt checking runs on Worker via test.sh. Uses independent anchors (=== Fmt check ===) to avoid renumbering existing phases. Update SKILL.md monitoring guide: pipe-based launch to avoid tee /dev/stderr log corruption, expanded phase regex for fmt anchors, pre-flight fmt check, and fmt phase documentation.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Background
Conflux's activation mechanism has gone through a gradual migration from block-number-based to epoch-height-based triggers.
In the early design, precompile and EVM feature activations all used DAG block numbers, mirroring the EVM
numberopcode exposed to contracts. Because smart contracts had no way to query epoch height, block number was the only on-chain signal available to them for detecting spec changes. Only consensus-layer features (which are invisible to contracts) used epoch heights.Two developments shifted this design:
ConfluxContextinternal contract, removing the original constraint that contracts could only observe block numbers.As a result, newer features activate by epoch height. CIP-133 (Enhanced Block Hash Query) is the most illustrative case: it distinguishes core space (
cip133b, block-number-triggered) from eSpace (cip133e, epoch-height-triggered). Going forward, all EVM-layer activations are expected to migrate to epoch height.The Bug (EIP-2537)
eip2537is declared inTransitionsEpochHeight— an epoch height value. However, before this fix,Builtin::activate_atwas a plainu64, andis_activecompared it againstenv.number(the DAG block number) regardless of what the stored value represented.Because DAG block numbers grow approximately 2× faster than epoch heights, the BLS12-381 precompiles activated roughly 2× earlier than configured, meaning they would be available at an epoch that is far below the intended threshold.
Fix
Commit 1 —
fix(executor): correct BLS12-381 precompile activation to use epoch heightActivateAtenum (builtin/mod.rs)Replace the bare
u64field with a typed enum:is_activenow takes bothblock_numberandepoch_heightand dispatches on the variant, so the correct counter is always used.Extension traits (
machine/mod.rs)Two private traits,
ActivateByNumbersandActivateByHeights, are implemented onTransitionsBlockNumberandTransitionsEpochHeightrespectively. Each exposes anactivate_at(f)method that accepts a field-selector closure typed against the concrete struct:This makes the category of bug impossible to reintroduce silently.
Callsites (
context.rs,stack/executable.rs)Machine::builtinnow receives bothblock_numberandepoch_height, both sourced fromenv, so the correct value reaches eachBuiltin.Commit 2 —
fix: harden dev-support scripts and consensus_bench workspace isolationFour small fixes uncovered while runningtest.shend-to-end in a worktree:Removed, the first 2 issues have been resolved by PR #3442 , the CXXFLAGS issue have been resolved by PR #3441, the others is to be resolved after merging #3442.
activate_new_venv.shuv venvwith[ ! -d .venv ]so repeated runs do not recreate the virtualenvdep_pip3.shpip install uvwhenuvis already onPATH, avoiding PEP 668 errors on system Pythontest.shCXXFLAGS=-Wno-error=array-boundsto suppress a C++ build failure on newer GCC; fix symlink bug:rm -f targetsilently fails whentarget/is a real directory, causingln -s build targetto create a dangling link inside the directory — changed torm -rf targettools/consensus_bench/Cargo.toml[workspace]to make it a standalone workspace root, preventing Cargo from resolving upward to the parent repository's workspace when the worktree is nested inside itTest Plan
Before merging the current branch into the production environment, restart tests must be conducted on both the mainnet and testnet! This is because the activation time of the relevant feature has actually been moved forward (earlier than originally planned). We want to verify that no calls were made to the relevant code paths during the period between the actual activation time and the originally expected activation time.
This change is
Closes #3375