Skip to content

Commit

Permalink
Initial draft
Browse files Browse the repository at this point in the history
  • Loading branch information
LogvinovLeon committed Feb 4, 2019
1 parent f276952 commit 9cbd543
Showing 1 changed file with 96 additions and 0 deletions.
96 changes: 96 additions & 0 deletions EIPS/eip-838.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
---
eip: 838
title: ABI specification for REVERT reason
author: Federico Bond (@federicobond), Leonid Logvinov (@LogvinovLeon)
discussions-to: <URL>
status: Draft
type: ERC
category: ERC
created: 2019-01-31
---

<!--You can leave these HTML comments in your merged EIP and delete the visible duplicate text guides, they will not appear and may be helpful to refer to if you edit it again. This is the suggested template for new EIPs. Note that an EIP number will be assigned by an editor. When opening a pull request to submit your EIP, please use an abbreviated title in the filename, `eip-draft_title_abbrev.md`. The title should be 44 characters or less.-->

## Simple Summary

<!--"If you can't explain it simply, you don't understand it well enough." Provide a simplified and layman-accessible explanation of the EIP.-->

A proposal to extend the ABI specification to include typed errors in the REVERT reason.

## Abstract

<!--A short (~200 word) description of the technical issue being addressed.-->

This proposal specifies how to encode potential error conditions in the JSON ABI of a smart contract. A high-level language could then provide a syntax for declaring and throwing these errors. The compiler will encode these errors in the reason parameter of the REVERT opcode in a way that can be easily reconstructed by libraries such as `ethers` or `web3`.

## Motivation

<!--The motivation is critical for EIPs that want to change the Ethereum protocol. It should clearly explain why the existing protocol specification is inadequate to address the problem that the EIP solves. EIP submissions without sufficient motivation may be rejected outright.-->

It's important to provide clear feedback to users (and developers) about what went wrong with their Ethereum transactions. The `REVERT` opcode is a step in the right direction, as it allows smart contract developers to encode a message describing the failure in the reason parameter. There is an implementation released by Solidity that accepts a `string`, thus providing a low-level interface to this parameter. However, standardizing a method for passing errors from this parameter back to clients will bring many benefits to both users and developers.

The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in RFC 2119.

## Specification

<!--The technical specification should describe the syntax and semantics of any new feature. The specification should be detailed enough to allow competing, interoperable implementations for any of the current Ethereum platforms (go-ethereum, parity, cpp-ethereum, ethereumj, ethereumjs, and [others](https://github.com/ethereum/wiki/wiki/Clients)).-->

To conform to this specification, compilers producing JSON ABIs SHOULD include error declarations alongside functions and events. Each error object MUST contain the keys `name` (string) and `arguments` (same types as the function’s `inputs` list). The value of `type` MUST be "error".
Example:

```json
{
"type": "error",
"name": "InsufficientBalance",
"arguments": [
{
"name": "amount",
"type": "uint256"
}
]
}
```

A selector for this error can be computed from its signature (`InsufficientBalance(uint256)` for the example above) in the same way that it's currently done for public functions and events. Any arguments for the error together with the selector are ABI encoded in the same way as call data for functions.

A high-level language like Solidity can then implement a syntax like this:

```solidity
contract MyToken {
error InsufficientFunds(uint256 amount);
function transfer(address _to, uint256 _amount) {
if (balances[msg.sender] <= _amount) {
revert InsufficientFunds(_amount);
}
}
}
```

## Rationale

<!--The rationale fleshes out the specification by describing what motivated the design and why particular design decisions were made. It should describe alternate designs that were considered and related work, e.g. how the feature is supported in other languages. The rationale may also provide evidence of consensus within the community, and should discuss important objections or concerns raised during discussion.-->

This specific encoding was choosen because it is the same one Solidity uses at this moment for REVERTs. This PR just proposes to allow for user-defined errro ABIs instead of hard-coding `Error(string)`.

In terms of previous work - there is one other [EIP 207](https://github.com/ethereum/EIPs/pull/207). It proposes to use **CBOR** encoding. In my oponion - there is no need to introduce another encoding scheme because the ABI encoding is flexible fast cheap and supported already.

## Backwards Compatibility

<!--All EIPs that introduce backwards incompatibilities must include a section describing these incompatibilities and their severity. The EIP must explain how the author proposes to deal with these incompatibilities. EIP submissions without a sufficient backwards compatibility treatise may be rejected outright.-->

Apps and tools that have not implemented this spec are checking for the old error selector. The only way to break that is to define an error ABI `Error(string)` (or to find a hash collision), but in that case - our data is a string - so they will work correctly. This EIP is a superset of a current solidity feature and therefore is backwards compatible.

## Test Cases

<!--Test cases for an implementation are mandatory for EIPs that are affecting consensus changes. Other EIPs can choose to include links to test cases if applicable.-->

## Implementation

<!--The implementations must be completed before any EIP is given status "Final", but it need not be completed before the EIP is accepted. While there is merit to the approach of reaching consensus on the specification and rationale before writing code, the principle of "rough consensus and running code" is still useful when it comes to resolving many discussions of API details.-->

Not started yet.

## Copyright

Copyright and related rights waived via [CC0](https://creativecommons.org/publicdomain/zero/1.0/).

0 comments on commit 9cbd543

Please sign in to comment.