-
Notifications
You must be signed in to change notification settings - Fork 120
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[NCC-E005955-M2F] zebra-chain
: Check that header block version field is valid when serializing blocks
#497
Comments
Removing open-to-contributors on this one based on henry's comment pending further discussion in today's gardening session |
Comment from Henry says "not sure about that one" but nothing more. I think we should detail further. |
I think the issue is that this depends on generating blocks which is something we don't have implemented yet, but I'm not sure, @hdevalence? |
I am asking because if that is the case i think we could still check the version in the receiving side just as we did with header_solution and coinbase. |
The BlockVerifier checks the version on blocks as of PR #748. |
Oops, that's not correct, I misread the code. Note: generated blocks aren't part of the "sync and validate" milestone. They only happen if we implement mining. |
We don't plan on generating blocks any time soon. |
This came up in the audit: there is a missing check in the block header version serialize function. |
zebra-chain
: Check that header block version field is valid when serializing blocks
Impact
Zebra assumes all serialization/deserialization functions cannot produce invalid data. Unenforced constraints violate this assumption and may affect consensus or interoperability.
Description
Zebra implements the
ZCashSerialize
trait for consensus-critical data.zebra/zebra-chain/src/serialization/zcash_serialize.rs
Lines 19 to 30 in 5a88fe7
Note the highlighted requirement that illegal states must be unrepresentable.
The function
zcash_deserialize()
forHeader
contains historical information regarding the version field of the header. In particular, it specifies that the only valid version number is 4, but that incorrect implementations in the past resulted in several blocks with an incorrect value. The function has some special case handling for this, as well as an explicit check that the parsed version is greater than or equal to 4:zebra/zebra-chain/src/block/serialize.rs
Lines 75 to 82 in 5a88fe7
This is similarly captured in other annotations for the version field, where it is specified that:
In comparison, the corresponding
zcash_deserialize()
function does not perform validation on the version field:zebra/zebra-chain/src/block/serialize.rs
Lines 28 to 43 in 5a88fe7
No instances within the codebase will currently set this value incorrectly, but it appears to be a violation of the specified constraint. It is possible to construct a
Header
such that the output ofzcash_serialize
will not correctly deserialize within Zebra.Recommendation
Align the constraint checks for the version field such that any serialized Header will correctly deserialize without an error.
Location
zebra-chain/src/block/serialize.rs
Original issue description
Once Zebra starts generating its own blocks, we'll need to do the version check in a few more places:
This task is open to contributors, but some parts of it depend on future Zebra features.
The text was updated successfully, but these errors were encountered: