unpackAndVerify enforces verify-then-unpack by statement order: verifyNarHash and verifyNarSize run before deserialise and the disk writes, but the NAR bytes have the same ByteString type before and after verification, so nothing structural prevents a future call path from reaching the unpack sink with unverified bytes. The exported surface (unpackNarEntry, NAR.deserialise) likewise accepts any bytes.
A VerifiedNar wrapper (constructed only by the verification pipeline, consumed by the unpack path) turns the ordering into a type. Small, local to the substituter; the main design question is whether the wrapper carries the decoded declared hash (pairing with the registration record) or stays a bare witness.
From the #85 audit (cache subsystem).
unpackAndVerifyenforces verify-then-unpack by statement order:verifyNarHashandverifyNarSizerun beforedeserialiseand the disk writes, but the NAR bytes have the sameByteStringtype before and after verification, so nothing structural prevents a future call path from reaching the unpack sink with unverified bytes. The exported surface (unpackNarEntry,NAR.deserialise) likewise accepts any bytes.A
VerifiedNarwrapper (constructed only by the verification pipeline, consumed by the unpack path) turns the ordering into a type. Small, local to the substituter; the main design question is whether the wrapper carries the decoded declared hash (pairing with the registration record) or stays a bare witness.From the #85 audit (cache subsystem).