Files
zeekayandGitHub 96da029e9a Thinking Chains: chains (#2)
* hanzo-evm: aiquorum + aimarket precompiles, evmllm (geth AI precompile + e2e), operator/canonical (commit/reveal, int8-quant), aiffi bench. Thinking-chain substrate.

* hanzo-evm/evm: wire AI precompiles (inference 0x0300..03 + modelregistry)

Registers deterministic int8 inference (Tier-1 in-consensus AI) + ModelSpec
registry into the Hanzo EVM. threshold dep aligned to v1.9.4 (go.mod match).
Builds green (55M binary). aivmbridge follows luxfi/precompile release.
2026-06-21 20:53:42 -07:00

75 lines
2.3 KiB
Go

// Copyright (C) 2026, Hanzo AI Inc. All rights reserved.
// RED-2: exhaustive verification of BucketBps round-half-to-even over the FULL
// input domain [0,10000], plus clamp behavior above it, against an independent
// big.Rat reference. This proves there is no off-by-one or float-bias anywhere on
// the grid (two honest operators with the SAME raw confidence always bucket the
// same — a precondition for governance quorum).
package operator
import (
"math/big"
"testing"
"github.com/hanzoai/chains/hanzo-evm/operator/canonical"
)
// refBucket: independent round-half-to-even of bps onto a 1000 grid using exact
// rational arithmetic (no float), clamped to [0,10000].
func refBucket(bps int) int {
if bps > canonical.MaxConfidenceBps {
bps = canonical.MaxConfidenceBps
}
const g = canonical.ConfidenceGridBps
q := bps / g
r := bps % g
idx := q
switch {
case 2*r < g:
case 2*r > g:
idx = q + 1
default: // exact half -> round to even index
if q%2 != 0 {
idx = q + 1
}
}
snapped := idx * g
if snapped > canonical.MaxConfidenceBps {
snapped = canonical.MaxConfidenceBps
}
return snapped
}
func TestRED2_BucketBpsExhaustive(t *testing.T) {
// Full domain plus a band above MaxConfidenceBps to exercise the clamp.
for bps := 0; bps <= 70000; bps++ {
in := uint16(bps)
if bps > 65535 {
in = 65535 // uint16 ceiling; still well above MaxConfidenceBps -> clamps
}
got := canonical.Decision{ConfidenceBps: in}.BucketBps()
want := refBucket(int(in))
if int(got) != want {
t.Fatalf("BucketBps(%d) = %d, want %d", in, got, want)
}
}
// Sanity: confirm the reference itself matches a big.Rat half-even at the
// canonical half-points, so we're not validating against a buggy reference.
for _, hp := range []int{500, 1500, 2500, 3500, 4500, 5500, 6500, 7500, 8500, 9500} {
// exact half: round to even multiple of 1000.
lo := (hp / 1000) * 1000
hi := lo + 1000
evenChoice := lo
if (lo/1000)%2 != 0 {
evenChoice = hi
}
// guard hi clamp
if evenChoice > canonical.MaxConfidenceBps {
evenChoice = canonical.MaxConfidenceBps
}
if refBucket(hp) != evenChoice {
t.Fatalf("reference wrong at half-point %d: ref=%d evenChoice=%d", hp, refBucket(hp), evenChoice)
}
_ = big.NewRat(int64(hp), 1000) // documents the exact-rational intent
}
}