mirror of
https://github.com/luxfi/annulus.git
synced 2026-10-30 17:02:25 +00:00
Defines the policy that constrains which cryptographic operations a
Quasar node accepts. The package contains no cryptographic primitives.
Two values, one gate:
Profile immutable 8-byte canonical encoding; SHA3-256
hash is published in block headers.
Refuse(ctx, Op) reports whether op is admissible under the
profile bound to ctx.
Policy and enforcement are decomplected. Each constrained operation
(ECDSA precompile, pairing precompile, classical SNARK verifier)
calls Refuse once at its entry point and otherwise proceeds in its
own lane. The profile does not know how the operations compute; the
operations do not know how the profile is selected.
Presets:
Strict forbids every classical category — mainnet.
Permissive admits every operation — testnet, default for
unbound contexts.
Categories (Forbid* flags map 1:1):
CatECDSAContractAuth ECDSARecover, ECDSAVerify, Schnorr
CatClassicalSig Ed25519, X25519
CatPairingPrecompile BN254Pairing, BLS12381Pair, BLSSignature
CatKZGPrecompile KZGEval
CatClassicalSNARK Groth16, Plonk, Marlin
CatNonSHA3Hash SHA256, RIPEMD160, Blake2b, Blake2s, Keccak256
Strict profile hash (pinned in profile_test.go):
9d70a692103d09414ffb2577ca53852c99b2d13b987c49f20852899f9a0be348
Permissive profile hash:
cf7b7f49edcad4722838277dd310dcf6a61d0552ce0f2116ad39c3dcd23bd916
A change to either hash is a consensus-breaking change and requires a
canonical-encoding version bump.
Environment override: QUASAR_STRICT_PQ=1 selects Strict via
ProfileFromEnv. Mainnet binaries set it in their entrypoint.
31 unit tests; vet-clean.
32 lines
818 B
Go
32 lines
818 B
Go
package annulus
|
|
|
|
import (
|
|
"os"
|
|
"strings"
|
|
)
|
|
|
|
// EnvVar is the name of the single environment variable that selects
|
|
// the active profile at startup. Production binaries read it once in
|
|
// main and bind the resulting profile to their root context.
|
|
const EnvVar = "QUASAR_STRICT_PQ"
|
|
|
|
// truthy enumerates the values that ProfileFromEnv accepts as "set".
|
|
// Anything else, including the empty string, selects [Permissive].
|
|
var truthy = map[string]bool{
|
|
"1": true,
|
|
"true": true,
|
|
"on": true,
|
|
"yes": true,
|
|
"y": true,
|
|
}
|
|
|
|
// ProfileFromEnv returns [Strict] when [EnvVar] is set to a truthy
|
|
// value and [Permissive] otherwise. Comparison is case-insensitive.
|
|
func ProfileFromEnv() Profile {
|
|
v := strings.ToLower(strings.TrimSpace(os.Getenv(EnvVar)))
|
|
if truthy[v] {
|
|
return Strict()
|
|
}
|
|
return Permissive()
|
|
}
|