8000 fix: we do support empty bytes now by 0xkarmacoma · Pull Request #462 · a16z/halmos · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix: we do support empty bytes now #462

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

0xkarmacoma
Copy link
Collaborator

No description provided.

@daejunpark
Copy link
Collaborator

the ci failure is orthogonal to the change in the test. but the change somehow triggers solc optimization, which replaces keccak256("") with its evaluation at compile time. this replacement doesn't use the push opcode, so the existing mechanism doesn't work.

this temporary workaround ae0cacb fixes the ci failure, but it needs to be properly implemented. do not merge.

@0xkarmacoma 0xkarmacoma marked this pull request as draft February 19, 2025 00:56
@daejunpark daejunpark force-pushed the fix/keccak-empty-bytes branch from ae0cacb to ca7c6e3 Compare February 19, 2025 04:53
@daejunpark
Copy link
Collaborator

it turns out that the empty keccak value is read from memory (probably because it was previously stored into memory using codecopy). ca7c6e3 moves the special value handling logic to the point where a value is pushed to the stack to cover various cases.

name = name_of(extract_string_argument(arg, 1))
symbolic_bytes = create_generic(ex, byte_size * 8, name, "bytes")
symbolic_bytes = create_any(ex, bits, name, "bytes") if bits else ByteVec()
Copy link
Collaborator

Choose a reason for hiding this comment

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

an alternative approach is to add the empty byte logic inside create_any() rather than here. though, it's unclear to me which is necessarily better.

if we decide to keep it here, then we also need to add it to create_string() below, which is basically the same as create_bytes() except for the error message. indeed, it would be better to factor out the common logic to avoid code duplication.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@daejunpark daejunpark force-pushed the fix/keccak-empty-bytes branch from 5593859 to 518857e Compare March 28, 2025 00:41
@daejunpark daejunpark marked this pull request as ready for review March 28, 2025 00:42
@daejunpark
Copy link
Collaborator

applied the special handling only to push and mload operations, instead of to all stack pushes, for performance consideration: 518857e

it would be more robust to apply to all pushes, if it doesn't hurt performance too much, though. wdyt?

@0xkarmacoma
Copy link
Collaborator Author

seems related to #393, but does not fix it

@0xkarmacoma
Copy link
Collaborator Author

trying to wrap my head around this. It does feel like we're playing whack-a-mole since there could be other sources of concrete hashes (returndata, calldata, codecopy, ...). So we may end up with values on the stack that are either a concrete hash value, or its hash expression. In that sense, it would indeed be more consistent to eagerly lookup every value that goes on the stack in sha_inv and try to make it an expr, but at a cost. OTOH, I'm not completely sure I understand what issues we solve by eagerly converting everything to an expr. Some things that come to mind:

Maybe an alternative would be that we don't need to eagerly do anything, and instead try to convert lazily to an expr at the point of use -- that could be both robust and cheap?

I say let's merge this PR as-is and do a more intentional keccak refactor in a follow-up

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
0