Repository navigation
Contract class ID in L2→L1 messages #61
benesjan
started this conversation in
AZIP Proposals
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
What follows should be quite complete but please let's not obsess with details now as I didn't spent much time on those since I would fist like feedback whether this is something we want to pursue.
Abstract
An L2→L1 message currently proves only the emitting contract's address. This proposal extends the message preimage with the emitting contract's class ID, injected and constrained by the protocol circuits (the private kernel for private execution, the AVM for public execution). L1 contracts consuming a message can then verify that it was emitted by an instance of a known contract class, enabling "one contract class → one L1 portal" applications. With the class ID being injected by the protocol circuits the L1 portal is then able to trust that the source message has been constructed correctly irrespective of the individual instance that emitted it.
Revelation is opt-in per message and not revealed by default reveals nothing beyond what messages reveal today. Revelation is restricted to instances that have never been updated via the
ContractInstanceRegistry— a class ID revealed by an updated instance would be unsound (see Security Considerations).Motivation
The rollup proof binds an L2→L1 message to
sender.actor— the emitting contract's address — and nothing else. The messagecontentis application-controlled, so placing a class ID there proves nothing: a contract of any class can claim any class ID.An Aztec address commits to its original class ID and initialization state, but through a derivation ending in a Grumpkin scalar multiplication. No EVM precompile covers Grumpkin, so L1 cannot recompute the address from a claimed class ID; the commitment is unopenable on L1 without a SNARK.
This blocks a natural class of applications: an L1 contract that trusts code rather than instances. Concrete example: a multi-asset withdrawal portal where each ERC20 has its own canonical L2 token instance — same class,
(portal, asset)as instance immutables — so any standard ERC20 works out of the box with no whitelist. The portal only needs to know that the withdrawal message came from an instance of the pinned class; the class's own code constrains everything else. Today the portal has no way to tell, forcing either an extra kernel iteration per operation (a canonical L2 hub emitting all messages) or a per-asset L1 registration transaction verified by a dedicated SNARK verifier.The kernel already derives the calling contract's class ID and constrains it — against the address for never-updated contracts, or against the
ContractInstanceRegistryfor updated ones — as part of verifying every private call. Exposing that already-proven value in the message preimage is a small change that removes the workaround cost entirely.Specification
reveal_class_idflag when emitting the message,class_idor zero based on the above flagContractInstanceRegistry.ContractInstanceRegistrycheck is cheap as the circuits already check it when dealing with contract upgrades.Aztec.nr interface
The existing emission functions are unchanged and never reveal — they leave the flag unset. Revelation is a separate, explicitly-named variant on both contexts:
On the private side the flag travels in the app circuit's public inputs and the kernel resolves it while scoping the message. On the public side the
SendL2ToL1Msgopcode gains a reveal flag (or a sibling opcode, as sketched) and the AVM resolves it the same way.L1 interface
Three pieces of
l1-contractsmust change in lockstep with the circuits:DataStructures.L2ToL1Msggains the class-ID field:The field lives on
L2ToL1Msgrather than onL2ActorbecauseL2Actoris shared withL1ToL2Msg(as its recipient), which this proposal does not touch.Hash.sha256ToField(L2ToL1Msg)must pack the fields in the exact byte order the circuits hash (class ID between sender address and rollup version, matching the preimage layout above):Outbox.consumetakesL2ToL1Msgas calldata, so extending the struct changes the function's ABI — a consumer-facing change for every portal (see Backwards Compatibility). The Outbox itself needs no new logic: the class ID is authenticated by the same Merkle membership check as every other field, and the existing checks onsender.version,recipient.actorandrecipient.chainIdare unchanged.Portal author requirements
A portal consuming class-attested messages MUST:
maybeSenderClassIdfor equality against a class ID pinned at portal deployment (or otherwise governed). A merely nonzero value proves only that some never-updated regular contract emitted the message and MUST NOT be accepted;maybeSenderClassId == 0as "no attestation" — the message is still authentic with respect tosender.actor, it just carries no class claim — and reject it rather than fall back to weaker checks;sender.actorfrom the message as the instance identity for any per-instance accounting, since a class-trusting portal by design accepts messages from every instance of the class.A portal need not re-check
sender.version,recipient.actor == msg.sender, orrecipient.chainId == block.chainid—Outbox.consumealready enforces all three.Backwards Compatibility
The change alters the preimage of every L2→L1 message and hence must ship as part of a new rollup version.
The consumer-facing break is the struct, not hash computation: portals do not hash L2→L1 messages — they construct a
DataStructures.L2ToL1Msgand pass it toOutbox.consume.Existing application-facing L2 interfaces for emitting messages are unchanged as this is purely an additive change Aztec.nr API-wise.
Security Considerations
Why updated instances cannot reveal
Instances are upgradeable:
ContractInstanceRegistry::updatelets an instance switch to any registered class, and state (public storage and notes) is siloed by address, not class. Without the never-updated restriction, an attacker deploys an instance under a malicious classB, usesB's code to write arbitrary values into the slots that a pinned classAinterprets (balances, initialized flags, …), then updates the instance toA: its messages now carryA's class ID while derived from stateAnever authored. A revealed class ID is therefore only sound if it speaks for the address's entire execution history — which is exactly what an empty registry entry proves.Weaker rules do not work:
current == original: anA → B → Aupdate round trip restores equality while leavingB-authored state behind. The registry entry, by contrast, is monotonic — updating back to the original class still leaves an entry — so only its absence proves that no foreign code ever ran at the address.Aand from the forged instance above become indistinguishable on L1, breaking the guarantee for honest senders too.Consequences for applications
Timing
The never-updated check is evaluated at emission time: the private kernel reads the registry entry as a
DelayedPublicMutableat the anchor block, with the tx'sinclude_by_timestampbounded before any scheduled change activates; the AVM reads it at block timestamp. Updates after emission do not retroactively affect a message — all state prior to an instance's first update was authored solely by the address-committed class.All reactions