Skip to content

Add cheap memory slices abstraction (with slice_/truncate)#453

Merged
rodrigogribeiro merged 3 commits into
argotorg:mainfrom
axic:slices
Jun 12, 2026
Merged

Add cheap memory slices abstraction (with slice_/truncate)#453
rodrigogribeiro merged 3 commits into
argotorg:mainfrom
axic:slices

Conversation

@axic

@axic axic commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

No description provided.

Comment thread std/std.solc Outdated

// 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);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
  )
)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we agree with this design, I'd like to remove data slice(t) to avoid naming conflict (and not have slice_ here).

@axic axic force-pushed the slices branch 2 times, most recently from f957054 to 9efe99e Compare June 11, 2026 13:32
@axic axic marked this pull request as ready for review June 11, 2026 13:33
@axic axic force-pushed the slices branch 2 times, most recently from 04955fd to 92d5800 Compare June 11, 2026 14:41
claude and others added 2 commits June 11, 2026 16:47
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>

@rodrigogribeiro rodrigogribeiro left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@rodrigogribeiro rodrigogribeiro merged commit f5e1d3b into argotorg:main Jun 12, 2026
4 checks passed
@axic axic deleted the slices branch June 12, 2026 12:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants