Skip to content

Revert panic#1395

Merged
sbillig merged 6 commits intoargotorg:masterfrom
cburgdorf:revert_panic
Apr 16, 2026
Merged

Revert panic#1395
sbillig merged 6 commits intoargotorg:masterfrom
cburgdorf:revert_panic

Conversation

@cburgdorf
Copy link
Copy Markdown
Collaborator

@cburgdorf cburgdorf commented Apr 15, 2026

Summary

  • Remove the redundant EvmResultExt trait and unwrap_or_revert() method.
  • Add #[error] for Solidity-compatible custom error types, including generated ABI encoding support, revert_error(), and a predefined Panic(uint256) error type.
  • Extend #[test(should_revert)] with panic and selector arguments for verifying revert payloads.
  • Make assert(false) revert with Solidity-compatible Panic(uint256) data instead of empty revert data.
  • Make Result::unwrap() emit selector-prefixed revert data for #[error] types.
  • Make checked arithmetic overflow revert with Solidity-compatible Panic(uint256) data.

@cburgdorf cburgdorf force-pushed the revert_panic branch 2 times, most recently from 622a366 to 74e6b0a Compare April 15, 2026 13:20
@cburgdorf
Copy link
Copy Markdown
Collaborator Author

@codex review

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 74e6b0a4b1

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread crates/codegen/src/yul/emitter/module.rs
Comment thread crates/codegen/src/sonatina/lower.rs Outdated
Comment thread crates/codegen/src/yul/emitter/module.rs Outdated
@cburgdorf
Copy link
Copy Markdown
Collaborator Author

@codex review

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ff44f0d256

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread crates/hir/src/core/lower/item.rs Outdated
@cburgdorf
Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector
Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Hooray!

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@cburgdorf cburgdorf marked this pull request as ready for review April 15, 2026 18:50
@cburgdorf cburgdorf requested a review from sbillig April 15, 2026 18:50
@cburgdorf
Copy link
Copy Markdown
Collaborator Author

@sbillig Codex is happy, are you, too?

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f9e56427b9

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread crates/codegen/src/yul/emitter/module.rs
Comment thread crates/hir/src/core/lower/item.rs Outdated
@cburgdorf
Copy link
Copy Markdown
Collaborator Author

@codex review

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ee2afab133

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread crates/codegen/src/yul/emitter/module.rs Outdated
@cburgdorf
Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector
Copy link
Copy Markdown

Codex Review: Didn't find any major issues. More of your lovely PRs please.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@cburgdorf
Copy link
Copy Markdown
Collaborator Author

More of your lovely PRs please.

Thank you @codex, I love you, too.

@chatgpt-codex-connector
Copy link
Copy Markdown

To use Codex here, create an environment for this repo.

Since `Result::unwrap()` already ABI-encodes errors on revert via
`panic_with_value`, `unwrap_or_revert()` was a leftover that duplicated
this behavior.
Introduce a new `#[error]` struct attribute that mirrors the existing
`#[event]` pattern. The compiler auto-generates `ErrorVariant<Sol>`,
`AbiSize`, and `Encode<Sol>` implementations with a compile-time
computed 4-byte selector matching Solidity's custom error ABI.

New stdlib additions:
- `ErrorVariant<A>` trait in `core::error` (analogous to `MsgVariant`)
- `revert_error<T>()` in `std::evm::effects` for selector-prefixed reverts
- `Panic` struct in `std::evm::panic` with Solidity-compatible panic codes
Add two new optional arguments to the test attribute:
- `#[test(should_revert, panic = 0x11)]` — match Panic(uint256) with
  specific code (verifies selector 0x4e487b71 + ABI-encoded code)
- `#[test(should_revert, selector = 0x4e487b71)]` — match only the
  4-byte error selector

This enables end-to-end verification that `revert_error()` produces
the correct Solidity-compatible revert payloads.
`assert(false)` now calls `revert_error(Panic { code: 0x01 })`
producing a Solidity-compatible Panic(uint256) revert payload,
making assertion failures identifiable by off-chain tooling.
The monomorphizer now checks whether the error type of
`panic_with_value<T>()` implements `ErrorVariant<Sol>`. If so,
the call is rewritten to `revert_error<T>()` (selector-prefixed)
instead of `revert<T>()` (raw ABI-encoded).

This means `Result<MyError, T>::unwrap()` automatically produces
Solidity-compatible error payloads when `MyError` is an `#[error]`
type, without requiring the user to call `revert_error()` explicitly.
The Sonatina codegen now writes Panic(uint256) revert payloads with
the correct Solidity panic code instead of empty revert data:
- 0x11 for arithmetic overflow/underflow (add, sub, mul, neg)
- 0x12 for division/modulo by zero (div, rem)
- 0x32 for array index out of bounds
@sbillig sbillig merged commit e2491d9 into argotorg:master Apr 16, 2026
6 checks passed
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