1
- ERC20: Formal Executable Specification
2
- ======================================
1
+ ERC20-K : Formal Executable Specification of ERC20
2
+ =================================================
3
3
4
4
Authors: [ Philip Daian] ( http://pdaian.com/ ) and [ Grigore Rosu] ( http://fsl.cs.illinois.edu/grosu )
5
5
6
6
Date: November 28, 2017
7
7
8
- ** Acknowledgments:** Warm thanks to the K team who defined the
8
+ ** Acknowledgments:** Warmest thanks to the K team who defined the
9
9
[ KEVM] ( https://github.com/kframework/evm-semantics ) semantics
10
10
(see
11
- [ our technical report] ( https://www.ideals.illinois.edu/handle/2142/97207 ) , too)
11
+ [ technical report] ( https://www.ideals.illinois.edu/handle/2142/97207 ) , too)
12
12
and verified smart contracts for ERC20 compliance.
13
13
It is their effort that inevitably led to the quest for a formal specification
14
14
of ERC20.
15
15
We also thank [ IOHK] ( http://iohk.io ) for their generous support
16
- of the [ KEVM] ( https://github.com/kframework/evm-semantics ) and
17
- [ IELE] ( https://github.com/runtimeverification/iele-semantics )
18
- projects; the latter, in particular, led to the question of whether
19
- the ERC20 specification can be defined in a way that does not depend on
20
- the EVM and thus can be used in combination with other computational
21
- infrastructures.
16
+ of both [ KEVM] ( https://github.com/kframework/evm-semantics ) and
17
+ [ IELE] ( https://github.com/runtimeverification/iele-semantics ) ;
18
+ IELE, in particular, led to the question of whether the ERC20 specification
19
+ can be defined in a more abstract way that does not depend on the EVM, and
20
+ thus can also be used in combination with other computational infrastructures.
22
21
23
22
## Abstract
24
23
@@ -27,39 +26,43 @@ is one of the most important standards for the implementation of tokens
27
26
within Ethereum smart contracts.
28
27
ERC20 provides basic functionality to transfer tokens and to be approved so
29
28
they can be spent by another on-chain third party.
30
- Here we provide a complete formalization of ERC20 in
31
- [ K] ( http://kframework.org ) .
32
- Specifically, we provide a formal executable semantics of ERC20.
33
- Our semantics clarifies what data (accounts, allowances, etc.) are handled by
34
- the various ERC20 functions and the precise meaning of the functions on such
29
+ Unfortunately, ERC20 leaves several corner cases unspecified, which makes it
30
+ inadequate to use in the formal verification of token implementations.
31
+ ERC20-K is a complete formal specification of the ERC20 standard.
32
+ Specifically, it is a * formal executable semantics* of a * completion of the
33
+ ERC20 standard* , using the [ K framework] ( http://kframework.org ) .
34
+ ERC20-K clarifies what data (accounts, allowances, etc.) are handled by
35
+ the various ERC20 functions and the precise meaning of those functions on such
35
36
data.
36
- It also clarifies the semantics of * all* the corner cases that the ERC20
37
+ ERC20-K also clarifies the meaning of * all* the corner cases that the ERC20
37
38
standard omits to discuss, such as transfers from yourself to yourself
38
- or transfers that result in arithmetic overflows,
39
- following the most natural implementations that aim at minimizing gas
40
- consumption.
39
+ or transfers that result in arithmetic overflows, following the most natural
40
+ implementations that aim at minimizing gas consumption.
41
+ Being executable, ERC20-K can also be tested for increased confidence.
42
+ Driven by the semantic rules that form ERC20-K, as well as by their side
43
+ conditions, we manually but systematically produced a test-suite
44
+ (under the ` tests ` folder) consisting of several dozens of tests which
45
+ we believe cover all the corner cases.
46
+ We encourage you to analyze these tests and use them to test your
47
+ implementations.
48
+ Please contribute with more tests if you think that we left any interesting
49
+ behaviors uncovered.
50
+
41
51
42
52
## Motivation
43
53
44
- Now that the K team has developed
45
- [ KEVM] ( https://github.com/kframework/evm-semantics ) , a formal semantics of
46
- the Ethereum Virtual Machine, it has become possible to rigorously verify
47
- smart contracts at the EVM level against higher level specifications.
54
+ [ KEVM] ( https://github.com/kframework/evm-semantics ) makes it possible to
55
+ rigorously verify smart contracts at the EVM level against higher level
56
+ specifications.
48
57
The most requested property to verify so far was * ERC20 compliance* of
49
- smart contracts written in languages like Solidity or Viper.
50
- But what does that really mean?
51
- When formal verification is sought, a property (or specification) to
52
- verify the code against must be explicitly or implicitly provided.
53
- Moreover, such a specification is expected to be non-ambiguous and
54
- capable of answering all the questions regarding corner-case behaviors.
55
- At our knowledge, there was no such formal ERC20 specification available
56
- at the time of this writing.
57
- Our specification below is executable, so it can also be tested for increased
58
- confidence.
59
- We tested it against a test-suite of more than 60 tests
60
- (under the ` tests ` folder), which we believe cover all the corner cases.
61
- Please contribute with more tests if you think that we left some behaviors
62
- uncovered.
58
+ tokens written in languages like Solidity or Viper.
59
+ But what does "ERC20 compliance" really mean?
60
+ When formal verification is sought, a property (or specification) that the
61
+ code must satisfy must be available.
62
+ Moreover, such a specification should be non-ambiguous and capable of
63
+ answering all the questions regarding corner-case behaviors.
64
+ At our knowledge, there was no such formal specification for ERC20, or
65
+ ERC20 variants, available at the time of this writing.
63
66
64
67
## Formal Specification
65
68
0 commit comments