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

Replace InvalidDeposit and InvalidOpcode exceptions with asserts #15596

Merged
merged 2 commits into from
Nov 29, 2024

Conversation

cameel
Copy link
Member

@cameel cameel commented Nov 29, 2024

A bit of simplification of our error handling in bytecode generation. We have dedicated exceptions defined for some cases but they're almost never caught and are de facto equivalent with failed assertions. The only case where we catch one of them is assembly import.

The PR replaces them with proper asserts (and AssemblyImportException in the one case where we do catch them).

- We never actually catch it so it's already de facto handled like a failed assert, just with worse diagnostics.
- The only case where it needs to be an exception is assembly import. In other situations we don't catch it so it's effectively an assert.
@cameel cameel self-assigned this Nov 29, 2024
@@ -267,28 +268,28 @@ inline unsigned getLogNumber(Instruction _inst)
/// @returns the PUSH<_number> instruction
inline Instruction pushInstruction(unsigned _number)
{
assertThrow(_number <= 32, InvalidOpcode, std::string("Invalid PUSH instruction requested (") + std::to_string(_number) + ").");
solAssert(_number <= 32);
Copy link
Member Author

Choose a reason for hiding this comment

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

Note that this validation was impossible to trigger via assembly import, because the import blindly converts the value to u256 without checking the range. The conversion silently truncates the value to 256 bits so it can never exceed 32 bytes. This means that this case is not validated at all.

This is actually a bug in assembly import - out-of-range PUSH values result in something wrong being pushed to the stack.

@cameel cameel merged commit d2a7eb3 into develop Nov 29, 2024
74 checks passed
@cameel cameel deleted the remove-superfluous-assembly-exceptions branch November 29, 2024 15:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants