singular-registry
LicenseApache-2.0
Safe HaskellNone
LanguageGHC2021

Singular.Registry.Trie.Pure

Description

Snapshots compute with rootFromDb, stateTrie, membershipFromDb and exclusionFromDb, without IO allocation. The legacy mkPureTrie and mkPureTrieFromRef names refer to the in-memory backend: their 'Trie IO' handles are mutable compatibility adapters, not pure computations.

The caller owns each adapter for one serial builder, replay or mirror lifetime. A shared IORef requires external serialization of the whole session, including reads and writes; these adapters provide no locking or thread-safety guarantee. Speculation belongs to the manager, not this handle.

All keys and values are hashed through MPF conventions (mkMPFHash) so proof paths match what the Aiken on-chain validator expects.

Synopsis

Construction

mkPureTrie :: IO (Trie IO) Source #

Create a new empty 'Trie IO' backed by a fresh IORef holding an empty in-memory MPF database.

mkPureTrieFromRef :: IORef MPFInMemoryDB -> Trie IO Source #

Build a 'Trie IO' from an existing IORef. The caller owns the reference and must serialize every session sharing it. Allows sharing the database with a TrieManager; this adds no synchronization.

Pure snapshot computations

getRootFromDb :: MPFInMemoryDB -> IO Root Source #

Get root hash from a database snapshot.

rootFromDb :: MPFInMemoryDB -> Root Source #

The pure root computation shared with the existing IO facade.

stateTrie :: Trie (State MPFInMemoryDB) Source #

The existing MPF operations in genuine State, with no IORef or IO.

membershipFromDb :: MPFInMemoryDB -> ByteString -> Maybe ByteString Source #

The serialized membership proof produced from the authenticated nodes.

exclusionFromDb :: MPFInMemoryDB -> ByteString -> Maybe (MPFExclusionProof MPFHash) Source #

An exclusion proof produced from the same authenticated nodes.

verifyExclusion :: MPFExclusionProof MPFHash -> ByteString -> Bool Source #

Check an exclusion proof against its key and the caller's selected root.

Proofs against a trusted root

provesMember :: MPFInMemoryDB -> ByteString -> ByteString -> ByteString -> Bool Source #

Whether the tree nodes of a database prove this key bound to this value under a trusted root (#299). Only the tree the root commits to is read, never the key index kept beside it, and the proof is checked in the encoding the on-chain validator folds, against the trusted root rather than the database's own.

provesAbsent :: MPFInMemoryDB -> ByteString -> ByteString -> Bool Source #

Whether the tree nodes of a database prove this key bound to nothing under a trusted root (#299), from the tree alone, as provesMember does. The all-zero root is the empty tree's.