Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A fairly regular CopySlice simplification #366

Merged
merged 5 commits into from
Sep 7, 2023
Merged

Conversation

msooseth
Copy link
Collaborator

Description

This simplifies away some of the ConcreteBuf when we CopySlice from a WriteWord+ConcreteBuf combo. If the ConcreteBuf is larger than what we will copy, the last parts of the ConcreteBuf is useless.

Without:

            (CopySlice
              srcOffset: 0x0
              dstOffset: 0x0
              size:      0x40
              src:
                (WriteWord
                  idx:
                    0x0
                  val:
                    (WAddr
                      (SymAddr "arg1")
                    )
                )
                (ConcreteBuf
                  Length: 96 (0x60) bytes
                  0000:   00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00   ................
                  0010:   00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00   ................
                  0020:   00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00   ................
                  0030:   00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00   ................
                  0040:   00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00   ................
                  0050:   00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 80   ................
                )
            )
            (ConcreteBuf "")

With:

            (CopySlice
              srcOffset: 0x0
              dstOffset: 0x0
              size:      0x40
              src:
                (WriteWord
                  idx:
                    0x0
                  val:
                    (WAddr
                      (SymAddr "arg1")
                    )
                )
                (ConcreteBuf
                  Length: 64 (0x40) bytes
                  0000:   00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00   ................
                  0010:   00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00   ................
                  0020:   00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00   ................
                  0030:   00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00   ................
                )
            )

Notice that there was no need for all that 96B ConcreteBuf -- the CopySlice will cut it out anyway. So we only keep 64B, which is what CopySlice will copy.

Checklist

  • tested locally
  • added automated tests
  • updated the docs
  • updated the changelog

Copy link
Collaborator

@d-xo d-xo left a comment

Choose a reason for hiding this comment

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

could be a little more general maybe, but otherwise lgtm

src/EVM/Expr.hs Outdated Show resolved Hide resolved
@msooseth msooseth added the enhancement New feature or request label Aug 30, 2023
@msooseth
Copy link
Collaborator Author

msooseth commented Sep 1, 2023

I have now made it more general, let me know what you think! :)

src/EVM/Expr.hs Show resolved Hide resolved
(WriteWord wOff value (ConcreteBuf buf)) dst)
-- Let's not deal with overflow
| n+sz >= n && n+sz >= sz = (CopySlice srcOff dstOff size
(WriteWord wOff value (ConcreteBuf simplifiedBuf)) dst)
Copy link
Collaborator

Choose a reason for hiding this comment

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

fine to merge as is, but wondering if we can have some recursive rewrites that work for buffers other than a single writeword over concretebuf?

Copy link
Collaborator

@d-xo d-xo left a comment

Choose a reason for hiding this comment

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

lgtm!

@msooseth msooseth merged commit 79d7a75 into main Sep 7, 2023
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants