ThatAIguyA world of ideas

THE CONSCIOUSNESS ATLAS
Read. Experiment. Follow the evidence.

ConsciousnessLearn · Explore · Joseph Anady

Janady13/missionmatch / internal/platform/federated/accountant.go

Source identity, revision, and recovered contents.

GitHub sourceSource text recovered

Source identity

FieldRecorded value
Source typeGitHub source
Original recordJanady13/missionmatch / internal/platform/federated/accountant.go
DateNot specified in source
RepositoryJanady13/missionmatch
Revision720d47fae476b0d38477ae4401697d372b1ea2bc
Branchfeature/opportunity-to-outcome
Path or archive memberinternal/platform/federated/accountant.go
Original SHA-2561834ea0d0d477d61088ddc4c50846ef1c9e6d5d41f4fb3cbc7aa69b3998b0430
Git blob SHA3c719897a864b71e2344dc6a22f625b43144d471
Reading-copy SHA-2561834ea0d0d477d61088ddc4c50846ef1c9e6d5d41f4fb3cbc7aa69b3998b0430

Original source ↗

Every recorded occurrence

These 14 records contain identical original source bytes. Their paths and revisions remain part of the archive.

Original recordBranch or archiveRevision / identifierOriginal location
Janady13/missionmatch / internal/platform/federated/accountant.gofeature/opportunity-to-outcome720d47fae476b0d38477ae4401697d372b1ea2bcOpen original
Janady13/missionmatch / internal/platform/federated/accountant.gocollision-deconfliction4ee5a09972608ed89f8377c6665542d5f450f0a6Open original
Janady13/missionmatch / internal/platform/federated/accountant.gom5-price-to-win41000ad30fff4129fdaf5ec84e15ba14c27d4890Open original
Janady13/missionmatch / internal/platform/federated/accountant.gomaster1e9249840a4302ec82e123b9c9cb6f75badea3e4Open original
Janady13/missionmatch / internal/platform/federated/accountant.gows8-teaching-loopc823f0fb6bb2aba0f39001eb6de96f4000d9321fOpen original
Janady13/missionmatch / internal/platform/federated/accountant.gomag-substrateb82c7100a492dec67dfd1eda6b3f53def859be35Open original
Janady13/missionmatch / internal/platform/federated/accountant.gotime-to-fill-survivalb66e1e505863d4f17741a4b9ede73509e45bd6c6Open original
Janady13/missionmatch / internal/platform/federated/accountant.gographrag-foundationb0ddeb9f633fd138d09309d1a17b7d13bc3a67f7Open original
Janady13/missionmatch / internal/platform/federated/accountant.gows9-bench-ingestionf585a9ef32fa554663ce1fba9a414a54b6e49cf0Open original
Janady13/missionmatch / internal/platform/federated/accountant.gopresentation-readinesseb574acaa29d71ce4d0f852572e87c275c79fdb7Open original
Janady13/missionmatch / internal/platform/federated/accountant.govendor-intelligencefe9796a19c261951d3f2565206c0c1b5ac294465Open original
Janady13/missionmatch / internal/platform/federated/accountant.gophase2-connectorse038d4c687aec16f8bd9bc4d907eea14d91f8704Open original
Janady13/missionmatch / internal/platform/federated/accountant.gofeature/aioe-upgrade2178e7298d0e5d9af83afa12402fd587f0ba6ed8Open original
Janady13/missionmatch / internal/platform/federated/accountant.gocapture-readinessbae6af7cb2997e819174a9e9cfff5e16067a1975Open original

Recovered source transcript

// Package federated holds the pure Go differential privacy accountant and aggregator boundary for the cross // tenant federated learning path (WS8). The whole package is DEAD CODE unless MM_FEDERATED_DP_ENABLED is set // and a real cohort of five or more live non test tenants exists. In tenant LIVE keeps it off; only the in // tenant producer and the human approved curation pipeline ship enabled. Nothing here samples noise or emits // a release today: the package has no non test caller, and the noise sampler is a HARD activation blocker // (see Noise below) so the naive float sampler can never run on an activated path. // // THREAT MODEL (central DP, trusted server). This is plain central differential privacy: the Go API tier // clips and noises each tenant aggregate and only stores the noised result, so the server sees the raw per // tenant vector before noising and is therefore inside the trusted computing base, inside one cloud // boundary. We do NOT claim the server never sees tenant data. A TEE or secure aggregation upgrade removes // that trust later; the Aggregator interface is the seam for that drop in. The inference plane stays // stateless and never sees a cross tenant aggregate. // // UNIT OF PRIVACY is the tenant. One live non test organization is one privacy unit; each tenant // contribution is L2 clipped to a fixed sensitivity C, so a tenant that contributes many rows cannot blow // past the claimed guarantee. Record level DP would be the wrong, weaker unit for a multi tenant story. // // FIPS POSTURE. No new crypto dependency. The accountant is pure float64 and shopspring decimal arithmetic, // no cgo. When the path is activated, the noise sampler must use only in module primitives behind the FIPS // validated boundary (crypto/rand under GOFIPS140), via a Mironov safe discrete or snapped Gaussian routine. // That routine is not written yet and MUST NOT be a naive float sampler (see the float DP attack note on // Noise). No dashes in any string or comment here, by project rule. package federated import ( "errors" "math" "github.com/shopspring/decimal" ) // ErrNotImplemented is returned by the activation blocked noise sampler. It guarantees that the only noise // path that exists today returns an error rather than sampling, so no naive float Gaussian can ever run. var ErrNotImplemented = errors.New("federated: secure noise sampler is an activation blocker, not implemented") // ErrBudgetExceeded is returned by a Charge that would push the accumulated epsilon at the configured delta // over the budget. The release is refused and nothing is written. var ErrBudgetExceeded = errors.New("federated: differential privacy budget exceeded, release refused") // defaultRenyiOrders is the FIXED Renyi order grid the accountant composes over. The conversion from // accumulated RDP to (epsilon, delta) takes the minimum epsilon over these orders, so a denser grid only // tightens the reported epsilon, never loosens it. The grid spans small fractional orders (which favor large // delta) up to large integer orders (which favor small delta), so the min over the grid tracks the optimal // order across the practical (sigma, delta) range. Orders are strictly greater than 1, because the // conversion divides by (alpha minus 1). var defaultRenyiOrders = []float64{ 1.25, 1.5, 1.75, 2, 2.5, 3, 4, 5, 6, 8, 10, 12, 16, 20, 24, 32, 48, 64, 96, 128, 192, 256, 384, 512, } // GaussianRelease describes one Gaussian mechanism release for the accountant. // // CONVENTION (documented once, load bearing). The mechanism clips each per tenant contribution to L2 norm C // (the sensitivity), then adds isotropic Gaussian noise of standard deviation NoiseSigma. The privacy of a // Gaussian mechanism depends only on the noise multiplier sigma = NoiseSigma / C, the noise measured in // units of the sensitivity. For an L2 sensitivity 1 mechanism (NoiseSigma already expressed in sensitivity // units, C = 1) the multiplier is just NoiseSigma. The per release Renyi differential privacy at order alpha // is the closed form alpha / (2 * sigma^2). This is the standard Gaussian mechanism RDP curve (Mironov 2017, // cited in docs/AI_RESEARCH.md, the federated learning with differential privacy section). type GaussianRelease struct { NoiseSigma float64 // standard deviation of the added Gaussian noise, in the same units as the clip norm ClipNorm float64 // the L2 clip norm C, the per tenant sensitivity; must be greater than zero } // noiseMultiplier returns sigma = NoiseSigma / ClipNorm, the noise measured in units of the sensitivity, the // only quantity the Gaussian RDP curve depends on. A non positive clip norm or non positive noise sigma is a // programming error and yields NaN, so the per release RDP is NaN and the accountant rejects it rather than // silently treating an invalid mechanism as zero privacy loss. func (r GaussianRelease) noiseMultiplier() float64 { if r.ClipNorm <= 0 || r.NoiseSigma <= 0 { return math.NaN() } return r.NoiseSigma / r.ClipNorm } // gaussianRDP returns the per release Renyi differential privacy at order alpha for a Gaussian mechanism with // noise multiplier sigma, the closed form alpha / (2 * sigma^2). This accounts WITHOUT subsampling // amplification. WORST CASE: in a small fixed set of GovCon tenants, tenant participation is not genuinely // random and unknown to the adversary each round, so privacy amplification by subsampling cannot be claimed // (docs/AI_RESEARCH.md gotcha 5). Accounting without amplification is the conservative, worst case bound: // every tenant is assumed to participate every round, which can only overstate the spent epsilon, never // understate it. If a provably random participation scheme is ever adopted, the subsampled RDP bound from // arxiv 1808.00087 would tighten this, but the no amplification curve here stays a sound upper bound. func gaussianRDP(sigma, alpha float64) float64 { return alpha / (2 * sigma * sigma) } // epsilonAtOrder converts an accumulated RDP value at one Renyi order to an (epsilon, delta) epsilon using // the standard closed form epsilon(alpha) = rdp(alpha) + log(1/delta) / (alpha - 1). This is the canonical // RDP to approximate DP conversion (Mironov 2017, cited in docs/AI_RESEARCH.md). alpha must be greater than 1 // and delta must be in (0, 1). func epsilonAtOrder(rdp, alpha, delta float64) float64 { return rdp + math.Log(1/delta)/(alpha-1) } // Accountant is the privacy budget accountant boundary. Charge composes one release into the running budget // and returns the epsilon at the configured delta after the release, or refuses it (returning // ErrBudgetExceeded) if it would exceed the budget. Remaining returns the epsilon headroom left before the // budget is spent. An accountant implementation may be pure (in memory, for tests and the math) or ledger // backed (the hard server side spend gate in federated.go). type Accountant interface { // Charge composes the release into the running budget and returns the epsilon at the configured delta // after the release. If the release would exceed the budget it is refused, nothing is persisted, and // the returned error is ErrBudgetExceeded. Charge(release GaussianRelease) (epsilonNow float64, err error) // Remaining returns the epsilon headroom left before the budget is spent, the configured epsilon target // minus the current epsilon at the configured delta. It is never negative; a spent budget returns zero. Remaining() float64 } // rdpAccountant is the pure in memory Gaussian mechanism RDP accountant. It composes releases by SUMMING the // per release RDP at each order in the fixed grid, then converts the accumulated RDP to an (epsilon, delta) // epsilon by taking the MINIMUM epsilon over the grid orders. The grid math is float64; a ledger backed gate // records the spent epsilon as shopspring decimal for a bit stable audit record. This type is the math the // hard tests pin and the engine the ledger backed gate composes through; it never samples noise. type rdpAccountant struct { orders []float64 // the fixed Renyi order grid, strictly greater than 1 accRDP []float64 // accumulated RDP per order, index aligned with orders, summed over composed releases epsilon float64 // the epsilon budget target at delta, from config, never a code constant delta float64 // the delta target at which epsilon is reported, from config, never a code constant } // newRDPAccountant builds a pure RDP accountant over the fixed grid with the given epsilon and delta budget. // epsilon and delta come from configuration (MM_FEDERATED_DP_EPSILON and MM_FEDERATED_DP_DELTA), never from // code constants, so a privacy officer tunes them without a rebuild. priorAccRDP, when non nil, seeds the // accumulated RDP per order from a persisted ledger so composition resumes across process restarts; it must // be index aligned with the grid. delta must be in (0, 1) and epsilon must be positive. func newRDPAccountant(epsilon, delta float64, priorAccRDP []float64) (*rdpAccountant, error) { if !(delta > 0 && delta < 1) { return nil, errors.New("federated: delta must be in the open interval (0, 1)") } if !(epsilon > 0) { return nil, errors.New("federated: epsilon budget must be positive") } orders := defaultRenyiOrders acc := make([]float64, len(orders)) if priorAccRDP != nil { if len(priorAccRDP) != len(orders) { return nil, errors.New("federated: prior accumulated RDP length does not match the order grid") } copy(acc, priorAccRDP) } return &rdpAccountant{orders: orders, accRDP: acc, epsilon: epsilon, delta: delta}, nil } // composedRDP returns the per order RDP that composing one release ADDS to the running accumulation, index // aligned with the grid. It does not mutate the accountant; the caller adds it on a successful Charge. A // non finite noise multiplier (a non positive clip norm or sigma) yields a non finite RDP the caller rejects. func (a *rdpAccountant) composedRDP(release GaussianRelease) []float64 { sigma := release.noiseMultiplier() out := make([]float64, len(a.orders)) for i, alpha := range a.orders { out[i] = gaussianRDP(sigma, alpha) } return out } // epsilonFor converts a per order accumulated RDP slice to the reported epsilon at the configured delta: the // MINIMUM over the grid of epsilon(alpha) = rdp(alpha) + log(1/delta) / (alpha - 1). Taking the min over the // grid is what makes this a valid (epsilon, delta) guarantee: an (alpha, rdp(alpha)) RDP bound implies the // (epsilon, delta) bound at every order, so the smallest of them is the tightest sound epsilon. // // An empty accumulation (no releases composed, every order zero) is the zero mechanism, whose true privacy // loss is exactly zero, so epsilonFor returns 0 rather than the positive delta slack the conversion formula // would otherwise report at zero RDP. This matches the standard accountant convention (a fresh budget has // spent nothing). func (a *rdpAccountant) epsilonFor(accRDP []float64) float64 { allZero := true for _, v := range accRDP { if v != 0 { allZero = false break } } if allZero { return 0 } best := math.Inf(1) for i, alpha := range a.orders { eps := epsilonAtOrder(accRDP[i], alpha, a.delta) if eps < best { best = eps } } return best } // currentEpsilon returns the epsilon at the configured delta for the accumulation composed so far. func (a *rdpAccountant) currentEpsilon() float64 { return a.epsilonFor(a.accRDP) } // Charge composes one release into the running accumulation and returns the epsilon at the configured delta // after it. The pure accountant enforces the budget itself: if the post release epsilon would exceed the // epsilon target it refuses, leaves the accumulation untouched, and returns ErrBudgetExceeded. A non finite // release (non positive clip norm or sigma) is rejected as a programming error before any composition. func (a *rdpAccountant) Charge(release GaussianRelease) (float64, error) { add := a.composedRDP(release) candidate := make([]float64, len(a.accRDP)) for i := range a.accRDP { if math.IsInf(add[i], 0) || math.IsNaN(add[i]) { return 0, errors.New("federated: non finite per release RDP, check the clip norm and sigma") } candidate[i] = a.accRDP[i] + add[i] } eps := a.epsilonFor(candidate) if eps > a.epsilon { return 0, ErrBudgetExceeded } a.accRDP = candidate return eps, nil } // Remaining returns the epsilon headroom left before the budget is spent, never negative. func (a *rdpAccountant) Remaining() float64 { rem := a.epsilon - a.currentEpsilon() if rem < 0 { return 0 } return rem } // accumulatedRDPDecimal returns the accumulated RDP per order as shopspring decimals, the bit stable // representation the ledger persists in the rdp_orders jsonb so the audit record reproduces exactly. The grid // math runs in float64 (decimal is for the recorded artifact only, per docs/AI_RESEARCH.md). func (a *rdpAccountant) accumulatedRDPDecimal() map[float64]decimal.Decimal { out := make(map[float64]decimal.Decimal, len(a.orders)) for i, alpha := range a.orders { out[alpha] = decimal.NewFromFloat(a.accRDP[i]) } return out } // epsilonDecimal returns the current epsilon at the configured delta as a shopspring decimal, the bit stable // epsilon_at_delta the ledger records. func (a *rdpAccountant) epsilonDecimal() decimal.Decimal { return decimal.NewFromFloat(a.currentEpsilon()) } // worstRDPDecimal returns the largest accumulated RDP over the grid as a shopspring decimal, a single bit // stable scalar for the ledger accumulated_rdp summary column. It is a conservative scalar summary of the per // order accumulation, not the conversion; the per order detail lives in rdp_orders. func (a *rdpAccountant) worstRDPDecimal() decimal.Decimal { worst := math.Inf(-1) for _, v := range a.accRDP { if v > worst { worst = v } } return decimal.NewFromFloat(worst) }

Mathematical records from this source

Search equations, builds, manuscript text, and recovered sources.