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

Support Custom Errors #2994

Open
skeletor-spaceman opened this issue Jul 27, 2022 · 6 comments
Open

Support Custom Errors #2994

skeletor-spaceman opened this issue Jul 27, 2022 · 6 comments
Labels
VIP: Deferred VIP is not scheduled to move forward at this time

Comments

@skeletor-spaceman
Copy link

Version Information

  • vyper Version (output of vyper --version): 0.3.3
  • OS: linux
  • Python Version (output of python --version): 3.8

What's your issue about?

I want to mimic the behavior of custom errors in solidity: https://blog.soliditylang.org/2021/04/21/custom-errors/
Right now I'm just trying to raise an error without parameters, adding parameters would be nice to have.

Should be able to raise bytes4 | Bytes[4] but encountering following errors:

vyper.exceptions.TypeMismatch: Given reference has type Bytes[4], expected String[1024]
vyper.exceptions.InvalidType: Expected String[1024] but literal can only be cast as bytes4

Tried all these different options with no success:

    if msg.sender != self.governance: raise keccak256('Governable_OnlyGovernance()')
    if msg.sender != self.governance: raise convert(method_id('Governable_OnlyGovernance()', output_type=Bytes[4]), String[1024]) # Compiler panic
    if msg.sender != self.governance: raise convert(method_id('Governable_OnlyGovernance()'), String[4])
    if msg.sender != self.governance: raise _abi_encode(method_id=method_id('Governable_OnlyGovernance()'))
    if msg.sender != self.governance: raise method_id('Governable_OnlyGovernance()')
    if msg.sender != self.governance: raise 0xe0ae9db4
@charles-cooper
Copy link
Member

meeting notes: punt for now as testing frameworks can use other means of error detection. implement if some production smart contracts require handling or issuing of specific custom errors.

@charles-cooper charles-cooper added the VIP: Deferred VIP is not scheduled to move forward at this time label Aug 8, 2022
@charles-cooper
Copy link
Member

idea for how we can export for debugging:

# example: x, y and z are local variables
if x > 10:
  raise  # @error My Custom Error, @trace x,y
  # no runtime reason, tooling should print something like "My Custom Error, x = 11, y = ..."

@z80dev
Copy link
Contributor

z80dev commented Oct 3, 2022

Here's a use-case where production smart contracts require issuing of specific custom errors: https://eips.ethereum.org/EIPS/eip-3668

Contracts wishing to support lookup of data from external sources may, instead of returning the data directly, revert using OffchainLookup(address sender, string[] urls, bytes callData, bytes4 callbackFunction, bytes extraData). Clients supporting this specification then make an RPC call to a URL from urls, supplying callData, and getting back an opaque byte string response. Finally, clients call the function specified by callbackFunction on the contract, providing response and extraData. The contract can then decode and verify the returned data using an implementation-specific method.

@charles-cooper
Copy link
Member

raw_revert as implemented in #3136 should address this particular use case

@pcaversaccio
Copy link
Collaborator

We should consider adding custom errors to .vyi files since they are already part of some EIPs: https://eips.ethereum.org/EIPS/eip-6093.

@fubuloubu
Copy link
Member

custom errors is basically a requirement now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
VIP: Deferred VIP is not scheduled to move forward at this time
Projects
None yet
Development

No branches or pull requests

5 participants