Skip to content

feat(utils): add high-speed Yul byte swapping utility - #760

Merged
mijinummi merged 1 commit into
MDTechLabs:mainfrom
rabsqueen:feat/748-yul-byte-swapper
Aug 20, 2026
Merged

feat(utils): add high-speed Yul byte swapping utility#760
mijinummi merged 1 commit into
MDTechLabs:mainfrom
rabsqueen:feat/748-yul-byte-swapper

Conversation

@rabsqueen

Copy link
Copy Markdown
Contributor

Summary

Implements #748 by adding a high-performance Yul utility for reversing
the byte order of 256-bit words.

Changes

  • Added YulByteSwapper library.
  • Implemented 32-byte endian reversal using inline Yul assembly.
  • Uses fixed SHR, SHL, AND, and OR operations.
  • No loops or memory-buffer allocation.
  • Added bytes32 and uint256 interfaces.
  • Added a test harness for exercising the internal library functions.
  • Added known-value, edge-case, high-level-reference, and inverse-operation tests.

Performance

The implementation performs byte reversal in constant time using
a fixed sequence of bitwise operations:

  1. 8-bit group swap
  2. 16-bit group swap
  3. 32-bit group swap
  4. 64-bit group swap
  5. 128-bit half swap

There are no dynamic loops or temporary memory buffers.

Testing

Validated against:

  • Known endian conversion vectors
  • Zero value
  • Maximum uint256
  • Repeated-byte values
  • High-level endian conversion reference implementation
  • Double-swap/inverse property

Validation

  • npm run format:check
  • npm run lint
  • npm run typecheck
  • npm test
  • npm run build
  • Yul byte swapper test suite

Closes #748

@mijinummi
mijinummi merged commit b1f169c into MDTechLabs:main Aug 20, 2026
5 of 7 checks passed
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.

[PERF] Build High-Speed Byte Swapping Utility in Yul

2 participants