-
Notifications
You must be signed in to change notification settings - Fork 60
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
ChainMmr
does not guarantee it tracks valid block headers
#1173
Comments
Yes, for correctness this shouldn't be an issue but it would be good to catch errors before we get to executing MASM as by the time we get there, reverting things may become quite expensive. So, I agree that We could probably have two different ways of constructing
|
I'd like to give this a shot if available |
Is this close to something we want here? I'm not sure if I've got the right values for the |
Thanks @varun-doshi for offering to take this issue. I think this issue may not be a good fit due to the dependency of this API with miden-node, i.e. we have to design this API in concert with how it is used in miden-node. If you'd like to drive #1145 instead, that'd be a big help too! |
A
ChainMmr
is a wrapper around aPartialMmr
and a map ofBlockHeader
s. The way we use it is to usually check whether the mmr's hashed peaks equals the reference block of a tx/batch/block and then "verify" that some block is tracked by checking whether the map of headers contains the block number.It is not documented on
ChainMmr
whether it is supposed to guarantee that it only contains headers which are in the MMR, but the way we use it strongly suggest it does. However in that case, I would expect this test to pass, i.e.ChainMmr::new
to return an error:However it doesn't and instead returns
Ok(ChainMmr)
. Innew
, we only check whether the passed header's block number is tracked in the mmr, not whether the tracked header's hash matches the passed one. So this allows passing an incorrect block header whose number matches an actually tracked header's number.The question is, is this intended? Probably not the way we use it.
I think ChainMmr should guarantee that it only contains valid headers, but the fix is not straightforward, afaict, because PartialMmr doesn't allow for the hash equality check because it does not track the leaves, only authentication paths.
I would suggest to:
Document what
ChainMmr
guarantees (and/or what it doesn't).Revisit how
ChainMmr
is constructed. Maybenew
should return an empty data structure and the type should expose anfn track(&mut self, header_witness: BlockHeaderWitness)
method withBlockHeaderWitness { header: BlockHeader, mmr_proof: MmrProof }
. In that method, we add the header's hash to the MMR at the header's block num with the given merkle path from the proof. That way, it would be impossible for an invalid block header to end up in theChainMmr
without the hashed peaks also being different.Or maybe we want a
new
function to take animpl Iterator<BlockHeaderWitness>
in case we ever want to parallelize something.This might need some more investigation overall, and if we work on this, we should verify that the
ChainMmr
can be built easily inget_batch_inputs
andget_block_inputs
in miden-node.Finally, I assume this is not an issue for overall correctness, because the MASM code must ultimately be correct and the way the MMR works there does not depend on
ChainMmr
correctness. I think if an invalid block header was in the advice provider, it would be detected there, but may be good to double check.The text was updated successfully, but these errors were encountered: