Add cheap memory slices abstraction (with slice_/truncate)#453
Merged
Conversation
axic
commented
Jun 10, 2026
|
|
||
| // This is a very cheap abstraction over a memory area of [ptr, ptr+len) | ||
| // No type information is preserved. | ||
| data memory_slice = memory_slice(word, word); |
Contributor
Author
There was a problem hiding this comment.
I tried a parametric version (which is started earlier in the file with data slice(t), but that becomes so much more complicated and loses a ton of flexibility (like the fact this can be nested).
I very much prefer this option, but let me know. It may be also better called memory_ref and not a slice.
With this design we can do the following (nested to_bytes/concat/truncate/slice/hashing functions):
to_bytes(
truncate(
slice_(
concat(truncate(a, 1)), b),
2
),
5
)
)
Contributor
Author
There was a problem hiding this comment.
If we agree with this design, I'd like to remove data slice(t) to avoid naming conflict (and not have slice_ here).
f957054 to
9efe99e
Compare
04955fd to
92d5800
Compare
Adds test/examples/dispatch/slice.{solc,json} exercising the new
memory_slice slice_/truncate functions composed with concat, to_bytes,
and the (now generic) keccak256_/sha256 precompiles.
Covers: slice/truncate of a memory(bytes), of a concat result, the
nested truncate(slice_(concat(...))) window, slices as concat operands,
re-sliced memory_slices, and hashing a slice with zero copy. Includes
identity, zero-length, sub-word, >32-byte, and OutOfBounds revert cases.
Hash goldens are anchored to the canonical "abc"/empty keccak256 and
sha256 test vectors already used by hashes.json. Registered in
run_contests.sh.
Co-authored-by: Alex Beregszaszi <alex@rtfs.hu>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
No description provided.