Skip to content

Conversation

ChaoticWalrus
Copy link
Contributor

…rray`

This function was naively using the built-in bytes.concat method, but it copies the array to memory, incurring memory expansion costs!

Fuzzed tests (e.g. testFuzz_BytesArrayToBitmapToBytesArray) -- which do the encoding twice -- show a ~20k gas improvement with this commit

see for reference:
https://github.com/Layr-Labs/eigenlayer-middleware/actions/runs/7574740337/job/20629810269#step:5:151-152

…rray`

This function was naively using the built-in `bytes.concat` method, but it copies the array to memory, incurring memory expansion costs!

Fuzzed tests (e.g. testFuzz_BytesArrayToBitmapToBytesArray) -- which do the encoding twice -- show a ~20k gas improvement with this commit

see for reference:
https://github.com/Layr-Labs/eigenlayer-middleware/actions/runs/7574740337/job/20629810269#step:5:151-152
@ChaoticWalrus
Copy link
Contributor Author

Seems I don't have my pre-commit hooks set up locally correctly for this repo, as I failed the commitlint CI 😅

@ChaoticWalrus
Copy link
Contributor Author

I added a few simple tests to get better gas estimates (comparing previous usage -> usage with this commit)
max/"full" bitmap: ~204565 -> ~135577 gas
empty bitmap: ~44974 -> ~6232 gas
ten entry bitmap with only the first ten slots filled: ~49062 -> ~11969 gas
ten entry bitmap with 0th, 10th, 20th, ..., 90th slots filled: ~48700 -> ~26535 gas

Copy link
Contributor

@wadealexc wadealexc left a comment

Choose a reason for hiding this comment

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

Looks great!

@ChaoticWalrus ChaoticWalrus merged commit 6e95af9 into m2-mainnet Jan 23, 2024
@ChaoticWalrus ChaoticWalrus deleted the bitmap-to-bytes-array-improvement branch January 23, 2024 20:04
bobwzy pushed a commit to bobwzy/eigenlayer-middleware-fork that referenced this pull request Apr 3, 2024
Layr-Labs#149)

* feat: massive improvement in gas usage of `BitmapUtils.bitmapToBytesArray`

This function was naively using the built-in `bytes.concat` method, but it copies the array to memory, incurring memory expansion costs!

Fuzzed tests (e.g. testFuzz_BytesArrayToBitmapToBytesArray) -- which do the encoding twice -- show a ~20k gas improvement with this commit

see for reference:
https://github.com/Layr-Labs/eigenlayer-middleware/actions/runs/7574740337/job/20629810269#step:5:151-152

* chore: add some additional testing which logs the cost of the `bitmapToBytesArray` function
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.

2 participants