Skip to content

Conversation

@msooseth
Copy link
Collaborator

@msooseth msooseth commented Sep 30, 2025

Description

This PR does two things.

Firstly, it reduces the shrink limit to 32B from 1024B. This means that we now try shrinking even small buffers. This should make sure that trailing useless bytes are not shown to the user, even if the calldata is small.

Secondly, this PR makes the decoding more robust, by introducing decodeBufFuzzy that is a bit more relaxed, allowing trailing bytes at the end of the buffer, and returning more meaningful errors/warnings to the user, which are displayed at the end of the mostly decoded calldata, such as: calldata: prove_negative_886(-42) -- with trailing bytes: [0,0,0]

Test eq-issue-with-length-cex-bug679 has been updated to remove the trailing f. It's not needed. I checked with evm.codes' playground, and the two bytecodes return, respectively 0x1 and 0x0, for the generated, shorter, CEX.

Fixes #886

Checklist

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

@msooseth msooseth marked this pull request as ready for review October 2, 2025 09:58
src/EVM/ABI.hs Outdated
where
isDynamic t = abiKind t == Dynamic

decudeBufRobust :: [AbiType] -> Expr Buf -> (AbiVals, String)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we fix the existing method instead of introducing new one?
We can adjust the types to better convey the necessary information.

decodeBuff can return an Either, where Left can pass along the error string. Right can be AbiVals where we remove NoVals.
We can extend it with Maybe ByteString to return the unprocessed bytes back, if there are any.

I would prefer to leave it up to the caller to decide what to do in such case, and not decide on the message here in the callee.

I was thinking that in our use case, where we want to pretty print the Solidity function call, the extra bytes do not pose any problem and we can safely ignore them, no?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

the extra bytes do not pose any problem -> in this case, they don't seem to. But we also use this method to decode things for cheatcodes, for example, where we cannot ignore it. Either would work there, actually. Let's say that I don't want to warn the user about the trailing bytes (not my preference, but OK). I'd still need to return a Left, because some functions rely on this being exact. Should I return a Left AbiVals?

Copy link
Collaborator

Choose a reason for hiding this comment

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

What do you mean by "relying on this being exact"?
My idea is that the return type would be something like Either String (AbiVals, Maybe ByteString).
The callers then implement their way of handling each situation.
Which could be an error, or success with all bytes consumed, or success with some leftover bytes.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Aaaaaah I see! OK, that make sense!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think it should now be how we want it to be? Let me know what you think :)_

Copy link
Collaborator

@blishko blishko left a comment

Choose a reason for hiding this comment

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

I would prefer to not decide on the error message for trailing bytes inside decodeBuf, but just return enough information for the callers to decide on their own.
That's why I was suggesting return type Either String (AbiVals, Maybe ByteString).

But I am also OK if you prefer to decide on the error string here already.

@msooseth
Copy link
Collaborator Author

msooseth commented Oct 8, 2025

Sorry, I would need to think about this more to do it in a different way. I'll think about it, or you can maybe explain how you mean it? Sorry, I am not up to par for this.

@blishko
Copy link
Collaborator

blishko commented Oct 8, 2025

Let's merge this then now. We can try something different later and see what we think about it.

@blishko blishko merged commit 3a72058 into main Oct 8, 2025
7 checks passed
@blishko blishko deleted the fix-decoding branch October 8, 2025 16:20
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.

Inconsistent decoding of negative values when using solc 0.6.12

3 participants