refactor: add stack comments to claim_batch_pipe_double_words#2620
refactor: add stack comments to claim_batch_pipe_double_words#2620partylikeits1983 wants to merge 4 commits intoagglayerfrom
claim_batch_pipe_double_words#2620Conversation
claim_batch_pipe_double_words
mmagician
left a comment
There was a problem hiding this comment.
We should not remove the current invocation of claim_batch_pipe_double_words, but leaf data is piped to memory twice now:
claim->claim_batch_pipe_double_words(piped viapipe_double_words_preimage_to_memory)claim->verify_leaf_bridge->get_leaf_value-> (piped viapipe_preimage_to_memory)
Since both happen within the AggLayerBridge account context, the latter is not necessary
|
Seems like changes from this PR are already in the |
Good catch. I did a really deep dive into this and here's what's going on: Why leaf data is piped twiceThe leaf data pipe in The data at addr 536 (from So the second pipe to addr 0 is effectively a memcpy, it creates a sacrificial copy that Proof data is also piped twiceNote that it's not just leaf data, proof data is also piped to memory twice:
The first pipe serves as the integrity/sanity check. The second pipe in Can we remove the double pipe?Yes, the double pipe of leaf data can be removed. I prototyped the change and all tests pass, however, there are some trade offs. The approach:
Alternatively, we could refactor Why I think we should keep the code as isThe double pipe costs extra cycles, but it keeps the code clearer. The current Removing the double pipe would require changing the expected API of This is a valid optimization but the tradeoff is reduced clarity for ~cycle savings. What do you think @mmagician @bobbinth ? |
|
Thanks for the investigation.
I agree this would be the cleanest approach to not overwrite memory but instead write to a different pointer location.
So we can remove one of the writes of proof data - it sounds like that one is clear?
|
I think we may even be able to use the local memory of Also (and not for this PR), I think we may be able to simplify the This is because multiplying this value by |
This PR adds stack comments to
claim_batch_pipe_double_words, and was an opportunity to research if the call tomem::pipe_double_words_preimage_to_memoryforPROOF_DATA_KEYis necessary in theclaim_batch_pipe_double_wordsprocedure.The purpose of this PR is to close #2237 specifically point 5:
@bobbinth left a comment here regarding the old state of the
claim_batch_pipe_double_wordsprocedure. In the comment, it is pointed out that it is not necessary to callexec.mem::pipe_double_words_preimage_to_memoryfor thePROOF_DATA_KEY, which is technically true.This is the current state of the
claim_batch_pipe_double_wordsprocedure:It is possible to remove the call to
mem::pipe_double_words_preimage_to_memoryfor thePROOF_DATA_KEY, however, I think we should keep this call.Why? Because the bridge should not have to trust that the
CLAIMnote (or the note calling theclaimprocedure), correctly insertedPROOF_DATAunderPROOF_DATA_KEYin theAdviceMap. This call tomem::pipe_double_words_preimage_to_memoryis in effect a sanity check. If we removed it, it's unlikely to open a possible vulnerability, however, I think we should keep it, unless there is a strong reason to remove it. Removing it would save around ~257 cycles.Essentially this call to
mem::pipe_double_words_preimage_to_memorymakes it so that thebridge_incomponent does not have to trust that the note which called theclaimprocedure correctly insertedPROOF_DATAunderPROOF_DATA_KEYin theAdviceMap.Closes #2237