|
| 1 | +--- |
| 2 | +title: 'Firefly' |
| 3 | +subtitle: 'Solidity testing using KEVM' |
| 4 | +author: |
| 5 | +- Everett Hildenbrandt |
| 6 | +- Grigore Rosu |
| 7 | +institute: |
| 8 | +- Runtime Verification |
| 9 | +date: '\today' |
| 10 | +theme: metropolis |
| 11 | +fontsize: 8pt |
| 12 | +--- |
| 13 | + |
| 14 | +Overview |
| 15 | +-------- |
| 16 | + |
| 17 | +- (Brief) Introduction to KEVM |
| 18 | +- Introduction to Firefly |
| 19 | +- Firefly Demo |
| 20 | +- Future Directions |
| 21 | + |
| 22 | +(Brief) Introduction to KEVM |
| 23 | +---------------------------- |
| 24 | + |
| 25 | +- Repository: <https://github.com/kframework/evm-semantics> |
| 26 | +- Considered the canonical spec of EVM: <https://ethereum-magicians.org/t/jello-paper-as-canonical-evm-spec/2389> |
| 27 | +- All K tooling is derived automatically: |
| 28 | + - Reference EVM interpreter |
| 29 | + - Symbolic execution engine |
| 30 | + - EVM bytecode formal verification engine |
| 31 | + - Several EVM bytecode debugger options |
| 32 | + |
| 33 | +Introduction to Firefly |
| 34 | +----------------------- |
| 35 | + |
| 36 | +- `npm` package here: <https://www.npmjs.com/package/kevm-ganache-cli>. |
| 37 | +- Drop-in replacement for `ganache-cli`, can be used directly by Truffle. |
| 38 | + |
| 39 | + Instead of: |
| 40 | + |
| 41 | + ```sh |
| 42 | + npx ganache-cli |
| 43 | + ``` |
| 44 | + |
| 45 | + run: |
| 46 | + |
| 47 | + ```sh |
| 48 | + npx kevm-ganache-cli |
| 49 | + ``` |
| 50 | + |
| 51 | +. . . |
| 52 | + |
| 53 | +### Why?? |
| 54 | + |
| 55 | +- Higher confidence in results (run tests with both!). |
| 56 | +- More features to come: |
| 57 | + - Test coverage metrics. |
| 58 | + - Automated property verification. |
| 59 | + - Test generation. |
| 60 | + - Contract symbolic execution. |
| 61 | + - ... your ideas?? |
| 62 | + |
| 63 | +Firefly Demo - Setup |
| 64 | +-------------------- |
| 65 | + |
| 66 | +Instructions from <https://www.npmjs.com/package/kevm-ganache-cli>: |
| 67 | + |
| 68 | +. . . |
| 69 | + |
| 70 | +### Install KEVM (once) |
| 71 | + |
| 72 | +**TODO**: Update release URL. |
| 73 | + |
| 74 | +```sh |
| 75 | +sudo apt install nodejs npm curl git |
| 76 | +curl --location 'https://github.com/kframework/evm-semantics/releases/download/v1.0.0-a47e4b2/kevm_1.0.0_amd64.deb' \ |
| 77 | + --output kevm_1.0.0_amd64.deb |
| 78 | +sudo apt install ./kevm_1.0.0_amd64.deb |
| 79 | +``` |
| 80 | + |
| 81 | +. . . |
| 82 | + |
| 83 | +### Install `npx` (once) |
| 84 | + |
| 85 | +```sh |
| 86 | +sudo npm install -g npx |
| 87 | +``` |
| 88 | + |
| 89 | +Firefly Demo - Run OpenZeppelin Tests |
| 90 | +------------------------------------- |
| 91 | + |
| 92 | +### Start `kevm-ganache-cli` |
| 93 | + |
| 94 | +```sh |
| 95 | +npx kevm-ganache-cli \ |
| 96 | + --gasLimit 0xfffffffffff \ |
| 97 | + --account="0x2bdd21761a483f71054e14f5b827213567971c676928d9a1808cbfa4b7501200,1000000000000000000000000" \ |
| 98 | + --account="0x2bdd21761a483f71054e14f5b827213567971c676928d9a1808cbfa4b7501201,1000000000000000000000000" \ |
| 99 | + --account="0x2bdd21761a483f71054e14f5b827213567971c676928d9a1808cbfa4b7501202,1000000000000000000000000" \ |
| 100 | + --account="0x2bdd21761a483f71054e14f5b827213567971c676928d9a1808cbfa4b7501203,1000000000000000000000000" \ |
| 101 | + --account="0x2bdd21761a483f71054e14f5b827213567971c676928d9a1808cbfa4b7501204,1000000000000000000000000" \ |
| 102 | + --account="0x2bdd21761a483f71054e14f5b827213567971c676928d9a1808cbfa4b7501205,1000000000000000000000000" \ |
| 103 | + --account="0x2bdd21761a483f71054e14f5b827213567971c676928d9a1808cbfa4b7501206,1000000000000000000000000" \ |
| 104 | + --account="0x2bdd21761a483f71054e14f5b827213567971c676928d9a1808cbfa4b7501207,1000000000000000000000000" \ |
| 105 | + --account="0x2bdd21761a483f71054e14f5b827213567971c676928d9a1808cbfa4b7501208,1000000000000000000000000" \ |
| 106 | + --account="0x2bdd21761a483f71054e14f5b827213567971c676928d9a1808cbfa4b7501209,1000000000000000000000000" |
| 107 | +``` |
| 108 | + |
| 109 | +. . . |
| 110 | + |
| 111 | +### Run OpenZeppelin tests |
| 112 | + |
| 113 | +```sh |
| 114 | +git clone 'https://github.com/OpenZeppelin/openzeppelin-contracts.git' |
| 115 | +cd openzeppelin-contracts |
| 116 | +git checkout b8c8308 |
| 117 | +npm install |
| 118 | +npx truffle test test/token/ERC20/ERC20.test.js |
| 119 | +``` |
| 120 | + |
| 121 | +KEVM Extensions - Event Monitoring |
| 122 | +---------------------------------- |
| 123 | + |
| 124 | +Compile semantics with additional file `media/201908-trufflecon/kevm-ltl.md`. |
| 125 | + |
| 126 | +```k |
| 127 | + syntax LTLEvent ::= "overflow" |
| 128 | + // ------------------------------ |
| 129 | + rule <k> ADD W0 W1 ... </k> |
| 130 | + <events> EVENTS (.Set => SetItem(overflow)) </events> |
| 131 | + requires notBool overflow in EVENTS |
| 132 | + andBool W0 +Word W1 =/=Int W0 +Int W1 |
| 133 | + [priority(24)] |
| 134 | +
|
| 135 | + syntax LTLEvent ::= "revert" |
| 136 | + // ---------------------------- |
| 137 | + rule <k> REVERT _ _ ... </k> |
| 138 | + <events> EVENTS (.Set => SetItem(revert)) </events> |
| 139 | + requires notBool revert in EVENTS |
| 140 | + [priority(24)] |
| 141 | +``` |
| 142 | + |
| 143 | +- Monitors built-in to the KEVM semantics as an extension. |
| 144 | +- Can build arbitrary LTL formula over the monitors. |
| 145 | + |
| 146 | +KEVM Extensions - LTL Model Checking |
| 147 | +------------------------------------ |
| 148 | + |
| 149 | +### Input file `addition.evm` |
| 150 | + |
| 151 | +```evm |
| 152 | +load { "gas" : 10000000 |
| 153 | + // Query: always ((~ overflow) \/ eventually revert) |
| 154 | + // , "code" : UNSAFEADD(100 , 100) // True |
| 155 | + // , "code" : UNSAFEADD(maxUInt256 , 100) // False |
| 156 | + // , "code" : SAFEADD(100 , 100) // True |
| 157 | + , "code" : SAFEADD(maxUInt256 , 100) // True |
| 158 | + } |
| 159 | +
|
| 160 | +start |
| 161 | +``` |
| 162 | +
|
| 163 | +. . . |
| 164 | +
|
| 165 | +### Query |
| 166 | +
|
| 167 | +```sh |
| 168 | +./kevm run --backend llvm media/201908-trufflecon/addition.evm -cLTLFORMULA='always (overflow -> eventually revert)' |
| 169 | +``` |
| 170 | +
|
| 171 | +Truffle Firefly Plugin |
| 172 | +---------------------- |
| 173 | +
|
| 174 | +- Developed with help from Truffle devs today as plugin! |
| 175 | +- Modified OpenZeppelin test-suite which links to `truffle-plugin-firefly`. |
| 176 | +
|
| 177 | +```sh |
| 178 | +npx truffle run firefly SafeMath 'always (overflow -> eventually revert)' |
| 179 | +``` |
| 180 | +
|
0 commit comments