Always use a normal segment for first SegmentArena segment #1845
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
(Note that this is basically a clone of Moonsong-Labs#45. We'd love to get this accepted upstream if possible.)
Problem: Starknet OS expects SegmentArena segments to all be temporary except the first segment, which must be normal. This is so that relocation rules for all segments can chain back into the first.
Solution: Use temporary segments only if it's not the first.
Description
The Starknet OS verifies the continuity of the segments in
SegmentArena
s here, which requires relocation rules to be properly set up.The requirements for this to work are that each
src_ptr
is a temporary segment and eachdest_ptr
is a non-temporary segment (or a temporary segment with an existing rule mapping it to a non-temporary segment).cairo-vm
uses a number of hints to accomplish this, and these are injected by the sierra-to-casm compiler. However, it relies on one additional hint which is not injected anywhere in the case of SNOS.This hint seems to ensure the same condition needed in SNOS: that the initial segment is a normal segment and that all other segments are temporary segments with relocation rules pointing back to the initial one. However, it creates the normal segment inside this last hint rather than when the SegmentArena is initialized.
SNOS handles this by simply allocating the initial segment as a normal one as explained here. This seems to alleviate the need to later recreate the segment in
relocate_all_segments()
, allowing the implementation to work in SNOS without the hint mentioned above.Checklist