8000 Evm result ext by cburgdorf · Pull Request #1326 · argotorg/fe · GitHub
[go: up one dir, main page]

Skip to content

Evm result ext#1326

Closed
cburgdorf wants to merge 2 commits intoargotorg:masterfrom
cburgdorf:EvmResultExt
Closed

Evm result ext#1326
cburgdorf wants to merge 2 commits intoargotorg:masterfrom
cburgdorf:EvmResultExt

Conversation

@cburgdorf
Copy link
Collaborator
@cburgdorf cburgdorf commented Mar 11, 2026

Add revert<T>() and EvmResultExt trait to std library

Summary

  • Add a high-level revert<T: Encode<Sol> + AbiSize>(T) -> ! function that ABI-encodes the value and reverts with the encoded bytes as revert data
  • Add an EvmResultExt extension trait on Result providing unwrap_or_revert() — on Ok it returns the value, on Err it ABI-encodes the error and reverts
  • Both are re-exported via the prelude (std::evm::{revert, EvmResultExt})
  • Fix encoded_size<T>() intrinsic for enum types — abi_static_size_bytes() only handled primitives and structs/tuples, causing a codegen failure ("unknown function: encoded_size__...") when T is an
    enum. Added enum support: discriminant word (32 bytes) + max variant payload
  • Add single-file tests covering the basic revert and unwrap_or_revert API

Test plan

  • test_revert_with_errorrevert() with a custom error enum (should_revert)
  • test_revert_with_u256revert() with a primitive u256 value (should_revert)
  • test_unwrap_or_revert_okunwrap_or_revert() on Ok returns the inner value
  • test_unwrap_or_revert_errunwrap_or_revert() on Err reverts (should_revert)

Adds a high-level `revert<T: Encode<Sol> + AbiSize>(T) -> !` function
that ABI-encodes the value and reverts, and an `EvmResultExt` extension
trait on `Result` providing `unwrap_or_revert()` for ergonomic error
handling in recv handlers.
@cburgdorf
Copy link
Collaborator Author

@sbillig in this PR the new revert API works standalone just like assert meaning it doesn't require the user to use an effect. Maybe that's ok? I'm not sure.

abi_static_size_bytes() only handled primitives and structs/tuples,
causing encoded_size<T>() to fail at codegen when T is an enum.
The extern intrinsic has no body, so when the compile-time constant
folding failed, the call fell through to a missing function.

Add enum support: discriminant word (32 bytes) + max variant payload,
mirroring the pattern in layout::ty_size_bytes.
@cburgdorf
Copy link
Collaborator Author

@codex review

@cburgdorf cburgdorf marked this pull request as ready for review March 11, 2026 09:25
@cburgdorf
Copy link
Collaborator Author

This landed in a slightly different way as #1342

@cburgdorf cburgdorf closed this Mar 20, 2026
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.

1 participant

0