mirror of
https://github.com/luxfi/evm.git
synced 2026-09-24 00:27:44 +00:00
Wires the existing cevm (C++ EVM) byte-exact shadow verifier so it observes EVERY block of the real ./core suite, and reports the true tally — without weakening the gate or ever letting cevm apply state. - core/main_cevm_test.go (//go:build cevm): a cevm-only TestMain that runs the whole ./core suite then prints the aggregate parallel.CevmShadowStats(). Because state_processor.go:124 routes every block through parallel.DefaultExecutor().ExecuteBlock — which under -tags cevm is the cevmShadowExecutor — this is the honest whole-suite count. main_test.go's goleak TestMain is gated //go:build !cevm so exactly one TestMain exists per build. - core/parallel/cevm_shadow_registration_test.go (//go:build cevm): asserts DefaultExecutor() is the cevmShadowExecutor (not the no-op fallback) — the precondition for the whole claim. - core/parallel/cevm_shadow_e2e_test.go: scaled the real-StateProcessor agreement proof from 3 to 256 genuine InsertChain blocks (768 transfers). cevm's independent real-MPT process_block root byte-matched the Go EVM header.Root on ALL 256/256 blocks (0 disagree, 0 finalize-gap). - Four precompile test files (genesis_dexsettle_reproduce, precompile_alwayson, precompile_statedb_subbalance, precompile_env_call) gated //go:build !cevm: they alone pull precompile/registry -> luxfi/precompile/dex -> luxfi/dex/pkg/dex whose cgo file #includes the absent dex_gpu.h, breaking the CGO_ENABLED=1 build the bridge needs. They are precompile tests, not block-execution tests, and still run in every non-cevm build — an orthogonal blocker isolated, not a cevm regression. HONEST RESULTS (CGO_ENABLED=1 -tags cevm): - Whole ./core suite: 78 PASS / 0 FAIL / 32 SKIP. cevm observed all 9794 blocks; it declined every one as no-preimage (the production default runs preimages OFF, and the shadow needs trie-key preimages to recover the 20-byte addresses that seed cevm) — 0 disagree, 0 errored, 0 false roots. The Go EVM applied every block; cevm never touched state. - Real-block agreement (preimages ON, the config the shadow requires), driven through core.BlockChain.InsertChain -> StateProcessor.Process -> the shadow: 256/256 blocks byte-exact agreement (768 transfers). Default (!cevm) build unchanged: ./core and ./core/parallel green in both CGO modes; the 10 gated precompile tests present in the default build. Co-authored-by: Hanzo Dev <[email protected]>
70 lines
3.3 KiB
Go
70 lines
3.3 KiB
Go
// Copyright (C) 2025-2026, Lux Industries Inc. All rights reserved.
|
|
// See the file LICENSE for licensing terms.
|
|
|
|
// Excluded under -tags cevm: imports precompile/registry, which transitively
|
|
// pulls luxfi/precompile/dex -> luxfi/dex/pkg/dex whose cgo file #includes the
|
|
// (absent) dex_gpu.h header — breaking the CGO_ENABLED=1 build the cevm shadow
|
|
// verifier needs. Precompile test, not a block-execution test; still runs in
|
|
// every non-cevm build. Orthogonal blocker, not a cevm regression.
|
|
//go:build !cevm
|
|
|
|
package core
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/holiman/uint256"
|
|
"github.com/luxfi/geth/common"
|
|
"github.com/luxfi/geth/core/tracing"
|
|
)
|
|
|
|
// precompile_statedb_subbalance_test.go pins the fix for a LATENT bug: the
|
|
// precompile registry's stateDBBridge.SubBalance type-asserts the internal
|
|
// contract.StateDB for the EXTERNAL SubBalance signature
|
|
//
|
|
// SubBalance(common.Address, *uint256.Int, tracing.BalanceChangeReason) uint256.Int
|
|
//
|
|
// and previously fell back to a NO-OP when the assertion failed. The concrete
|
|
// adapter the EVM hands precompiles is *stateDBAdapter; if it does not implement
|
|
// that EXACT signature, a precompile that debits native value — e.g. the DEX 0x9999
|
|
// custody vault, whose withdraw debits the vault before releasing to the caller —
|
|
// would silently MINT (caller credited, vault never debited). The fix added
|
|
// SubBalance to *stateDBAdapter so the bridge's assertion succeeds and the fallback
|
|
// is unreachable; the fallback itself now FAILS CLOSED (panics → reverted call)
|
|
// rather than returning a zero "previous balance" without debiting.
|
|
|
|
// subBalancer is the EXACT interface precompile/registry/bridge.go type-asserts.
|
|
// Keep it byte-identical so this test fails if the bridge's expected signature or
|
|
// the adapter's method ever drifts.
|
|
type subBalancer interface {
|
|
SubBalance(common.Address, *uint256.Int, tracing.BalanceChangeReason) uint256.Int
|
|
}
|
|
|
|
// TestStateDBAdapter_SatisfiesSubBalancer is the regression guard: *stateDBAdapter
|
|
// MUST satisfy the subBalancer interface the registry bridge type-asserts. If this
|
|
// fails to compile or asserts false, the bridge would hit its mint fallback for
|
|
// every precompile native-value debit (the DEX withdraw vault-release).
|
|
func TestStateDBAdapter_SatisfiesSubBalancer(t *testing.T) {
|
|
// Compile-time assertion (the primary guard against signature drift).
|
|
var _ subBalancer = (*stateDBAdapter)(nil)
|
|
|
|
// Runtime assertion mirroring exactly what the bridge does:
|
|
// if sb, ok := s.internal.(subBalancer); ok { return sb.SubBalance(...) }
|
|
var adapter contractStateDBSurface = (*stateDBAdapter)(nil)
|
|
if _, ok := interface{}(adapter).(subBalancer); !ok {
|
|
t.Fatal("*stateDBAdapter does NOT satisfy subBalancer — the registry bridge would hit the mint fallback for native-value debits")
|
|
}
|
|
// A non-nil *uint256.Int sanity reference (keeps the import meaningful and the
|
|
// signature exercised in source).
|
|
_ = uint256.NewInt(0)
|
|
}
|
|
|
|
// contractStateDBSurface is the minimal surface we hold the adapter as for the
|
|
// runtime assertion — it is satisfied by *stateDBAdapter (which implements the
|
|
// full internal contract.StateDB). Held as an interface value so the type
|
|
// assertion to subBalancer is a genuine runtime check, not a compile-time tautology.
|
|
type contractStateDBSurface interface {
|
|
GetBalance(common.Address) *uint256.Int
|
|
AddBalance(common.Address, *uint256.Int)
|
|
}
|