Constrain preimage request lengths below state-key discriminators - #542
Constrain preimage request lengths below state-key discriminators#542philoniare wants to merge 3 commits into
Conversation
|
We should name the set of allowed preimage lengths rather than repeating |
|
@zdave-parity Done — added |
zdave-parity
left a comment
There was a problem hiding this comment.
Thanks, just a few minor nits.
| \using \sq{o, l, \sa¬minaccgas, \sa¬minmemogas, \sa¬gratis, \local¬desiredid} &= \registers\subrange{7}{6} \\ | ||
| \using \sa¬codehash &= \begin{cases} | ||
| \memory\subrange{o}{32} &\when \Nrange{o}{32} \subseteq \readable{\memory} \wedge l \in \Nbits{32} \\ | ||
| \memory\subrange{o}{32} &\when \Nrange{o}{32} \subseteq \readable{\memory} \wedge l \in \preimagelen \\ |
There was a problem hiding this comment.
I think the l check here can just be dropped as it is now covered below?
| \item[$\balance$] The set of balance values. Equivalent to $\Nbits{64}$. See equation \ref{eq:balance}. | ||
| \item[$\gas$] The set of unsigned gas values. Equivalent to $\Nbits{64}$. See equation \ref{eq:gasregentry}. | ||
| \item[$\bloblength$] The set of blob length values. Equivalent to $\Nbits{32}$. See section \ref{sec:numbers}. | ||
| \item[$\preimagelen$] The set of lengths under which a preimage may be solicited. A subset of $\bloblength$, equivalent to $\Nmax{2^{32} - 2}$. See equation \ref{eq:serviceaccounts}. |
There was a problem hiding this comment.
Each line in a \begin{align} gets a separate equation number, so the ref here is not quite correct; we should add a separate label for the \preimagelen equation.
| As we already noted, a service in \Jam is somewhat analogous to a smart contract in Ethereum in that it includes amongst other items, a code component, a storage component and a balance. Unlike Ethereum, the code is split over two isolated entry-points each with their own environmental conditions; one, \emph{Refinement}, is essentially stateless and happens in-core, and the other, \emph{Accumulation}, which is stateful and happens on-chain. It is the latter which we will concern ourselves with now. | ||
|
|
||
| Service accounts are held in state under $\accounts$, a partial mapping from a service identifier $\serviceid$ into a tuple of named elements which specify the attributes of the service relevant to the \Jam protocol. Formally: | ||
| Service accounts are held in state under $\accounts$, a partial mapping from a service identifier $\serviceid$ into a tuple of named elements which specify the attributes of the service relevant to the \Jam protocol. We further name $\preimagelen$, the set of lengths under which a preimage may be solicited; this is the subset of $\bloblength$ omitting its two greatest values, since these are reserved as the discriminators of storage and preimage items respectively in the state-key derivation of section \ref{sec:statemerklization}. Formally: |
There was a problem hiding this comment.
I would move the \preimagelen description and definition further down, beside or after \serviceaccount? They seem out of place here. You could also reference the T equation directly rather than just referencing the section?
There was a problem hiding this comment.
Moved below \serviceaccount and included the reference to the equation
Thanks for the review, addressed all of the points |
Summary
Request lengths
l ∈ 𝔹_Ladmit the values2³²−1and2³²−2, which are thestate-key discriminators for the storage and preimages rows. A request
⟨h, 2³²−1⟩therefore produces aC-input byte-identical to storage keyk = h, givingT(σ)two values for one key — ill-typed state with nodeterministic resolution, reachable via a single
solicit. We reproduced thecollision with our client implementation, which accepts the sentinel lengths
and derives the identical trie key.
Changes
accounts.tex: restrict the request length domain from𝔹_Ltoℕ_{2³²−2}.pvm_invocations.tex: enforce the bound insolicit,forget,query,provide(HUHguard tightened) andnew(HUHcase added; code-hashguard tightened, since the created account solicits its own code as
⟨c, l⟩).Behavioral note
newpreviously panicked forl ≥ 2³²; it now returnsHUH, matching theother preimage host calls.