You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Three platform gaps that block cross-implementation Midnight standards
#260
These came out of rewriting MIP #214 as a protocol-first specification rather than a Compact contract. Each one blocks something a standard needs to be able to say, each affects any Midnight standard rather than only ours, and each has a small concrete fix. Raising them here rather than on the PR, since none of them are specific to it.
Summary
While rewriting a Standards-track MIP so that it specifies a protocol rather than a Compact contract, we hit three places where the platform's behaviour is load-bearing for the standard but is not published. Each one blocks something a standard needs to be able to say, each affects any Midnight standard rather than only ours, and each has a small, concrete fix.
#
Gap
What it blocks
Severity
1
Contract self-address is unavailable during construction
Per-instance domain separation sealed at deploy
Workaround exists, but it is load-bearing and unenforceable
2
No published byte framing for persistentHash / persistentCommit
Any standard built on these primitives being implemented outside Compact
Recoverable by probing, which no standards author should have to do
3
Authenticated-structure internals unpublished
Any standard specifying cross-implementation membership or absence proofs
Not recoverable; hard blocker
Taken together they define a clean line through what can be standardized on Midnight today. The credential-style cryptographic layer can be fully specified and is interoperable. Anything touching the authenticated structures cannot be, and per-deployment identity has to be supplied by the deployer rather than derived. We think that line is in the wrong place, and moving it is inexpensive.
Each finding below carries a concrete ask and an offer of what we will write for it. In short: for finding 2 we already have the text and can open a docs PR this week; for finding 3 we will write the component MIP once the internals are published; for finding 1 we will write the proposal if there is appetite, or the documentation note if the constraint is intrinsic. We would rather be corrected on any of it than have each standards author rediscover it privately.
1. Contract self-address is unavailable during construction
Observation. A constructor circuit is proven before the contract address exists, because the address is derived from the deploy transaction that embeds the constructor's initial state. kernel.self() therefore resolves to a dummy value inside a constructor.
How established. Two deployments sharing an issuer identity and schema, deriving a namespace from kernel.self() in the constructor, produced byte-identical namespaces. The intended per-instance separation silently did not happen.
Why it generalizes. Any contract that wants an instance-unique domain sealed at deployment currently cannot derive it from its own identity. This is a common pattern: it is how you stop a commitment, credential, or note issued against one deployment from being replayed against another. The failure mode is the dangerous kind, because it produces a plausible value rather than an error.
What we did instead. The deployer supplies a deploymentSalt constructor parameter that MUST be unique. This works, but the requirement is load-bearing, unenforceable on-chain, and now has to be carried as a normative caveat in the standard and repeated by every integrator.
Ask. Either a construction-time binding to the eventual contract address, or a protocol-supplied per-deployment nonce available to the constructor. Either would let the salt requirement be dropped and would remove the same footgun from every other contract that needs instance separation.
What we can contribute. If there is appetite for the protocol-supplied nonce, we will write the MPS and MIP for it, and carry the deployer-salt pattern in our own standard as the documented interim workaround so nothing is blocked on the change landing. If the constraint is considered intrinsic instead, a one-paragraph note in the kernel.self() documentation saying it is unavailable in a constructor would have saved us the experiment, and we will open that docs PR.
2. No published byte framing for the persistent hash and commitment primitives
Observation. The standard library documents persistentHash as "guaranteed to persist between upgrades, and to consistently use the SHA-256 compression algorithm", and persistentCommit similarly. What is not documented is how a Compact value is serialized into the SHA-256 input. Without that, the guarantee cannot be consumed by a specification: a standard can say its commitment is "SHA-256 based" and still be un-implementable by anyone not using Compact.
This is worth stating plainly, because the platform has already made the harder commitment. Stability across upgrades is a compatibility promise. Publishing the framing is what makes that promise expressible downstream.
How established. Probing a compiled contract against candidate framings:
Plain concatenation of 32-byte fields, no length prefix, no type tag, and in the commitment the opening comes first. Reproduction in the appendix.
Why it generalizes. Every Midnight standard that commits to or derives from anything, which is most of them, is built on these two primitives. Until the framing is published, each such standard must either restrict itself to Compact implementations, or do what we did and recover the framing by experiment and state it normatively on the platform's behalf. Neither is a good outcome for an ecosystem that wants independent wallets, verifiers, and indexers.
What we did instead. Stated the framing normatively in the MIP, pinned it with conformance vectors, and wrote an implementation from the specification alone using nothing but a standard-library SHA-256. It reproduced all nine published vectors, which is the evidence that the framing is right and that the standard is implementable. But the standard now asserts a platform behaviour rather than citing it.
Ask. Publish the serialization for persistentHash and persistentCommit: field widths, concatenation order, the position of the commitment opening, and the treatment of non-Bytes<32> types. It is a short document and it unblocks every standard at once.
What we can contribute, immediately. We have already written this text, because our standard needed it. We can open a midnight-docs PR this week adding the serialization to the standard-library reference, in the form above, together with the test vectors that pin it. Someone who knows the implementation would need to confirm it and extend it to the types we did not probe, which is the part we cannot do. The offer stands whether you take our wording or use it only as a starting point, and we would rather be corrected than have every standards author repeat the experiment privately.
3. Authenticated-structure internals are unpublished, and are a different primitive family
Observation. The gap here is larger than in finding 2, where the algorithm is documented and only the framing was missing. For the platform's Merkle structures:
roots and path siblings are field elements, not byte strings;
the empty-subtree digest is the zero field element;
path entries carry a sibling field element and a direction bit;
the node compression function is a circuit-optimised, field-native hash that is not documented at all.
How established. Reading roots and paths directly from ledger state on a live deployment. An empty tree's root is field 0; after a single insertion the root was, for one particular leaf, 25947365779665250145655892949531802268655526679415660917826040302073413385386. That value is illustrative of the form and magnitude rather than a vector to reproduce; the point is that it is a ~2^254 field element and not a 32-byte digest.
Why it generalizes. This is not recoverable the way finding 2 was. Recovering it would mean identifying an algebraic hash together with its parameters, and we do not think a Standards-track document should reverse-engineer and freeze an undocumented primitive. The consequence is that no Midnight standard can currently specify a cross-implementation membership or absence proof. That rules out interoperable revocation, allowlists, credential registries, anonymity sets, and anything else whose verification depends on agreeing about a tree.
What we did instead. The standard specifies the leaf layer, which is expressible in SHA-256 and is fully interoperable, and explicitly declines to specify the tree layer. To keep that from becoming a silent incompatibility, registries must declare an implementation-identifying identifier alongside the logical one, under normative rules requiring it to be authenticated, immutable, unambiguous, canonically compared, and changed whenever the underlying behaviour changes. That converts an invisible failure into a detectable one. It is the best available outcome, and it is strictly worse than being able to specify the thing.
Ask. Publish, for each authenticated structure: the node compression function and the field it operates over, the empty-subtree convention, the leaf-placement and indexing rules, sibling ordering within a path, root derivation, and the proof encoding. That would let a properly specified authenticated-structure component be defined once and reused by every standard that needs membership or absence proofs.
What we can contribute. We cannot write this one, because unlike finding 2 it is not recoverable from the outside. What we will do, given the published internals, is write the authenticated-structure component MIP itself: a named, versioned component that any standard can reference instead of each one re-deriving tree semantics, with conformance vectors in the same form as the ones we published for the credential layer. We have already built the surrounding machinery for it, since our standard has the two-part declaration that such a component would slot into. If it is more useful for that specification to live in platform documentation rather than as a MIP, we are equally happy to contribute it there.
Why the three belong together
They stratify cleanly:
Finding 2 governs whether the value layer of a standard can be specified. Currently yes, but only by experiment.
Finding 3 governs whether the proof layer can be specified. Currently no.
Finding 1 governs whether an instance can be identified without trusting the deployer. Currently no.
A standard can therefore be interoperable about what a credential is, but not about proving anything concerning it, and not about which deployment it belongs to without an out-of-band promise. Closing 2 and 3 in particular would move Midnight from "standards describe one implementation" to "standards describe a protocol", which is the difference between an ecosystem that can have independent wallets and verifiers and one that cannot.
Appendix: reproduction
Toolchain: compactc 0.31.0, language 0.23.0, runtime 0.16.x.
Finding 2. Compile a pure-circuit probe and compare against SHA-256 candidates:
With A = 0x11 * 32, B = 0x22 * 32, R = 0x33 * 32, the outputs equal SHA256(A), SHA256(A||B), and SHA256(R||A||B) respectively.
Finding 3. Deploy any contract with a MerkleTree or HistoricMerkleTree in its ledger, then read root() before and after an insertion. The returned value is { field: <bigint> }, not a byte string, and the empty-tree root is field 0. pathForLeaf(...) returns entries of the form { sibling: { field }, goes_left: bool }.
Finding 1. Deploy the same contract twice with identical constructor arguments, deriving a sealed namespace from kernel.self(). Compare the sealed values: they are identical.
Handle encoding note (secondary).Uint<248> -> Field -> Bytes<32> is 32-byte little-endian, byte 31 always zero, byte 30 fully significant; the accepted domain is [0, 2^248) and 2^248 is a compile-time type error. Little-endian is the opposite of the convention most credential and hashing specifications assume, so it is worth documenting explicitly alongside finding 2.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
These came out of rewriting MIP #214 as a protocol-first specification rather than a Compact contract. Each one blocks something a standard needs to be able to say, each affects any Midnight standard rather than only ours, and each has a small concrete fix. Raising them here rather than on the PR, since none of them are specific to it.
Summary
While rewriting a Standards-track MIP so that it specifies a protocol rather than a Compact contract, we hit three places where the platform's behaviour is load-bearing for the standard but is not published. Each one blocks something a standard needs to be able to say, each affects any Midnight standard rather than only ours, and each has a small, concrete fix.
persistentHash/persistentCommitTaken together they define a clean line through what can be standardized on Midnight today. The credential-style cryptographic layer can be fully specified and is interoperable. Anything touching the authenticated structures cannot be, and per-deployment identity has to be supplied by the deployer rather than derived. We think that line is in the wrong place, and moving it is inexpensive.
Each finding below carries a concrete ask and an offer of what we will write for it. In short: for finding 2 we already have the text and can open a docs PR this week; for finding 3 we will write the component MIP once the internals are published; for finding 1 we will write the proposal if there is appetite, or the documentation note if the constraint is intrinsic. We would rather be corrected on any of it than have each standards author rediscover it privately.
1. Contract self-address is unavailable during construction
Observation. A constructor circuit is proven before the contract address exists, because the address is derived from the deploy transaction that embeds the constructor's initial state.
kernel.self()therefore resolves to a dummy value inside a constructor.How established. Two deployments sharing an issuer identity and schema, deriving a namespace from
kernel.self()in the constructor, produced byte-identical namespaces. The intended per-instance separation silently did not happen.Why it generalizes. Any contract that wants an instance-unique domain sealed at deployment currently cannot derive it from its own identity. This is a common pattern: it is how you stop a commitment, credential, or note issued against one deployment from being replayed against another. The failure mode is the dangerous kind, because it produces a plausible value rather than an error.
What we did instead. The deployer supplies a
deploymentSaltconstructor parameter that MUST be unique. This works, but the requirement is load-bearing, unenforceable on-chain, and now has to be carried as a normative caveat in the standard and repeated by every integrator.Ask. Either a construction-time binding to the eventual contract address, or a protocol-supplied per-deployment nonce available to the constructor. Either would let the salt requirement be dropped and would remove the same footgun from every other contract that needs instance separation.
What we can contribute. If there is appetite for the protocol-supplied nonce, we will write the MPS and MIP for it, and carry the deployer-salt pattern in our own standard as the documented interim workaround so nothing is blocked on the change landing. If the constraint is considered intrinsic instead, a one-paragraph note in the
kernel.self()documentation saying it is unavailable in a constructor would have saved us the experiment, and we will open that docs PR.2. No published byte framing for the persistent hash and commitment primitives
Observation. The standard library documents
persistentHashas "guaranteed to persist between upgrades, and to consistently use the SHA-256 compression algorithm", andpersistentCommitsimilarly. What is not documented is how a Compact value is serialized into the SHA-256 input. Without that, the guarantee cannot be consumed by a specification: a standard can say its commitment is "SHA-256 based" and still be un-implementable by anyone not using Compact.This is worth stating plainly, because the platform has already made the harder commitment. Stability across upgrades is a compatibility promise. Publishing the framing is what makes that promise expressible downstream.
How established. Probing a compiled contract against candidate framings:
Plain concatenation of 32-byte fields, no length prefix, no type tag, and in the commitment the opening comes first. Reproduction in the appendix.
Why it generalizes. Every Midnight standard that commits to or derives from anything, which is most of them, is built on these two primitives. Until the framing is published, each such standard must either restrict itself to Compact implementations, or do what we did and recover the framing by experiment and state it normatively on the platform's behalf. Neither is a good outcome for an ecosystem that wants independent wallets, verifiers, and indexers.
What we did instead. Stated the framing normatively in the MIP, pinned it with conformance vectors, and wrote an implementation from the specification alone using nothing but a standard-library SHA-256. It reproduced all nine published vectors, which is the evidence that the framing is right and that the standard is implementable. But the standard now asserts a platform behaviour rather than citing it.
Ask. Publish the serialization for
persistentHashandpersistentCommit: field widths, concatenation order, the position of the commitment opening, and the treatment of non-Bytes<32>types. It is a short document and it unblocks every standard at once.What we can contribute, immediately. We have already written this text, because our standard needed it. We can open a
midnight-docsPR this week adding the serialization to the standard-library reference, in the form above, together with the test vectors that pin it. Someone who knows the implementation would need to confirm it and extend it to the types we did not probe, which is the part we cannot do. The offer stands whether you take our wording or use it only as a starting point, and we would rather be corrected than have every standards author repeat the experiment privately.3. Authenticated-structure internals are unpublished, and are a different primitive family
Observation. The gap here is larger than in finding 2, where the algorithm is documented and only the framing was missing. For the platform's Merkle structures:
How established. Reading roots and paths directly from ledger state on a live deployment. An empty tree's root is field
0; after a single insertion the root was, for one particular leaf,25947365779665250145655892949531802268655526679415660917826040302073413385386. That value is illustrative of the form and magnitude rather than a vector to reproduce; the point is that it is a ~2^254 field element and not a 32-byte digest.Why it generalizes. This is not recoverable the way finding 2 was. Recovering it would mean identifying an algebraic hash together with its parameters, and we do not think a Standards-track document should reverse-engineer and freeze an undocumented primitive. The consequence is that no Midnight standard can currently specify a cross-implementation membership or absence proof. That rules out interoperable revocation, allowlists, credential registries, anonymity sets, and anything else whose verification depends on agreeing about a tree.
What we did instead. The standard specifies the leaf layer, which is expressible in SHA-256 and is fully interoperable, and explicitly declines to specify the tree layer. To keep that from becoming a silent incompatibility, registries must declare an implementation-identifying identifier alongside the logical one, under normative rules requiring it to be authenticated, immutable, unambiguous, canonically compared, and changed whenever the underlying behaviour changes. That converts an invisible failure into a detectable one. It is the best available outcome, and it is strictly worse than being able to specify the thing.
Ask. Publish, for each authenticated structure: the node compression function and the field it operates over, the empty-subtree convention, the leaf-placement and indexing rules, sibling ordering within a path, root derivation, and the proof encoding. That would let a properly specified authenticated-structure component be defined once and reused by every standard that needs membership or absence proofs.
What we can contribute. We cannot write this one, because unlike finding 2 it is not recoverable from the outside. What we will do, given the published internals, is write the authenticated-structure component MIP itself: a named, versioned component that any standard can reference instead of each one re-deriving tree semantics, with conformance vectors in the same form as the ones we published for the credential layer. We have already built the surrounding machinery for it, since our standard has the two-part declaration that such a component would slot into. If it is more useful for that specification to live in platform documentation rather than as a MIP, we are equally happy to contribute it there.
Why the three belong together
They stratify cleanly:
A standard can therefore be interoperable about what a credential is, but not about proving anything concerning it, and not about which deployment it belongs to without an out-of-band promise. Closing 2 and 3 in particular would move Midnight from "standards describe one implementation" to "standards describe a protocol", which is the difference between an ecosystem that can have independent wallets and verifiers and one that cannot.
Appendix: reproduction
Toolchain: compactc 0.31.0, language 0.23.0, runtime 0.16.x.
Finding 2. Compile a pure-circuit probe and compare against SHA-256 candidates:
With
A = 0x11 * 32,B = 0x22 * 32,R = 0x33 * 32, the outputs equalSHA256(A),SHA256(A||B), andSHA256(R||A||B)respectively.Finding 3. Deploy any contract with a
MerkleTreeorHistoricMerkleTreein its ledger, then readroot()before and after an insertion. The returned value is{ field: <bigint> }, not a byte string, and the empty-tree root is field0.pathForLeaf(...)returns entries of the form{ sibling: { field }, goes_left: bool }.Finding 1. Deploy the same contract twice with identical constructor arguments, deriving a sealed namespace from
kernel.self(). Compare the sealed values: they are identical.Handle encoding note (secondary).
Uint<248> -> Field -> Bytes<32>is 32-byte little-endian, byte 31 always zero, byte 30 fully significant; the accepted domain is[0, 2^248)and2^248is a compile-time type error. Little-endian is the opposite of the convention most credential and hashing specifications assume, so it is worth documenting explicitly alongside finding 2.All reactions