├── .gitignore ├── LICENSE ├── README.md ├── assets └── headbang.gif ├── build └── contracts │ ├── MemoryArray.json │ ├── Migrations.json │ ├── MyContract.json │ ├── MyContractA.json │ ├── SafeMath.json │ └── StorageOverride.json ├── contracts ├── AddressEmpty.sol ├── AddressToString.sol ├── ArrayLiteralType.sol ├── ArrayRemove.sol ├── BytesToAddress.sol ├── DateSuffixes.sol ├── DefaultDataTypes.sol ├── Enum.sol ├── ExternalVsPublic.sol ├── IndexedEvents.sol ├── InfiniteLoop.sol ├── MemoryArray.sol ├── Migrations.sol ├── MultipleValuesReturn.sol ├── Pragma.sol ├── Random.sol ├── ReturnVariables.sol ├── SafeMath.sol ├── StorageOverride.sol ├── StringCompare.sol ├── StringLength.sol ├── VariableScope.sol └── bytes32ToString.sol ├── migrations ├── 1_initial_migration.js └── 2_deploy_contracts.js ├── test ├── memoryarray.js ├── safemath.js └── storageoverride.js └── truffle.js /.gitignore: -------------------------------------------------------------------------------- 1 | //this will affect all the git repos 2 | git config --global core.excludesfile ~/.gitignore 3 | 4 | 5 | //update files since .ignore won't if already tracked 6 | git rm --cached 7 | 8 | # Compiled source # 9 | ################### 10 | *.com 11 | *.class 12 | *.dll 13 | *.exe 14 | *.o 15 | *.so 16 | 17 | # Packages # 18 | ############ 19 | # it's better to unpack these files and commit the raw source 20 | # git has its own built in compression methods 21 | *.7z 22 | *.dmg 23 | *.gz 24 | *.iso 25 | *.jar 26 | *.rar 27 | *.tar 28 | *.zip 29 | 30 | # Logs and databases # 31 | ###################### 32 | *.log 33 | *.sql 34 | *.sqlite 35 | 36 | # OS generated files # 37 | ###################### 38 | .DS_Store 39 | .DS_Store? 40 | ._* 41 | .Spotlight-V100 42 | .Trashes 43 | # Icon? 44 | ehthumbs.db 45 | Thumbs.db 46 | .cache 47 | .project 48 | .settings 49 | .tmproj 50 | *.esproj 51 | nbproject 52 | 53 | # Numerous always-ignore extensions # 54 | ##################################### 55 | *.diff 56 | *.err 57 | *.orig 58 | *.rej 59 | *.swn 60 | *.swo 61 | *.swp 62 | *.vi 63 | *~ 64 | *.sass-cache 65 | *.grunt 66 | *.tmp 67 | 68 | # Dreamweaver added files # 69 | ########################### 70 | _notes 71 | dwsync.xml 72 | 73 | # Komodo # 74 | ########################### 75 | *.komodoproject 76 | .komodotools 77 | 78 | # Node # 79 | ##################### 80 | node_modules 81 | 82 | # Bower # 83 | ##################### 84 | bower_components 85 | 86 | # Folders to ignore # 87 | ##################### 88 | .hg 89 | .svn 90 | .CVS 91 | intermediate 92 | publish 93 | .idea 94 | .graphics 95 | _test 96 | _archive 97 | uploads 98 | tmp 99 | 100 | # files to ignore # 101 | ################### 102 | secrets.json 103 | stuff.txt 104 | server/sqlite.db 105 | todo.txt 106 | 107 | # Vim files to ignore # 108 | ####################### 109 | .VimballRecord 110 | .netrwhist 111 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT license 2 | 3 | Copyright (C) 2016 Miguel Mota 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 9 | of the Software, and to permit persons to whom the Software is furnished to do 10 | so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

2 |
3 | logo 4 |
5 |
6 |
7 |

8 | 9 | # Solidity idiosyncrasies 10 | 11 | > [Solidity](https://github.com/ethereum/solidity) gotchas, pitfalls, limitations, and idiosyncrasies. 12 | 13 | [![License](http://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/miguelmota/solidity-idiosyncrasies/master/LICENSE) 14 | 15 | This is a list of things that have caused me to bang my head against a brick wall when coming across them in solidity, especially when starting out as a beginner. 16 | 17 | 18 | 19 | Notice! These examples are from Solidity v0.4.x. Some of these example may no longer be relevant in newer versions of Solidity. 20 | 21 | ## Contents 22 | 23 | - [Examples](#examples) 24 | - [Contributing](#contributing) 25 | - [Issues](#issues) 26 | - [Credits](#credits) 27 | - [Resources](#resources) 28 | - [License](#license) 29 | 30 | --- 31 | 32 | ## Examples 33 | 34 | In no particular order: 35 | 36 | - **Using `delete` on an array leaves a gap**; need to shift items manually and update the `length` property. 37 | 38 | ```solidity 39 | contract MyContract { 40 | uint[] array = [1,2,3]; 41 | 42 | function removeAtIndex(uint index) returns (uint[]) { 43 | if (index >= array.length) return; 44 | 45 | for (uint i = index; i < array.length-1; i++) { 46 | array[i] = array[i+1]; 47 | } 48 | 49 | array.length--; 50 | 51 | return array; 52 | } 53 | } 54 | ``` 55 | 56 | - **Can't return `struct` for `external` methods**; need to return multiple values. 57 | 58 | ```solidity 59 | contract MyContract { 60 | struct MyStruct { 61 | string str; 62 | uint i; 63 | } 64 | 65 | MyStruct myStruct; 66 | 67 | function MyContract() { 68 | myStruct = MyStruct("foo", 1); 69 | } 70 | 71 | function myMethod() external returns (string, uint) { 72 | return (myStruct.str, myStruct.i); 73 | } 74 | } 75 | ``` 76 | 77 | - **Can't compare two `string`s**; one easy workaround is to compare the `sha3` hashes of the strings. 78 | 79 | ```solidity 80 | contract MyContract { 81 | function compare(string s1, string s2) returns (bool) { 82 | return (sha3(s1) == sha3(s2)); 83 | } 84 | } 85 | ``` 86 | 87 | or compare `byte` by `byte` which is more performant. Utility libraries such as [solidity-stringutils](https://github.com/Arachnid/solidity-stringutils) and [solidity-bytes-utils](https://github.com/GNSPS/solidity-bytes-utils) provide helper functions for string comparison and have good examples. 88 | 89 | - **Can't compare `address` to `0` to check if it's empty**; need to compare to `address(0)`. 90 | 91 | ```solidity 92 | contract MyContract { 93 | function isEmptyAddress(address addr) returns (bool) { 94 | return (addr == address(0)); 95 | } 96 | } 97 | ``` 98 | 99 | - **`string` has no `length` property**; need to manually check string length in characters. 100 | 101 | ```solidity 102 | contract MyContract { 103 | string str = "foo"; 104 | 105 | function MyContract() { 106 | assert(size(str) == 3); 107 | } 108 | 109 | function size(string s) returns (uint) { 110 | uint length = 0; 111 | uint i = 0; 112 | bytes memory strBytes = bytes(s); 113 | 114 | while (i < strBytes.length) { 115 | if (strBytes[i]>>7 == 0) { 116 | i+=1; 117 | } else if (strBytes[i]>>5 == 0x6) { 118 | i+=2; 119 | } else if (strBytes[i]>>4 == 0xE) { 120 | i+=3; 121 | } else if (strBytes[i]>>3 == 0x1E) { 122 | i+=4; 123 | } else { 124 | i+=1; 125 | } 126 | 127 | length++; 128 | } 129 | } 130 | } 131 | ``` 132 | 133 | Don't use `bytes(str).length` to check string length because encoded strings can differ in length, for example, a single character encoded in UTF-8 can be more than a byte long. 134 | 135 | - **Can't pass array of `string`s as argument to `external` function (from web3)**; need to do manual serializing and deserializing. 136 | 137 | - **Can't typecast `address` to `string`**; need to manually convert using `bytes`. 138 | 139 | ```solidity 140 | contract MyContract { 141 | string public str; 142 | 143 | function MyContract() { 144 | str = toString(msg.sender); 145 | } 146 | 147 | function toString(address addr) returns (string) { 148 | bytes memory b = new bytes(20); 149 | for (uint i = 0; i < 20; i++) { 150 | b[i] = byte(uint8(uint(addr) / (2**(8*(19 - i))))); 151 | } 152 | return string(b); 153 | } 154 | } 155 | ``` 156 | 157 | - **Can't typecast `bytes` to `string`**; need to do manual conversion. 158 | 159 | ```solidity 160 | contract MyContract { 161 | bytes32 bts = "foo"; 162 | string str; 163 | 164 | function MyContract() { 165 | str = bytes32ToString(bts); 166 | } 167 | 168 | function bytes32ToString(bytes32 x) constant returns (string) { 169 | bytes memory bytesString = new bytes(32); 170 | uint charCount = 0; 171 | for (uint j = 0; j < 32; j++) { 172 | byte char = byte(bytes32(uint(x) * 2 ** (8 * j))); 173 | if (char != 0) { 174 | bytesString[charCount] = char; 175 | charCount++; 176 | } 177 | } 178 | bytes memory bytesStringTrimmed = new bytes(charCount); 179 | for (j = 0; j < charCount; j++) { 180 | bytesStringTrimmed[j] = bytesString[j]; 181 | } 182 | return string(bytesStringTrimmed); 183 | } 184 | } 185 | ``` 186 | 187 | The helper library [solidity-stringutils](https://github.com/Arachnid/solidity-stringutils) has more string typecasting examples. 188 | 189 | - **Can't easily convert `bytes` to `address`**: need to manually convert each byte to `uint160`: 190 | 191 | ```solidity 192 | function bytesToAddress(bytes _address) public returns (address) { 193 | uint160 m = 0; 194 | uint160 b = 0; 195 | 196 | for (uint8 i = 0; i < 20; i++) { 197 | m *= 256; 198 | b = uint160(_address[i]); 199 | m += (b); 200 | } 201 | 202 | return address(m); 203 | } 204 | ``` 205 | 206 | - **The type is only deduced from the first assignment when using `var`**; so this can be dangerous in certain scenarios where it's initialized to a smaller data type then expected, causing undesired consequences, like the following: 207 | 208 | ```solidity 209 | contract MyContract { 210 | function loop() { 211 | /* `i` will have max a max value of 255 (initialized as uint8), 212 | * causing an infinite loop. 213 | */ 214 | for (var i = 0; i < 1000; i++) { 215 | 216 | } 217 | } 218 | } 219 | ``` 220 | 221 | It's best practice to use an explicit type (`var` is now deprecated). 222 | 223 | - **`uint` is alias to `uint256`**. 224 | 225 | - **`byte` is alias to `bytes1`**. 226 | 227 | - **`sha3` is alias to `keccak256`**. (keccak256 is preferred) 228 | 229 | - **`now` is alias to `block.timestamp`**. 230 | 231 | - **`bytes` is the same `byte[]` but packed tightly (more expensive)**. 232 | 233 | - **`string` is the same as `bytes` but doesn't allow length or index access**. 234 | 235 | - **Any type that can be converted to `uint160` can be converted to `address`**. 236 | 237 | - **`address`** is equivalent to `uint160`**. 238 | 239 | - **`public` vs `external` vs `internal` vs `private`** 240 | 241 | - `external`: function is part of the contract interface, which means it can be called from other contracts and via transactions. External functions are sometimes more efficient when they receive large arrays of data. Use external if you expect that the function will only ever be called externally. For external functions, the compiler doesn't need to allow internal calls, and so it allows arguments to be read directly from calldata, saving the copying step, which will save more gas. Also note that `external` functions *cannot* be inherited by other contracts! 242 | 243 | - `public`: function can either be called internally or externally. For public state variables, an automatic getter function is generated. 244 | 245 | - `internal`: function or state variables can only be accessed internally (i.e. from within the current contract or contracts deriving from it), without using `this`. 246 | 247 | - `private`: function or state variable is only visible for the contract they are defined in and not in derived contracts. 248 | 249 | - **`msg.sender` is the contract caller**; (aka contract creator if in the constructor). 250 | 251 | - **There's a limit to how many variables can be in a function**; this includes parameter and return variables. The limit is *16* variables, otherwise you get the `StackTooDeepException` error *"Internal compiler error: Stack too deep, try removing local variables."*. 252 | 253 | However if you need that many variables, then *you're probably doing something wrong*. You can break up the function into smaller functions, and set global variables to public to generate getters. 254 | 255 | - **`enum` variable type get compiled down to an `int8`**; (unless the enum has more than 8 options, in which case it walks up the int type scale). 256 | 257 | ```solidity 258 | contract MyContract { 259 | enum MyEnum { 260 | Foo, 261 | Bar, 262 | Qux 263 | } 264 | 265 | function MyContract() { 266 | assert(uint(MyEnum.Foo) == 0); 267 | assert(uint(MyEnum.Bar) == 1); 268 | assert(uint(MyEnum.Qux) == 2); 269 | } 270 | } 271 | ``` 272 | 273 | - **You have to use `new` keyword for creating variable length in-memory arrays**. As opposed to storage arrays, it's not possible to resize memory arrays by assigning to the `length` member. 274 | 275 | ```solidity 276 | contract MyContract { 277 | uint[] foo; 278 | 279 | function MyContract() { 280 | uint[] memory bar = new uint[](5); 281 | bytes memory qux = new bytes(5); 282 | 283 | // dynamically resize storage array 284 | foo.length = 6; 285 | foo[5] = 1; 286 | assert(foo[5] == 1); 287 | 288 | // doesn't work, will throw 289 | bar.length = 6; 290 | qux.length = 6; 291 | } 292 | } 293 | ``` 294 | 295 | - **The type of an array literal is a memory array of fixed size whose base type is the common type of the given elements**; e.g. the type of `[1, 2, 3]` is `uint8[3]` memory, because the type of each of these constants is `uint8`. Fixed size memory arrays can't be assigned to dynamically-sized memory arrays, e.g. the following is not possible: 296 | 297 | ```solidity 298 | contract MyContract { 299 | function MyContract() { 300 | /* This creates a `TypeError` because uint8[3] memory 301 | * can't be converted to uint256[] memory. 302 | */ 303 | uint[3] memory x = [1, 2, 3]; 304 | 305 | // This works, because it's the same common type. 306 | uint8[3] memory y = [1, 2, 3]; 307 | 308 | // This works, because it's the same common type. 309 | uint16[3] memory z = [256, 2, 3]; 310 | } 311 | } 312 | ``` 313 | 314 | - **Declaring a local array and assuming it'll be created in memory but it actually overwrites storage**; e.g. the type of the local variable `x` is `uint[]` storage, but it has to be assigned from a state variable before it can be used because storage is not dynamically allocated, so it functions only as an alias for a pre-existing variable in storage. What happens is that the compiler interprets `x` as a storage pointer and will make it point to the storage slot `0` by default, which in this case is variable `foo`, and is modified by `x.push(1)` causing an error. 315 | 316 | ```solidity 317 | contract MyContract { 318 | uint foo; 319 | uint[] bar; 320 | 321 | // This will not work! 322 | function MyContract() { 323 | uint[] x; 324 | x.push(1); 325 | bar = x; 326 | } 327 | } 328 | ``` 329 | 330 | do this instead: 331 | 332 | ```solidity 333 | contract MyContract() { 334 | uint foo; 335 | uint[] bar; 336 | 337 | function MyContract() { 338 | uint[] memory x = new uint[](5); 339 | x[0] = 1; 340 | bar = x; 341 | 342 | assert(foo == 0); 343 | assert(bar[0] == 1); 344 | } 345 | } 346 | ``` 347 | 348 | - **Solidity inherits scoping rules from JavaScript**; a variable declared anywhere within a function will be in scope for the entire function, regardless of where it's declared. There is no block scoping, e.g. the following examples: 349 | 350 | ```solidity 351 | contract MyContract { 352 | function MyContract() { 353 | uint i = 0; 354 | 355 | while (i++ < 1) { 356 | uint foo = 0; 357 | } 358 | 359 | while (i++ < 2) { 360 | // Illegal, second declaration of variable. 361 | uint foo = 0; 362 | } 363 | } 364 | } 365 | ``` 366 | 367 | ```solidity 368 | contract MyContract { 369 | function MyContract() { 370 | for (uint i = 0; i < 1; i ++) { 371 | 372 | } 373 | 374 | // Illegal, second declaration of variable. 375 | for (uint i = 0; i < 1; i++) { 376 | 377 | } 378 | } 379 | } 380 | ``` 381 | 382 | - **Integers will be truncated if they don't fit with the type range**; e.g. for `uint256` the range is `0` up to `2^256 - 1`, so if the result of an operation does not fit within the range then it's trucated and there can be serious consequences. Always perform assertions before modifying state e.g. making sure sender has enough token balance before sending to recipient. 383 | 384 | ```solidity 385 | require((balanceOf[to] + value) >= balanceOf[to]); 386 | ``` 387 | 388 | - **Exceptions consume all the gas**; EVM's only exception is `Out of Gas`, typically caused by an `invalid JUMP` error. 389 | 390 | - **`throw` is being deprecated in favor of `revert()`, `require()`, `assert()`**. 391 | 392 | - **Calls to external functions can fail, so always check return value**; like when using `send()`. 393 | 394 | - **Use `transfer()` instead of `send()`**; `transfer()` is equivalent of `require(x.send(y))` (will throw if not successful). 395 | 396 | There are some dangers in using send: The transfer fails if the call stack depth is at 1024 (this can always be forced by the caller) and it also fails if the recipient runs out of gas. 397 | 398 | A better solution is to use the pattern where the recipient withdraws the money. 399 | 400 | - **Calls are limited to a depth of 1024**; which means that for more complex operations, loops should be preferred over recursive calls. 401 | 402 | - **Have to declare the source file compiler version at the top of the contract file**; the `^` means to use the latest patch release (0.4.x), so it uses the most update to date version without any breaking changes. 403 | 404 | ```solidity 405 | pragma solidity ^0.4.4; 406 | 407 | contract MyContract { 408 | 409 | } 410 | ``` 411 | 412 | - **All primitive data types are initialized with default values**; there is no "null" data type (like in JavaScript). 413 | 414 | ```solidity 415 | contract MyContract { 416 | int n; // 0 417 | string str; // "" 418 | address addr; // 0x0000000000000000000000000000000000000000 419 | bool b; // false 420 | } 421 | ``` 422 | 423 | - **Date suffixes after literal numbers can be used to convert between units of time**, where seconds are the base unit and units are considered naively in the following way: 424 | 425 | ```solidity 426 | contract MyContract { 427 | function MyContract() { 428 | assert(1 == 1 seconds); 429 | assert(1 minutes == 60 seconds); 430 | assert(1 hours == 60 minutes); 431 | assert(1 days == 24 hours); 432 | assert(1 weeks == 7 days); 433 | assert(1 years == 365 days); 434 | } 435 | } 436 | ``` 437 | 438 | **But take care if you perform calendar calculations using these units**; not every year equals 365 days and not even every day has 24 hours because of leap seconds. Due to the fact that leap seconds cannot be predicted, an exact calendar library has to be updated by an external oracle. 439 | 440 | - **Date suffixes can't be applied to variables**; here's how you can interpret some input variable in, e.g days: 441 | 442 | ```solidity 443 | contract MyContract { 444 | function hasStarted(uint start, uint daysAfter) returns (bool) { 445 | return (now >= start + daysAfter * 1 days); 446 | } 447 | } 448 | ``` 449 | 450 | - **Generating random numbers is hard;** because Ethereum a deterministic system. You can generate a "random" number based on the block hash and block number, but keep in mind that miners have influence on these values. 451 | 452 | ```solidity 453 | contract MyContract { 454 | function rand(uint min, uint max) public returns (uint) { 455 | return uint(block.blockhash(block.number-1))%(min+max)-min; 456 | } 457 | } 458 | ``` 459 | 460 | - **Have to use `indexed` keyword for events parameters to allow events them to be searchable**; it allows you to search for the events using the indexed parameters as filters. 461 | 462 | ```solidity 463 | contract MyContract { 464 | event Transfer(address indexed sender, address indexed recipient, uint256 amount); 465 | } 466 | ``` 467 | 468 | ```javascript 469 | // Filter by indexed parameter. 470 | myContract.events.Transfer({sender: '0x123...abc'}, (error, events) => {}) 471 | 472 | /* Can't filter by un-indexed parameter, 473 | * so this won't work. 474 | */ 475 | myContract.events.Transfer({amount: 1}, (error, events) => {}) 476 | ``` 477 | 478 | - **Only up to three parameters can receive the attribute `indexed` for event parameters.** 479 | 480 | - **You can specify named output parameters in `returns` signature which creates new local variables.** 481 | 482 | ```solidity 483 | contract MyContract { 484 | function MyContract() { 485 | assert(myMethod() == 10); 486 | } 487 | 488 | function myMethod() returns (uint num) { 489 | num = 10; 490 | return num; 491 | } 492 | } 493 | ``` 494 | 495 | but make sure to rename it different than storage variables since it can override them. 496 | 497 | - **Need to use `payable` modifier to allow function to receive ether**; otherwise the transaction will be rejected. 498 | 499 | - **`assert` will use up all remaining gas**; after Metropolis, `require` behaves like `revert` which refunds remaining gas which is preferable. Use `assert` for runtime error catching where conditions should never ever be possible. 500 | 501 | - **Contracts can't activate themselves**; they need a "poke", e.g. a contract can't automatically do something when it reaches a certain block number (like a cron job). There needs to be a call from the outside for the contract to do something; an external poke. 502 | 503 | #### Remix 504 | 505 | - **Need to pass an array of single bytes instead of string for addresses**; e.g. `"0x2680EA4C9AbAfAa63C2957DD3951017d5BBAc518"` will be interpreted as a string rather than hex bytes. To pass an address represented in bytes you need to break up the address into an array of single bytes, e.g. `["0x26", "0x80", "0xEA", ... "0xBA", "0xc5", "0x18"]`, when sending in via Remix browser interface. 506 | 507 | #### Example code 508 | 509 | Example code available in the [`contracts/`](./contracts/) directory. 510 | 511 | ## Contributing 512 | 513 | Pull requests are always welcomed for explaining or showing a solidity feature that is not intuitive. 514 | 515 | ## Issues 516 | 517 | Ethereum and Solidity are quickly evolving so some things may no longer be relevant in the future. 518 | 519 | Please submit an issue or make a pull request if something in incorrect. 520 | 521 | ## Credits 522 | 523 | - Credits to the people contributing on Ethereum Stack Exchange, where I read a lot of the solutions from. 524 | 525 | ## Resources 526 | 527 | - [Solidity](https://github.com/ethereum/solidity) 528 | 529 | - [Truffle](https://github.com/trufflesuite/truffle) 530 | 531 | - [Smart Contract Best Practices](https://github.com/ConsenSys/smart-contract-best-practices) 532 | 533 | - [Solidity Baby Steps](https://github.com/fivedogit/solidity-baby-steps) 534 | 535 | - [Ethereum Stack Exchange](https://ethereum.stackexchange.com/) 536 | 537 | ## License 538 | 539 | [MIT](LICENSE) 540 | -------------------------------------------------------------------------------- /assets/headbang.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/miguelmota/solidity-idiosyncrasies/87bbb7dc3ae11cb3dbde9b5af5dd83dad806886c/assets/headbang.gif -------------------------------------------------------------------------------- /build/contracts/MemoryArray.json: -------------------------------------------------------------------------------- 1 | { 2 | "contractName": "MemoryArray", 3 | "abi": [ 4 | { 5 | "inputs": [], 6 | "payable": false, 7 | "stateMutability": "nonpayable", 8 | "type": "constructor" 9 | } 10 | ], 11 | "bytecode": "0x6060604052341561000f57600080fd5b6100176100c6565b61001f6100da565b600560405180591061002e5750595b9080825280602002602001820160405250915060056040518059106100505750595b9080825280601f01601f19166020018201604052509050600660008161007691906100ee565b5060016000600581548110151561008957fe5b9060005260206000209001819055506001600060058154811015156100aa57fe5b9060005260206000209001541415156100bf57fe5b505061013f565b602060405190810160405280600081525090565b602060405190810160405280600081525090565b81548183558181151161011557818360005260206000209182019101610114919061011a565b5b505050565b61013c91905b80821115610138576000816000905550600101610120565b5090565b90565b60358061014d6000396000f3006060604052600080fd00a165627a7a723058207f65291326ba7f8273e630ef745cce07d3e519a6543fdac1e301ed651c0a1ce50029", 12 | "deployedBytecode": "0x6060604052600080fd00a165627a7a723058207f65291326ba7f8273e630ef745cce07d3e519a6543fdac1e301ed651c0a1ce50029", 13 | "sourceMap": "25:316:11:-;;;65:274;;;;;;;;95:17;;:::i;:::-;134:16;;:::i;:::-;126:1;115:13;;;;;;;;;;;;;;;;;;;;;;;;95:33;;163:1;153:12;;;;;;;;;;;;;;;;;;;;;;;;;;;134:31;;225:1;212:3;:14;;;;;:::i;:::-;;241:1;232:3;236:1;232:6;;;;;;;;;;;;;;;;;;:10;;;;265:1;255:3;259:1;255:6;;;;;;;;;;;;;;;;;;;:11;248:19;;;;;;65:274;;25:316;;;;;;;;;;;;;;;;;:::o;:::-;;;;;;;;;;;;;;;:::o;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;;;;;:::o;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;:::o;:::-;;;;;;;", 14 | "deployedSourceMap": "25:316:11:-;;;;;", 15 | "source": "pragma solidity ^0.4.4;\n\ncontract MemoryArray {\n uint[] foo;\n\n function MemoryArray () {\n uint[] memory bar = new uint[](5);\n bytes memory qux = new bytes(5);\n\n // dynamically resize storage array\n foo.length = 6;\n foo[5] = 1;\n assert(foo[5] == 1);\n\n // doesn't work\n // bar.length = 6;\n // qux.length = 6;\n }\n}\n", 16 | "sourcePath": "/Users/mota/Sandbox/solidity-idiosyncrasies/contracts/MemoryArray.sol", 17 | "ast": { 18 | "attributes": { 19 | "absolutePath": "/Users/mota/Sandbox/solidity-idiosyncrasies/contracts/MemoryArray.sol", 20 | "exportedSymbols": { 21 | "MemoryArray": [ 22 | 484 23 | ] 24 | } 25 | }, 26 | "children": [ 27 | { 28 | "attributes": { 29 | "literals": [ 30 | "solidity", 31 | "^", 32 | "0.4", 33 | ".4" 34 | ] 35 | }, 36 | "id": 439, 37 | "name": "PragmaDirective", 38 | "src": "0:23:11" 39 | }, 40 | { 41 | "attributes": { 42 | "baseContracts": [ 43 | null 44 | ], 45 | "contractDependencies": [ 46 | null 47 | ], 48 | "contractKind": "contract", 49 | "documentation": null, 50 | "fullyImplemented": true, 51 | "linearizedBaseContracts": [ 52 | 484 53 | ], 54 | "name": "MemoryArray", 55 | "scope": 485 56 | }, 57 | "children": [ 58 | { 59 | "attributes": { 60 | "constant": false, 61 | "name": "foo", 62 | "scope": 484, 63 | "stateVariable": true, 64 | "storageLocation": "default", 65 | "type": "uint256[] storage ref", 66 | "value": null, 67 | "visibility": "internal" 68 | }, 69 | "children": [ 70 | { 71 | "attributes": { 72 | "length": null, 73 | "type": "uint256[] storage pointer" 74 | }, 75 | "children": [ 76 | { 77 | "attributes": { 78 | "name": "uint", 79 | "type": "uint256" 80 | }, 81 | "id": 440, 82 | "name": "ElementaryTypeName", 83 | "src": "50:4:11" 84 | } 85 | ], 86 | "id": 441, 87 | "name": "ArrayTypeName", 88 | "src": "50:6:11" 89 | } 90 | ], 91 | "id": 442, 92 | "name": "VariableDeclaration", 93 | "src": "50:10:11" 94 | }, 95 | { 96 | "attributes": { 97 | "constant": false, 98 | "implemented": true, 99 | "isConstructor": true, 100 | "modifiers": [ 101 | null 102 | ], 103 | "name": "MemoryArray", 104 | "payable": false, 105 | "scope": 484, 106 | "stateMutability": "nonpayable", 107 | "superFunction": null, 108 | "visibility": "public" 109 | }, 110 | "children": [ 111 | { 112 | "attributes": { 113 | "parameters": [ 114 | null 115 | ] 116 | }, 117 | "children": [], 118 | "id": 443, 119 | "name": "ParameterList", 120 | "src": "86:2:11" 121 | }, 122 | { 123 | "attributes": { 124 | "parameters": [ 125 | null 126 | ] 127 | }, 128 | "children": [], 129 | "id": 444, 130 | "name": "ParameterList", 131 | "src": "89:0:11" 132 | }, 133 | { 134 | "children": [ 135 | { 136 | "attributes": { 137 | "assignments": [ 138 | 448 139 | ] 140 | }, 141 | "children": [ 142 | { 143 | "attributes": { 144 | "constant": false, 145 | "name": "bar", 146 | "scope": 483, 147 | "stateVariable": false, 148 | "storageLocation": "memory", 149 | "type": "uint256[] memory", 150 | "value": null, 151 | "visibility": "internal" 152 | }, 153 | "children": [ 154 | { 155 | "attributes": { 156 | "length": null, 157 | "type": "uint256[] storage pointer" 158 | }, 159 | "children": [ 160 | { 161 | "attributes": { 162 | "name": "uint", 163 | "type": "uint256" 164 | }, 165 | "id": 446, 166 | "name": "ElementaryTypeName", 167 | "src": "95:4:11" 168 | } 169 | ], 170 | "id": 447, 171 | "name": "ArrayTypeName", 172 | "src": "95:6:11" 173 | } 174 | ], 175 | "id": 448, 176 | "name": "VariableDeclaration", 177 | "src": "95:17:11" 178 | }, 179 | { 180 | "attributes": { 181 | "argumentTypes": null, 182 | "isConstant": false, 183 | "isLValue": false, 184 | "isPure": true, 185 | "isStructConstructorCall": false, 186 | "lValueRequested": false, 187 | "names": [ 188 | null 189 | ], 190 | "type": "uint256[] memory", 191 | "type_conversion": false 192 | }, 193 | "children": [ 194 | { 195 | "attributes": { 196 | "argumentTypes": [ 197 | { 198 | "typeIdentifier": "t_rational_5_by_1", 199 | "typeString": "int_const 5" 200 | } 201 | ], 202 | "isConstant": false, 203 | "isLValue": false, 204 | "isPure": true, 205 | "lValueRequested": false, 206 | "type": "function (uint256) pure returns (uint256[] memory)" 207 | }, 208 | "children": [ 209 | { 210 | "attributes": { 211 | "length": null, 212 | "type": "uint256[] storage pointer" 213 | }, 214 | "children": [ 215 | { 216 | "attributes": { 217 | "name": "uint", 218 | "type": "uint256" 219 | }, 220 | "id": 449, 221 | "name": "ElementaryTypeName", 222 | "src": "119:4:11" 223 | } 224 | ], 225 | "id": 450, 226 | "name": "ArrayTypeName", 227 | "src": "119:6:11" 228 | } 229 | ], 230 | "id": 451, 231 | "name": "NewExpression", 232 | "src": "115:10:11" 233 | }, 234 | { 235 | "attributes": { 236 | "argumentTypes": null, 237 | "hexvalue": "35", 238 | "isConstant": false, 239 | "isLValue": false, 240 | "isPure": true, 241 | "lValueRequested": false, 242 | "subdenomination": null, 243 | "token": "number", 244 | "type": "int_const 5", 245 | "value": "5" 246 | }, 247 | "id": 452, 248 | "name": "Literal", 249 | "src": "126:1:11" 250 | } 251 | ], 252 | "id": 453, 253 | "name": "FunctionCall", 254 | "src": "115:13:11" 255 | } 256 | ], 257 | "id": 454, 258 | "name": "VariableDeclarationStatement", 259 | "src": "95:33:11" 260 | }, 261 | { 262 | "attributes": { 263 | "assignments": [ 264 | 456 265 | ] 266 | }, 267 | "children": [ 268 | { 269 | "attributes": { 270 | "constant": false, 271 | "name": "qux", 272 | "scope": 483, 273 | "stateVariable": false, 274 | "storageLocation": "memory", 275 | "type": "bytes memory", 276 | "value": null, 277 | "visibility": "internal" 278 | }, 279 | "children": [ 280 | { 281 | "attributes": { 282 | "name": "bytes", 283 | "type": "bytes storage pointer" 284 | }, 285 | "id": 455, 286 | "name": "ElementaryTypeName", 287 | "src": "134:5:11" 288 | } 289 | ], 290 | "id": 456, 291 | "name": "VariableDeclaration", 292 | "src": "134:16:11" 293 | }, 294 | { 295 | "attributes": { 296 | "argumentTypes": null, 297 | "isConstant": false, 298 | "isLValue": false, 299 | "isPure": true, 300 | "isStructConstructorCall": false, 301 | "lValueRequested": false, 302 | "names": [ 303 | null 304 | ], 305 | "type": "bytes memory", 306 | "type_conversion": false 307 | }, 308 | "children": [ 309 | { 310 | "attributes": { 311 | "argumentTypes": [ 312 | { 313 | "typeIdentifier": "t_rational_5_by_1", 314 | "typeString": "int_const 5" 315 | } 316 | ], 317 | "isConstant": false, 318 | "isLValue": false, 319 | "isPure": true, 320 | "lValueRequested": false, 321 | "type": "function (uint256) pure returns (bytes memory)" 322 | }, 323 | "children": [ 324 | { 325 | "attributes": { 326 | "name": "bytes", 327 | "type": "bytes storage pointer" 328 | }, 329 | "id": 457, 330 | "name": "ElementaryTypeName", 331 | "src": "157:5:11" 332 | } 333 | ], 334 | "id": 458, 335 | "name": "NewExpression", 336 | "src": "153:9:11" 337 | }, 338 | { 339 | "attributes": { 340 | "argumentTypes": null, 341 | "hexvalue": "35", 342 | "isConstant": false, 343 | "isLValue": false, 344 | "isPure": true, 345 | "lValueRequested": false, 346 | "subdenomination": null, 347 | "token": "number", 348 | "type": "int_const 5", 349 | "value": "5" 350 | }, 351 | "id": 459, 352 | "name": "Literal", 353 | "src": "163:1:11" 354 | } 355 | ], 356 | "id": 460, 357 | "name": "FunctionCall", 358 | "src": "153:12:11" 359 | } 360 | ], 361 | "id": 461, 362 | "name": "VariableDeclarationStatement", 363 | "src": "134:31:11" 364 | }, 365 | { 366 | "children": [ 367 | { 368 | "attributes": { 369 | "argumentTypes": null, 370 | "isConstant": false, 371 | "isLValue": false, 372 | "isPure": false, 373 | "lValueRequested": false, 374 | "operator": "=", 375 | "type": "uint256" 376 | }, 377 | "children": [ 378 | { 379 | "attributes": { 380 | "argumentTypes": null, 381 | "isConstant": false, 382 | "isLValue": true, 383 | "isPure": false, 384 | "lValueRequested": true, 385 | "member_name": "length", 386 | "referencedDeclaration": null, 387 | "type": "uint256" 388 | }, 389 | "children": [ 390 | { 391 | "attributes": { 392 | "argumentTypes": null, 393 | "overloadedDeclarations": [ 394 | null 395 | ], 396 | "referencedDeclaration": 442, 397 | "type": "uint256[] storage ref", 398 | "value": "foo" 399 | }, 400 | "id": 462, 401 | "name": "Identifier", 402 | "src": "212:3:11" 403 | } 404 | ], 405 | "id": 464, 406 | "name": "MemberAccess", 407 | "src": "212:10:11" 408 | }, 409 | { 410 | "attributes": { 411 | "argumentTypes": null, 412 | "hexvalue": "36", 413 | "isConstant": false, 414 | "isLValue": false, 415 | "isPure": true, 416 | "lValueRequested": false, 417 | "subdenomination": null, 418 | "token": "number", 419 | "type": "int_const 6", 420 | "value": "6" 421 | }, 422 | "id": 465, 423 | "name": "Literal", 424 | "src": "225:1:11" 425 | } 426 | ], 427 | "id": 466, 428 | "name": "Assignment", 429 | "src": "212:14:11" 430 | } 431 | ], 432 | "id": 467, 433 | "name": "ExpressionStatement", 434 | "src": "212:14:11" 435 | }, 436 | { 437 | "children": [ 438 | { 439 | "attributes": { 440 | "argumentTypes": null, 441 | "isConstant": false, 442 | "isLValue": false, 443 | "isPure": false, 444 | "lValueRequested": false, 445 | "operator": "=", 446 | "type": "uint256" 447 | }, 448 | "children": [ 449 | { 450 | "attributes": { 451 | "argumentTypes": null, 452 | "isConstant": false, 453 | "isLValue": true, 454 | "isPure": false, 455 | "lValueRequested": true, 456 | "type": "uint256" 457 | }, 458 | "children": [ 459 | { 460 | "attributes": { 461 | "argumentTypes": null, 462 | "overloadedDeclarations": [ 463 | null 464 | ], 465 | "referencedDeclaration": 442, 466 | "type": "uint256[] storage ref", 467 | "value": "foo" 468 | }, 469 | "id": 468, 470 | "name": "Identifier", 471 | "src": "232:3:11" 472 | }, 473 | { 474 | "attributes": { 475 | "argumentTypes": null, 476 | "hexvalue": "35", 477 | "isConstant": false, 478 | "isLValue": false, 479 | "isPure": true, 480 | "lValueRequested": false, 481 | "subdenomination": null, 482 | "token": "number", 483 | "type": "int_const 5", 484 | "value": "5" 485 | }, 486 | "id": 469, 487 | "name": "Literal", 488 | "src": "236:1:11" 489 | } 490 | ], 491 | "id": 470, 492 | "name": "IndexAccess", 493 | "src": "232:6:11" 494 | }, 495 | { 496 | "attributes": { 497 | "argumentTypes": null, 498 | "hexvalue": "31", 499 | "isConstant": false, 500 | "isLValue": false, 501 | "isPure": true, 502 | "lValueRequested": false, 503 | "subdenomination": null, 504 | "token": "number", 505 | "type": "int_const 1", 506 | "value": "1" 507 | }, 508 | "id": 471, 509 | "name": "Literal", 510 | "src": "241:1:11" 511 | } 512 | ], 513 | "id": 472, 514 | "name": "Assignment", 515 | "src": "232:10:11" 516 | } 517 | ], 518 | "id": 473, 519 | "name": "ExpressionStatement", 520 | "src": "232:10:11" 521 | }, 522 | { 523 | "children": [ 524 | { 525 | "attributes": { 526 | "argumentTypes": null, 527 | "isConstant": false, 528 | "isLValue": false, 529 | "isPure": false, 530 | "isStructConstructorCall": false, 531 | "lValueRequested": false, 532 | "names": [ 533 | null 534 | ], 535 | "type": "tuple()", 536 | "type_conversion": false 537 | }, 538 | "children": [ 539 | { 540 | "attributes": { 541 | "argumentTypes": [ 542 | { 543 | "typeIdentifier": "t_bool", 544 | "typeString": "bool" 545 | } 546 | ], 547 | "overloadedDeclarations": [ 548 | null 549 | ], 550 | "referencedDeclaration": 1185, 551 | "type": "function (bool) pure", 552 | "value": "assert" 553 | }, 554 | "id": 474, 555 | "name": "Identifier", 556 | "src": "248:6:11" 557 | }, 558 | { 559 | "attributes": { 560 | "argumentTypes": null, 561 | "commonType": { 562 | "typeIdentifier": "t_uint256", 563 | "typeString": "uint256" 564 | }, 565 | "isConstant": false, 566 | "isLValue": false, 567 | "isPure": false, 568 | "lValueRequested": false, 569 | "operator": "==", 570 | "type": "bool" 571 | }, 572 | "children": [ 573 | { 574 | "attributes": { 575 | "argumentTypes": null, 576 | "isConstant": false, 577 | "isLValue": true, 578 | "isPure": false, 579 | "lValueRequested": false, 580 | "type": "uint256" 581 | }, 582 | "children": [ 583 | { 584 | "attributes": { 585 | "argumentTypes": null, 586 | "overloadedDeclarations": [ 587 | null 588 | ], 589 | "referencedDeclaration": 442, 590 | "type": "uint256[] storage ref", 591 | "value": "foo" 592 | }, 593 | "id": 475, 594 | "name": "Identifier", 595 | "src": "255:3:11" 596 | }, 597 | { 598 | "attributes": { 599 | "argumentTypes": null, 600 | "hexvalue": "35", 601 | "isConstant": false, 602 | "isLValue": false, 603 | "isPure": true, 604 | "lValueRequested": false, 605 | "subdenomination": null, 606 | "token": "number", 607 | "type": "int_const 5", 608 | "value": "5" 609 | }, 610 | "id": 476, 611 | "name": "Literal", 612 | "src": "259:1:11" 613 | } 614 | ], 615 | "id": 477, 616 | "name": "IndexAccess", 617 | "src": "255:6:11" 618 | }, 619 | { 620 | "attributes": { 621 | "argumentTypes": null, 622 | "hexvalue": "31", 623 | "isConstant": false, 624 | "isLValue": false, 625 | "isPure": true, 626 | "lValueRequested": false, 627 | "subdenomination": null, 628 | "token": "number", 629 | "type": "int_const 1", 630 | "value": "1" 631 | }, 632 | "id": 478, 633 | "name": "Literal", 634 | "src": "265:1:11" 635 | } 636 | ], 637 | "id": 479, 638 | "name": "BinaryOperation", 639 | "src": "255:11:11" 640 | } 641 | ], 642 | "id": 480, 643 | "name": "FunctionCall", 644 | "src": "248:19:11" 645 | } 646 | ], 647 | "id": 481, 648 | "name": "ExpressionStatement", 649 | "src": "248:19:11" 650 | } 651 | ], 652 | "id": 482, 653 | "name": "Block", 654 | "src": "89:250:11" 655 | } 656 | ], 657 | "id": 483, 658 | "name": "FunctionDefinition", 659 | "src": "65:274:11" 660 | } 661 | ], 662 | "id": 484, 663 | "name": "ContractDefinition", 664 | "src": "25:316:11" 665 | } 666 | ], 667 | "id": 485, 668 | "name": "SourceUnit", 669 | "src": "0:342:11" 670 | }, 671 | "compiler": { 672 | "name": "solc", 673 | "version": "0.4.18+commit.9cf6e910.Emscripten.clang" 674 | }, 675 | "networks": {}, 676 | "schemaVersion": "1.0.1", 677 | "updatedAt": "2018-01-20T00:19:40.117Z" 678 | } -------------------------------------------------------------------------------- /build/contracts/Migrations.json: -------------------------------------------------------------------------------- 1 | { 2 | "contractName": "Migrations", 3 | "abi": [ 4 | { 5 | "constant": false, 6 | "inputs": [ 7 | { 8 | "name": "new_address", 9 | "type": "address" 10 | } 11 | ], 12 | "name": "upgrade", 13 | "outputs": [], 14 | "payable": false, 15 | "stateMutability": "nonpayable", 16 | "type": "function" 17 | }, 18 | { 19 | "constant": true, 20 | "inputs": [], 21 | "name": "last_completed_migration", 22 | "outputs": [ 23 | { 24 | "name": "", 25 | "type": "uint256" 26 | } 27 | ], 28 | "payable": false, 29 | "stateMutability": "view", 30 | "type": "function" 31 | }, 32 | { 33 | "constant": true, 34 | "inputs": [], 35 | "name": "owner", 36 | "outputs": [ 37 | { 38 | "name": "", 39 | "type": "address" 40 | } 41 | ], 42 | "payable": false, 43 | "stateMutability": "view", 44 | "type": "function" 45 | }, 46 | { 47 | "constant": false, 48 | "inputs": [ 49 | { 50 | "name": "completed", 51 | "type": "uint256" 52 | } 53 | ], 54 | "name": "setCompleted", 55 | "outputs": [], 56 | "payable": false, 57 | "stateMutability": "nonpayable", 58 | "type": "function" 59 | }, 60 | { 61 | "inputs": [], 62 | "payable": false, 63 | "stateMutability": "nonpayable", 64 | "type": "constructor" 65 | } 66 | ], 67 | "bytecode": "0x6060604052341561000f57600080fd5b336000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055506102db8061005e6000396000f300606060405260043610610062576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff1680630900f01014610067578063445df0ac146100a05780638da5cb5b146100c9578063fdacd5761461011e575b600080fd5b341561007257600080fd5b61009e600480803573ffffffffffffffffffffffffffffffffffffffff16906020019091905050610141565b005b34156100ab57600080fd5b6100b3610224565b6040518082815260200191505060405180910390f35b34156100d457600080fd5b6100dc61022a565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b341561012957600080fd5b61013f600480803590602001909190505061024f565b005b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161415610220578190508073ffffffffffffffffffffffffffffffffffffffff1663fdacd5766001546040518263ffffffff167c010000000000000000000000000000000000000000000000000000000002815260040180828152602001915050600060405180830381600087803b151561020b57600080fd5b6102c65a03f1151561021c57600080fd5b5050505b5050565b60015481565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614156102ac57806001819055505b505600a165627a7a7230582013492bd47b531f0796f560009cdb276051f41b1eb4aa9c70608798c1ea64bbd50029", 68 | "deployedBytecode": "0x606060405260043610610062576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff1680630900f01014610067578063445df0ac146100a05780638da5cb5b146100c9578063fdacd5761461011e575b600080fd5b341561007257600080fd5b61009e600480803573ffffffffffffffffffffffffffffffffffffffff16906020019091905050610141565b005b34156100ab57600080fd5b6100b3610224565b6040518082815260200191505060405180910390f35b34156100d457600080fd5b6100dc61022a565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b341561012957600080fd5b61013f600480803590602001909190505061024f565b005b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161415610220578190508073ffffffffffffffffffffffffffffffffffffffff1663fdacd5766001546040518263ffffffff167c010000000000000000000000000000000000000000000000000000000002815260040180828152602001915050600060405180830381600087803b151561020b57600080fd5b6102c65a03f1151561021c57600080fd5b5050505b5050565b60015481565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614156102ac57806001819055505b505600a165627a7a7230582013492bd47b531f0796f560009cdb276051f41b1eb4aa9c70608798c1ea64bbd50029", 69 | "sourceMap": "25:467:12:-;;;177:51;;;;;;;;213:10;205:5;;:18;;;;;;;;;;;;;;;;;;25:467;;;;;;", 70 | "deployedSourceMap": "25:467:12:-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;332:158;;;;;;;;;;;;;;;;;;;;;;;;;;;;73:36;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;49:20;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;232:96;;;;;;;;;;;;;;;;;;;;;;;;;;332:158;387:19;160:5;;;;;;;;;;;146:19;;:10;:19;;;142:26;;;420:11;387:45;;438:8;:21;;;460:24;;438:47;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;142:26;332:158;;:::o;73:36::-;;;;:::o;49:20::-;;;;;;;;;;;;;:::o;232:96::-;160:5;;;;;;;;;;;146:19;;:10;:19;;;142:26;;;314:9;287:24;:36;;;;142:26;232:96;:::o", 71 | "source": "pragma solidity ^0.4.4;\n\ncontract Migrations {\n address public owner;\n uint public last_completed_migration;\n\n modifier restricted() {\n if (msg.sender == owner) _;\n }\n\n function Migrations() {\n owner = msg.sender;\n }\n\n function setCompleted(uint completed) restricted {\n last_completed_migration = completed;\n }\n\n function upgrade(address new_address) restricted {\n Migrations upgraded = Migrations(new_address);\n upgraded.setCompleted(last_completed_migration);\n }\n}\n", 72 | "sourcePath": "/Users/mota/Sandbox/solidity-idiosyncrasies/contracts/Migrations.sol", 73 | "ast": { 74 | "attributes": { 75 | "absolutePath": "/Users/mota/Sandbox/solidity-idiosyncrasies/contracts/Migrations.sol", 76 | "exportedSymbols": { 77 | "Migrations": [ 78 | 541 79 | ] 80 | } 81 | }, 82 | "children": [ 83 | { 84 | "attributes": { 85 | "literals": [ 86 | "solidity", 87 | "^", 88 | "0.4", 89 | ".4" 90 | ] 91 | }, 92 | "id": 486, 93 | "name": "PragmaDirective", 94 | "src": "0:23:12" 95 | }, 96 | { 97 | "attributes": { 98 | "baseContracts": [ 99 | null 100 | ], 101 | "contractDependencies": [ 102 | null 103 | ], 104 | "contractKind": "contract", 105 | "documentation": null, 106 | "fullyImplemented": true, 107 | "linearizedBaseContracts": [ 108 | 541 109 | ], 110 | "name": "Migrations", 111 | "scope": 542 112 | }, 113 | "children": [ 114 | { 115 | "attributes": { 116 | "constant": false, 117 | "name": "owner", 118 | "scope": 541, 119 | "stateVariable": true, 120 | "storageLocation": "default", 121 | "type": "address", 122 | "value": null, 123 | "visibility": "public" 124 | }, 125 | "children": [ 126 | { 127 | "attributes": { 128 | "name": "address", 129 | "type": "address" 130 | }, 131 | "id": 487, 132 | "name": "ElementaryTypeName", 133 | "src": "49:7:12" 134 | } 135 | ], 136 | "id": 488, 137 | "name": "VariableDeclaration", 138 | "src": "49:20:12" 139 | }, 140 | { 141 | "attributes": { 142 | "constant": false, 143 | "name": "last_completed_migration", 144 | "scope": 541, 145 | "stateVariable": true, 146 | "storageLocation": "default", 147 | "type": "uint256", 148 | "value": null, 149 | "visibility": "public" 150 | }, 151 | "children": [ 152 | { 153 | "attributes": { 154 | "name": "uint", 155 | "type": "uint256" 156 | }, 157 | "id": 489, 158 | "name": "ElementaryTypeName", 159 | "src": "73:4:12" 160 | } 161 | ], 162 | "id": 490, 163 | "name": "VariableDeclaration", 164 | "src": "73:36:12" 165 | }, 166 | { 167 | "attributes": { 168 | "name": "restricted", 169 | "visibility": "internal" 170 | }, 171 | "children": [ 172 | { 173 | "attributes": { 174 | "parameters": [ 175 | null 176 | ] 177 | }, 178 | "children": [], 179 | "id": 491, 180 | "name": "ParameterList", 181 | "src": "133:2:12" 182 | }, 183 | { 184 | "children": [ 185 | { 186 | "attributes": { 187 | "falseBody": null 188 | }, 189 | "children": [ 190 | { 191 | "attributes": { 192 | "argumentTypes": null, 193 | "commonType": { 194 | "typeIdentifier": "t_address", 195 | "typeString": "address" 196 | }, 197 | "isConstant": false, 198 | "isLValue": false, 199 | "isPure": false, 200 | "lValueRequested": false, 201 | "operator": "==", 202 | "type": "bool" 203 | }, 204 | "children": [ 205 | { 206 | "attributes": { 207 | "argumentTypes": null, 208 | "isConstant": false, 209 | "isLValue": false, 210 | "isPure": false, 211 | "lValueRequested": false, 212 | "member_name": "sender", 213 | "referencedDeclaration": null, 214 | "type": "address" 215 | }, 216 | "children": [ 217 | { 218 | "attributes": { 219 | "argumentTypes": null, 220 | "overloadedDeclarations": [ 221 | null 222 | ], 223 | "referencedDeclaration": 1194, 224 | "type": "msg", 225 | "value": "msg" 226 | }, 227 | "id": 492, 228 | "name": "Identifier", 229 | "src": "146:3:12" 230 | } 231 | ], 232 | "id": 493, 233 | "name": "MemberAccess", 234 | "src": "146:10:12" 235 | }, 236 | { 237 | "attributes": { 238 | "argumentTypes": null, 239 | "overloadedDeclarations": [ 240 | null 241 | ], 242 | "referencedDeclaration": 488, 243 | "type": "address", 244 | "value": "owner" 245 | }, 246 | "id": 494, 247 | "name": "Identifier", 248 | "src": "160:5:12" 249 | } 250 | ], 251 | "id": 495, 252 | "name": "BinaryOperation", 253 | "src": "146:19:12" 254 | }, 255 | { 256 | "id": 496, 257 | "name": "PlaceholderStatement", 258 | "src": "167:1:12" 259 | } 260 | ], 261 | "id": 497, 262 | "name": "IfStatement", 263 | "src": "142:26:12" 264 | } 265 | ], 266 | "id": 498, 267 | "name": "Block", 268 | "src": "136:37:12" 269 | } 270 | ], 271 | "id": 499, 272 | "name": "ModifierDefinition", 273 | "src": "114:59:12" 274 | }, 275 | { 276 | "attributes": { 277 | "constant": false, 278 | "implemented": true, 279 | "isConstructor": true, 280 | "modifiers": [ 281 | null 282 | ], 283 | "name": "Migrations", 284 | "payable": false, 285 | "scope": 541, 286 | "stateMutability": "nonpayable", 287 | "superFunction": null, 288 | "visibility": "public" 289 | }, 290 | "children": [ 291 | { 292 | "attributes": { 293 | "parameters": [ 294 | null 295 | ] 296 | }, 297 | "children": [], 298 | "id": 500, 299 | "name": "ParameterList", 300 | "src": "196:2:12" 301 | }, 302 | { 303 | "attributes": { 304 | "parameters": [ 305 | null 306 | ] 307 | }, 308 | "children": [], 309 | "id": 501, 310 | "name": "ParameterList", 311 | "src": "199:0:12" 312 | }, 313 | { 314 | "children": [ 315 | { 316 | "children": [ 317 | { 318 | "attributes": { 319 | "argumentTypes": null, 320 | "isConstant": false, 321 | "isLValue": false, 322 | "isPure": false, 323 | "lValueRequested": false, 324 | "operator": "=", 325 | "type": "address" 326 | }, 327 | "children": [ 328 | { 329 | "attributes": { 330 | "argumentTypes": null, 331 | "overloadedDeclarations": [ 332 | null 333 | ], 334 | "referencedDeclaration": 488, 335 | "type": "address", 336 | "value": "owner" 337 | }, 338 | "id": 502, 339 | "name": "Identifier", 340 | "src": "205:5:12" 341 | }, 342 | { 343 | "attributes": { 344 | "argumentTypes": null, 345 | "isConstant": false, 346 | "isLValue": false, 347 | "isPure": false, 348 | "lValueRequested": false, 349 | "member_name": "sender", 350 | "referencedDeclaration": null, 351 | "type": "address" 352 | }, 353 | "children": [ 354 | { 355 | "attributes": { 356 | "argumentTypes": null, 357 | "overloadedDeclarations": [ 358 | null 359 | ], 360 | "referencedDeclaration": 1194, 361 | "type": "msg", 362 | "value": "msg" 363 | }, 364 | "id": 503, 365 | "name": "Identifier", 366 | "src": "213:3:12" 367 | } 368 | ], 369 | "id": 504, 370 | "name": "MemberAccess", 371 | "src": "213:10:12" 372 | } 373 | ], 374 | "id": 505, 375 | "name": "Assignment", 376 | "src": "205:18:12" 377 | } 378 | ], 379 | "id": 506, 380 | "name": "ExpressionStatement", 381 | "src": "205:18:12" 382 | } 383 | ], 384 | "id": 507, 385 | "name": "Block", 386 | "src": "199:29:12" 387 | } 388 | ], 389 | "id": 508, 390 | "name": "FunctionDefinition", 391 | "src": "177:51:12" 392 | }, 393 | { 394 | "attributes": { 395 | "constant": false, 396 | "implemented": true, 397 | "isConstructor": false, 398 | "name": "setCompleted", 399 | "payable": false, 400 | "scope": 541, 401 | "stateMutability": "nonpayable", 402 | "superFunction": null, 403 | "visibility": "public" 404 | }, 405 | "children": [ 406 | { 407 | "children": [ 408 | { 409 | "attributes": { 410 | "constant": false, 411 | "name": "completed", 412 | "scope": 520, 413 | "stateVariable": false, 414 | "storageLocation": "default", 415 | "type": "uint256", 416 | "value": null, 417 | "visibility": "internal" 418 | }, 419 | "children": [ 420 | { 421 | "attributes": { 422 | "name": "uint", 423 | "type": "uint256" 424 | }, 425 | "id": 509, 426 | "name": "ElementaryTypeName", 427 | "src": "254:4:12" 428 | } 429 | ], 430 | "id": 510, 431 | "name": "VariableDeclaration", 432 | "src": "254:14:12" 433 | } 434 | ], 435 | "id": 511, 436 | "name": "ParameterList", 437 | "src": "253:16:12" 438 | }, 439 | { 440 | "attributes": { 441 | "parameters": [ 442 | null 443 | ] 444 | }, 445 | "children": [], 446 | "id": 514, 447 | "name": "ParameterList", 448 | "src": "281:0:12" 449 | }, 450 | { 451 | "attributes": { 452 | "arguments": [ 453 | null 454 | ] 455 | }, 456 | "children": [ 457 | { 458 | "attributes": { 459 | "argumentTypes": null, 460 | "overloadedDeclarations": [ 461 | null 462 | ], 463 | "referencedDeclaration": 499, 464 | "type": "modifier ()", 465 | "value": "restricted" 466 | }, 467 | "id": 512, 468 | "name": "Identifier", 469 | "src": "270:10:12" 470 | } 471 | ], 472 | "id": 513, 473 | "name": "ModifierInvocation", 474 | "src": "270:10:12" 475 | }, 476 | { 477 | "children": [ 478 | { 479 | "children": [ 480 | { 481 | "attributes": { 482 | "argumentTypes": null, 483 | "isConstant": false, 484 | "isLValue": false, 485 | "isPure": false, 486 | "lValueRequested": false, 487 | "operator": "=", 488 | "type": "uint256" 489 | }, 490 | "children": [ 491 | { 492 | "attributes": { 493 | "argumentTypes": null, 494 | "overloadedDeclarations": [ 495 | null 496 | ], 497 | "referencedDeclaration": 490, 498 | "type": "uint256", 499 | "value": "last_completed_migration" 500 | }, 501 | "id": 515, 502 | "name": "Identifier", 503 | "src": "287:24:12" 504 | }, 505 | { 506 | "attributes": { 507 | "argumentTypes": null, 508 | "overloadedDeclarations": [ 509 | null 510 | ], 511 | "referencedDeclaration": 510, 512 | "type": "uint256", 513 | "value": "completed" 514 | }, 515 | "id": 516, 516 | "name": "Identifier", 517 | "src": "314:9:12" 518 | } 519 | ], 520 | "id": 517, 521 | "name": "Assignment", 522 | "src": "287:36:12" 523 | } 524 | ], 525 | "id": 518, 526 | "name": "ExpressionStatement", 527 | "src": "287:36:12" 528 | } 529 | ], 530 | "id": 519, 531 | "name": "Block", 532 | "src": "281:47:12" 533 | } 534 | ], 535 | "id": 520, 536 | "name": "FunctionDefinition", 537 | "src": "232:96:12" 538 | }, 539 | { 540 | "attributes": { 541 | "constant": false, 542 | "implemented": true, 543 | "isConstructor": false, 544 | "name": "upgrade", 545 | "payable": false, 546 | "scope": 541, 547 | "stateMutability": "nonpayable", 548 | "superFunction": null, 549 | "visibility": "public" 550 | }, 551 | "children": [ 552 | { 553 | "children": [ 554 | { 555 | "attributes": { 556 | "constant": false, 557 | "name": "new_address", 558 | "scope": 540, 559 | "stateVariable": false, 560 | "storageLocation": "default", 561 | "type": "address", 562 | "value": null, 563 | "visibility": "internal" 564 | }, 565 | "children": [ 566 | { 567 | "attributes": { 568 | "name": "address", 569 | "type": "address" 570 | }, 571 | "id": 521, 572 | "name": "ElementaryTypeName", 573 | "src": "349:7:12" 574 | } 575 | ], 576 | "id": 522, 577 | "name": "VariableDeclaration", 578 | "src": "349:19:12" 579 | } 580 | ], 581 | "id": 523, 582 | "name": "ParameterList", 583 | "src": "348:21:12" 584 | }, 585 | { 586 | "attributes": { 587 | "parameters": [ 588 | null 589 | ] 590 | }, 591 | "children": [], 592 | "id": 526, 593 | "name": "ParameterList", 594 | "src": "381:0:12" 595 | }, 596 | { 597 | "attributes": { 598 | "arguments": [ 599 | null 600 | ] 601 | }, 602 | "children": [ 603 | { 604 | "attributes": { 605 | "argumentTypes": null, 606 | "overloadedDeclarations": [ 607 | null 608 | ], 609 | "referencedDeclaration": 499, 610 | "type": "modifier ()", 611 | "value": "restricted" 612 | }, 613 | "id": 524, 614 | "name": "Identifier", 615 | "src": "370:10:12" 616 | } 617 | ], 618 | "id": 525, 619 | "name": "ModifierInvocation", 620 | "src": "370:10:12" 621 | }, 622 | { 623 | "children": [ 624 | { 625 | "attributes": { 626 | "assignments": [ 627 | 528 628 | ] 629 | }, 630 | "children": [ 631 | { 632 | "attributes": { 633 | "constant": false, 634 | "name": "upgraded", 635 | "scope": 540, 636 | "stateVariable": false, 637 | "storageLocation": "default", 638 | "type": "contract Migrations", 639 | "value": null, 640 | "visibility": "internal" 641 | }, 642 | "children": [ 643 | { 644 | "attributes": { 645 | "contractScope": null, 646 | "name": "Migrations", 647 | "referencedDeclaration": 541, 648 | "type": "contract Migrations" 649 | }, 650 | "id": 527, 651 | "name": "UserDefinedTypeName", 652 | "src": "387:10:12" 653 | } 654 | ], 655 | "id": 528, 656 | "name": "VariableDeclaration", 657 | "src": "387:19:12" 658 | }, 659 | { 660 | "attributes": { 661 | "argumentTypes": null, 662 | "isConstant": false, 663 | "isLValue": false, 664 | "isPure": false, 665 | "isStructConstructorCall": false, 666 | "lValueRequested": false, 667 | "names": [ 668 | null 669 | ], 670 | "type": "contract Migrations", 671 | "type_conversion": true 672 | }, 673 | "children": [ 674 | { 675 | "attributes": { 676 | "argumentTypes": [ 677 | { 678 | "typeIdentifier": "t_address", 679 | "typeString": "address" 680 | } 681 | ], 682 | "overloadedDeclarations": [ 683 | null 684 | ], 685 | "referencedDeclaration": 541, 686 | "type": "type(contract Migrations)", 687 | "value": "Migrations" 688 | }, 689 | "id": 529, 690 | "name": "Identifier", 691 | "src": "409:10:12" 692 | }, 693 | { 694 | "attributes": { 695 | "argumentTypes": null, 696 | "overloadedDeclarations": [ 697 | null 698 | ], 699 | "referencedDeclaration": 522, 700 | "type": "address", 701 | "value": "new_address" 702 | }, 703 | "id": 530, 704 | "name": "Identifier", 705 | "src": "420:11:12" 706 | } 707 | ], 708 | "id": 531, 709 | "name": "FunctionCall", 710 | "src": "409:23:12" 711 | } 712 | ], 713 | "id": 532, 714 | "name": "VariableDeclarationStatement", 715 | "src": "387:45:12" 716 | }, 717 | { 718 | "children": [ 719 | { 720 | "attributes": { 721 | "argumentTypes": null, 722 | "isConstant": false, 723 | "isLValue": false, 724 | "isPure": false, 725 | "isStructConstructorCall": false, 726 | "lValueRequested": false, 727 | "names": [ 728 | null 729 | ], 730 | "type": "tuple()", 731 | "type_conversion": false 732 | }, 733 | "children": [ 734 | { 735 | "attributes": { 736 | "argumentTypes": [ 737 | { 738 | "typeIdentifier": "t_uint256", 739 | "typeString": "uint256" 740 | } 741 | ], 742 | "isConstant": false, 743 | "isLValue": false, 744 | "isPure": false, 745 | "lValueRequested": false, 746 | "member_name": "setCompleted", 747 | "referencedDeclaration": 520, 748 | "type": "function (uint256) external" 749 | }, 750 | "children": [ 751 | { 752 | "attributes": { 753 | "argumentTypes": null, 754 | "overloadedDeclarations": [ 755 | null 756 | ], 757 | "referencedDeclaration": 528, 758 | "type": "contract Migrations", 759 | "value": "upgraded" 760 | }, 761 | "id": 533, 762 | "name": "Identifier", 763 | "src": "438:8:12" 764 | } 765 | ], 766 | "id": 535, 767 | "name": "MemberAccess", 768 | "src": "438:21:12" 769 | }, 770 | { 771 | "attributes": { 772 | "argumentTypes": null, 773 | "overloadedDeclarations": [ 774 | null 775 | ], 776 | "referencedDeclaration": 490, 777 | "type": "uint256", 778 | "value": "last_completed_migration" 779 | }, 780 | "id": 536, 781 | "name": "Identifier", 782 | "src": "460:24:12" 783 | } 784 | ], 785 | "id": 537, 786 | "name": "FunctionCall", 787 | "src": "438:47:12" 788 | } 789 | ], 790 | "id": 538, 791 | "name": "ExpressionStatement", 792 | "src": "438:47:12" 793 | } 794 | ], 795 | "id": 539, 796 | "name": "Block", 797 | "src": "381:109:12" 798 | } 799 | ], 800 | "id": 540, 801 | "name": "FunctionDefinition", 802 | "src": "332:158:12" 803 | } 804 | ], 805 | "id": 541, 806 | "name": "ContractDefinition", 807 | "src": "25:467:12" 808 | } 809 | ], 810 | "id": 542, 811 | "name": "SourceUnit", 812 | "src": "0:493:12" 813 | }, 814 | "compiler": { 815 | "name": "solc", 816 | "version": "0.4.18+commit.9cf6e910.Emscripten.clang" 817 | }, 818 | "networks": {}, 819 | "schemaVersion": "1.0.1", 820 | "updatedAt": "2018-01-20T00:19:40.119Z" 821 | } -------------------------------------------------------------------------------- /build/contracts/MyContractA.json: -------------------------------------------------------------------------------- 1 | { 2 | "contract_name": "MyContractA", 3 | "abi": [ 4 | { 5 | "constant": false, 6 | "inputs": [], 7 | "name": "MyContract", 8 | "outputs": [], 9 | "payable": false, 10 | "type": "function" 11 | }, 12 | { 13 | "constant": false, 14 | "inputs": [], 15 | "name": "myMethod", 16 | "outputs": [ 17 | { 18 | "name": "num", 19 | "type": "uint256" 20 | } 21 | ], 22 | "payable": false, 23 | "type": "function" 24 | } 25 | ], 26 | "unlinked_binary": "0x6060604052341561000f57600080fd5b5b60c08061001e6000396000f300606060405263ffffffff7c01000000000000000000000000000000000000000000000000000000006000350416636d7da0b18114604657806370dce926146058575b600080fd5b3415605057600080fd5b6056607a565b005b3415606257600080fd5b6068608e565b60405190815260200160405180910390f35b6080608e565b600b14608b57600080fd5b5b565b600a5b905600a165627a7a72305820eacb5d13cb2cd86750c20c350fe10a756b755791532c5ec30f2835b2981738460029", 27 | "networks": {}, 28 | "schema_version": "0.0.5", 29 | "updated_at": 1508224379530 30 | } -------------------------------------------------------------------------------- /build/contracts/SafeMath.json: -------------------------------------------------------------------------------- 1 | { 2 | "contractName": "SafeMath", 3 | "abi": [ 4 | { 5 | "constant": false, 6 | "inputs": [ 7 | { 8 | "name": "x", 9 | "type": "uint256" 10 | }, 11 | { 12 | "name": "y", 13 | "type": "uint256" 14 | } 15 | ], 16 | "name": "safeMult", 17 | "outputs": [ 18 | { 19 | "name": "", 20 | "type": "uint256" 21 | } 22 | ], 23 | "payable": false, 24 | "stateMutability": "nonpayable", 25 | "type": "function" 26 | }, 27 | { 28 | "constant": false, 29 | "inputs": [ 30 | { 31 | "name": "x", 32 | "type": "uint256" 33 | }, 34 | { 35 | "name": "y", 36 | "type": "uint256" 37 | } 38 | ], 39 | "name": "safeSubtract", 40 | "outputs": [ 41 | { 42 | "name": "", 43 | "type": "uint256" 44 | } 45 | ], 46 | "payable": false, 47 | "stateMutability": "nonpayable", 48 | "type": "function" 49 | }, 50 | { 51 | "constant": false, 52 | "inputs": [ 53 | { 54 | "name": "x", 55 | "type": "uint256" 56 | }, 57 | { 58 | "name": "y", 59 | "type": "uint256" 60 | } 61 | ], 62 | "name": "safeAdd", 63 | "outputs": [ 64 | { 65 | "name": "", 66 | "type": "uint256" 67 | } 68 | ], 69 | "payable": false, 70 | "stateMutability": "nonpayable", 71 | "type": "function" 72 | } 73 | ], 74 | "bytecode": "0x6060604052341561000f57600080fd5b6101c38061001e6000396000f300606060405260043610610057576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806364b3302d1461005c578063d30fbd0d1461009c578063e6cb9013146100dc575b600080fd5b341561006757600080fd5b610086600480803590602001909190803590602001909190505061011c565b6040518082815260200191505060405180910390f35b34156100a757600080fd5b6100c6600480803590602001909190803590602001909190505061014f565b6040518082815260200191505060405180910390f35b34156100e757600080fd5b610106600480803590602001909190803590602001909190505061016d565b6040518082815260200191505060405180910390f35b6000808284029050600084148061013d575082848281151561013a57fe5b04145b151561014557fe5b8091505092915050565b60008082841015151561015e57fe5b82840390508091505092915050565b60008082840190508381101580156101855750828110155b151561018d57fe5b80915050929150505600a165627a7a72305820b2ea56027fbf06e4f08ad6e797bd738b7bc46f7c39965a69ee9d8ccffca8ff1e0029", 75 | "deployedBytecode": "0x606060405260043610610057576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806364b3302d1461005c578063d30fbd0d1461009c578063e6cb9013146100dc575b600080fd5b341561006757600080fd5b610086600480803590602001909190803590602001909190505061011c565b6040518082815260200191505060405180910390f35b34156100a757600080fd5b6100c6600480803590602001909190803590602001909190505061014f565b6040518082815260200191505060405180910390f35b34156100e757600080fd5b610106600480803590602001909190803590602001909190505061016d565b6040518082815260200191505060405180910390f35b6000808284029050600084148061013d575082848281151561013a57fe5b04145b151561014557fe5b8091505092915050565b60008082841015151561015e57fe5b82840390508091505092915050565b60008082840190508381101580156101855750828110155b151561018d57fe5b80915050929150505600a165627a7a72305820b2ea56027fbf06e4f08ad6e797bd738b7bc46f7c39965a69ee9d8ccffca8ff1e0029", 76 | "sourceMap": "25:420:17:-;;;;;;;;;;;;;;;;;", 77 | "deployedSourceMap": "25:420:17:-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;310:133;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;183:123;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;47:132;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;310:133;358:7;373:9;389:1;385;:5;373:17;;409:1;404;:6;403:20;;;;421:1;416;414;:3;;;;;;;;:8;403:20;396:28;;;;;;437:1;430:8;;310:133;;;;;:::o;183:123::-;235:7;270:9;262:1;257;:6;;250:14;;;;;;286:1;282;:5;270:17;;300:1;293:8;;183:123;;;;;:::o;47:132::-;94:7;109:9;125:1;121;:5;109:17;;145:1;140;:6;;139:20;;;;;157:1;152;:6;;139:20;132:28;;;;;;173:1;166:8;;47:132;;;;;:::o", 78 | "source": "pragma solidity ^0.4.4;\n\ncontract SafeMath {\n function safeAdd(uint256 x, uint256 y) returns(uint256) {\n uint256 z = x + y;\n assert((z >= x) && (z >= y));\n return z;\n }\n\n function safeSubtract(uint256 x, uint256 y) returns(uint256) {\n assert(x >= y);\n uint256 z = x - y;\n return z;\n }\n\n function safeMult(uint256 x, uint256 y) returns(uint256) {\n uint256 z = x * y;\n assert((x == 0)||(z/x == y));\n return z;\n }\n}\n", 79 | "sourcePath": "/Users/mota/Sandbox/solidity-idiosyncrasies/contracts/SafeMath.sol", 80 | "ast": { 81 | "attributes": { 82 | "absolutePath": "/Users/mota/Sandbox/solidity-idiosyncrasies/contracts/SafeMath.sol", 83 | "exportedSymbols": { 84 | "SafeMath": [ 85 | 727 86 | ] 87 | } 88 | }, 89 | "children": [ 90 | { 91 | "attributes": { 92 | "literals": [ 93 | "solidity", 94 | "^", 95 | "0.4", 96 | ".4" 97 | ] 98 | }, 99 | "id": 640, 100 | "name": "PragmaDirective", 101 | "src": "0:23:17" 102 | }, 103 | { 104 | "attributes": { 105 | "baseContracts": [ 106 | null 107 | ], 108 | "contractDependencies": [ 109 | null 110 | ], 111 | "contractKind": "contract", 112 | "documentation": null, 113 | "fullyImplemented": true, 114 | "linearizedBaseContracts": [ 115 | 727 116 | ], 117 | "name": "SafeMath", 118 | "scope": 728 119 | }, 120 | "children": [ 121 | { 122 | "attributes": { 123 | "constant": false, 124 | "implemented": true, 125 | "isConstructor": false, 126 | "modifiers": [ 127 | null 128 | ], 129 | "name": "safeAdd", 130 | "payable": false, 131 | "scope": 727, 132 | "stateMutability": "nonpayable", 133 | "superFunction": null, 134 | "visibility": "public" 135 | }, 136 | "children": [ 137 | { 138 | "children": [ 139 | { 140 | "attributes": { 141 | "constant": false, 142 | "name": "x", 143 | "scope": 670, 144 | "stateVariable": false, 145 | "storageLocation": "default", 146 | "type": "uint256", 147 | "value": null, 148 | "visibility": "internal" 149 | }, 150 | "children": [ 151 | { 152 | "attributes": { 153 | "name": "uint256", 154 | "type": "uint256" 155 | }, 156 | "id": 641, 157 | "name": "ElementaryTypeName", 158 | "src": "64:7:17" 159 | } 160 | ], 161 | "id": 642, 162 | "name": "VariableDeclaration", 163 | "src": "64:9:17" 164 | }, 165 | { 166 | "attributes": { 167 | "constant": false, 168 | "name": "y", 169 | "scope": 670, 170 | "stateVariable": false, 171 | "storageLocation": "default", 172 | "type": "uint256", 173 | "value": null, 174 | "visibility": "internal" 175 | }, 176 | "children": [ 177 | { 178 | "attributes": { 179 | "name": "uint256", 180 | "type": "uint256" 181 | }, 182 | "id": 643, 183 | "name": "ElementaryTypeName", 184 | "src": "75:7:17" 185 | } 186 | ], 187 | "id": 644, 188 | "name": "VariableDeclaration", 189 | "src": "75:9:17" 190 | } 191 | ], 192 | "id": 645, 193 | "name": "ParameterList", 194 | "src": "63:22:17" 195 | }, 196 | { 197 | "children": [ 198 | { 199 | "attributes": { 200 | "constant": false, 201 | "name": "", 202 | "scope": 670, 203 | "stateVariable": false, 204 | "storageLocation": "default", 205 | "type": "uint256", 206 | "value": null, 207 | "visibility": "internal" 208 | }, 209 | "children": [ 210 | { 211 | "attributes": { 212 | "name": "uint256", 213 | "type": "uint256" 214 | }, 215 | "id": 646, 216 | "name": "ElementaryTypeName", 217 | "src": "94:7:17" 218 | } 219 | ], 220 | "id": 647, 221 | "name": "VariableDeclaration", 222 | "src": "94:7:17" 223 | } 224 | ], 225 | "id": 648, 226 | "name": "ParameterList", 227 | "src": "93:9:17" 228 | }, 229 | { 230 | "children": [ 231 | { 232 | "attributes": { 233 | "assignments": [ 234 | 650 235 | ] 236 | }, 237 | "children": [ 238 | { 239 | "attributes": { 240 | "constant": false, 241 | "name": "z", 242 | "scope": 670, 243 | "stateVariable": false, 244 | "storageLocation": "default", 245 | "type": "uint256", 246 | "value": null, 247 | "visibility": "internal" 248 | }, 249 | "children": [ 250 | { 251 | "attributes": { 252 | "name": "uint256", 253 | "type": "uint256" 254 | }, 255 | "id": 649, 256 | "name": "ElementaryTypeName", 257 | "src": "109:7:17" 258 | } 259 | ], 260 | "id": 650, 261 | "name": "VariableDeclaration", 262 | "src": "109:9:17" 263 | }, 264 | { 265 | "attributes": { 266 | "argumentTypes": null, 267 | "commonType": { 268 | "typeIdentifier": "t_uint256", 269 | "typeString": "uint256" 270 | }, 271 | "isConstant": false, 272 | "isLValue": false, 273 | "isPure": false, 274 | "lValueRequested": false, 275 | "operator": "+", 276 | "type": "uint256" 277 | }, 278 | "children": [ 279 | { 280 | "attributes": { 281 | "argumentTypes": null, 282 | "overloadedDeclarations": [ 283 | null 284 | ], 285 | "referencedDeclaration": 642, 286 | "type": "uint256", 287 | "value": "x" 288 | }, 289 | "id": 651, 290 | "name": "Identifier", 291 | "src": "121:1:17" 292 | }, 293 | { 294 | "attributes": { 295 | "argumentTypes": null, 296 | "overloadedDeclarations": [ 297 | null 298 | ], 299 | "referencedDeclaration": 644, 300 | "type": "uint256", 301 | "value": "y" 302 | }, 303 | "id": 652, 304 | "name": "Identifier", 305 | "src": "125:1:17" 306 | } 307 | ], 308 | "id": 653, 309 | "name": "BinaryOperation", 310 | "src": "121:5:17" 311 | } 312 | ], 313 | "id": 654, 314 | "name": "VariableDeclarationStatement", 315 | "src": "109:17:17" 316 | }, 317 | { 318 | "children": [ 319 | { 320 | "attributes": { 321 | "argumentTypes": null, 322 | "isConstant": false, 323 | "isLValue": false, 324 | "isPure": false, 325 | "isStructConstructorCall": false, 326 | "lValueRequested": false, 327 | "names": [ 328 | null 329 | ], 330 | "type": "tuple()", 331 | "type_conversion": false 332 | }, 333 | "children": [ 334 | { 335 | "attributes": { 336 | "argumentTypes": [ 337 | { 338 | "typeIdentifier": "t_bool", 339 | "typeString": "bool" 340 | } 341 | ], 342 | "overloadedDeclarations": [ 343 | null 344 | ], 345 | "referencedDeclaration": 1185, 346 | "type": "function (bool) pure", 347 | "value": "assert" 348 | }, 349 | "id": 655, 350 | "name": "Identifier", 351 | "src": "132:6:17" 352 | }, 353 | { 354 | "attributes": { 355 | "argumentTypes": null, 356 | "commonType": { 357 | "typeIdentifier": "t_bool", 358 | "typeString": "bool" 359 | }, 360 | "isConstant": false, 361 | "isLValue": false, 362 | "isPure": false, 363 | "lValueRequested": false, 364 | "operator": "&&", 365 | "type": "bool" 366 | }, 367 | "children": [ 368 | { 369 | "attributes": { 370 | "argumentTypes": null, 371 | "isConstant": false, 372 | "isInlineArray": false, 373 | "isLValue": false, 374 | "isPure": false, 375 | "lValueRequested": false, 376 | "type": "bool" 377 | }, 378 | "children": [ 379 | { 380 | "attributes": { 381 | "argumentTypes": null, 382 | "commonType": { 383 | "typeIdentifier": "t_uint256", 384 | "typeString": "uint256" 385 | }, 386 | "isConstant": false, 387 | "isLValue": false, 388 | "isPure": false, 389 | "lValueRequested": false, 390 | "operator": ">=", 391 | "type": "bool" 392 | }, 393 | "children": [ 394 | { 395 | "attributes": { 396 | "argumentTypes": null, 397 | "overloadedDeclarations": [ 398 | null 399 | ], 400 | "referencedDeclaration": 650, 401 | "type": "uint256", 402 | "value": "z" 403 | }, 404 | "id": 656, 405 | "name": "Identifier", 406 | "src": "140:1:17" 407 | }, 408 | { 409 | "attributes": { 410 | "argumentTypes": null, 411 | "overloadedDeclarations": [ 412 | null 413 | ], 414 | "referencedDeclaration": 642, 415 | "type": "uint256", 416 | "value": "x" 417 | }, 418 | "id": 657, 419 | "name": "Identifier", 420 | "src": "145:1:17" 421 | } 422 | ], 423 | "id": 658, 424 | "name": "BinaryOperation", 425 | "src": "140:6:17" 426 | } 427 | ], 428 | "id": 659, 429 | "name": "TupleExpression", 430 | "src": "139:8:17" 431 | }, 432 | { 433 | "attributes": { 434 | "argumentTypes": null, 435 | "isConstant": false, 436 | "isInlineArray": false, 437 | "isLValue": false, 438 | "isPure": false, 439 | "lValueRequested": false, 440 | "type": "bool" 441 | }, 442 | "children": [ 443 | { 444 | "attributes": { 445 | "argumentTypes": null, 446 | "commonType": { 447 | "typeIdentifier": "t_uint256", 448 | "typeString": "uint256" 449 | }, 450 | "isConstant": false, 451 | "isLValue": false, 452 | "isPure": false, 453 | "lValueRequested": false, 454 | "operator": ">=", 455 | "type": "bool" 456 | }, 457 | "children": [ 458 | { 459 | "attributes": { 460 | "argumentTypes": null, 461 | "overloadedDeclarations": [ 462 | null 463 | ], 464 | "referencedDeclaration": 650, 465 | "type": "uint256", 466 | "value": "z" 467 | }, 468 | "id": 660, 469 | "name": "Identifier", 470 | "src": "152:1:17" 471 | }, 472 | { 473 | "attributes": { 474 | "argumentTypes": null, 475 | "overloadedDeclarations": [ 476 | null 477 | ], 478 | "referencedDeclaration": 644, 479 | "type": "uint256", 480 | "value": "y" 481 | }, 482 | "id": 661, 483 | "name": "Identifier", 484 | "src": "157:1:17" 485 | } 486 | ], 487 | "id": 662, 488 | "name": "BinaryOperation", 489 | "src": "152:6:17" 490 | } 491 | ], 492 | "id": 663, 493 | "name": "TupleExpression", 494 | "src": "151:8:17" 495 | } 496 | ], 497 | "id": 664, 498 | "name": "BinaryOperation", 499 | "src": "139:20:17" 500 | } 501 | ], 502 | "id": 665, 503 | "name": "FunctionCall", 504 | "src": "132:28:17" 505 | } 506 | ], 507 | "id": 666, 508 | "name": "ExpressionStatement", 509 | "src": "132:28:17" 510 | }, 511 | { 512 | "attributes": { 513 | "functionReturnParameters": 648 514 | }, 515 | "children": [ 516 | { 517 | "attributes": { 518 | "argumentTypes": null, 519 | "overloadedDeclarations": [ 520 | null 521 | ], 522 | "referencedDeclaration": 650, 523 | "type": "uint256", 524 | "value": "z" 525 | }, 526 | "id": 667, 527 | "name": "Identifier", 528 | "src": "173:1:17" 529 | } 530 | ], 531 | "id": 668, 532 | "name": "Return", 533 | "src": "166:8:17" 534 | } 535 | ], 536 | "id": 669, 537 | "name": "Block", 538 | "src": "103:76:17" 539 | } 540 | ], 541 | "id": 670, 542 | "name": "FunctionDefinition", 543 | "src": "47:132:17" 544 | }, 545 | { 546 | "attributes": { 547 | "constant": false, 548 | "implemented": true, 549 | "isConstructor": false, 550 | "modifiers": [ 551 | null 552 | ], 553 | "name": "safeSubtract", 554 | "payable": false, 555 | "scope": 727, 556 | "stateMutability": "nonpayable", 557 | "superFunction": null, 558 | "visibility": "public" 559 | }, 560 | "children": [ 561 | { 562 | "children": [ 563 | { 564 | "attributes": { 565 | "constant": false, 566 | "name": "x", 567 | "scope": 694, 568 | "stateVariable": false, 569 | "storageLocation": "default", 570 | "type": "uint256", 571 | "value": null, 572 | "visibility": "internal" 573 | }, 574 | "children": [ 575 | { 576 | "attributes": { 577 | "name": "uint256", 578 | "type": "uint256" 579 | }, 580 | "id": 671, 581 | "name": "ElementaryTypeName", 582 | "src": "205:7:17" 583 | } 584 | ], 585 | "id": 672, 586 | "name": "VariableDeclaration", 587 | "src": "205:9:17" 588 | }, 589 | { 590 | "attributes": { 591 | "constant": false, 592 | "name": "y", 593 | "scope": 694, 594 | "stateVariable": false, 595 | "storageLocation": "default", 596 | "type": "uint256", 597 | "value": null, 598 | "visibility": "internal" 599 | }, 600 | "children": [ 601 | { 602 | "attributes": { 603 | "name": "uint256", 604 | "type": "uint256" 605 | }, 606 | "id": 673, 607 | "name": "ElementaryTypeName", 608 | "src": "216:7:17" 609 | } 610 | ], 611 | "id": 674, 612 | "name": "VariableDeclaration", 613 | "src": "216:9:17" 614 | } 615 | ], 616 | "id": 675, 617 | "name": "ParameterList", 618 | "src": "204:22:17" 619 | }, 620 | { 621 | "children": [ 622 | { 623 | "attributes": { 624 | "constant": false, 625 | "name": "", 626 | "scope": 694, 627 | "stateVariable": false, 628 | "storageLocation": "default", 629 | "type": "uint256", 630 | "value": null, 631 | "visibility": "internal" 632 | }, 633 | "children": [ 634 | { 635 | "attributes": { 636 | "name": "uint256", 637 | "type": "uint256" 638 | }, 639 | "id": 676, 640 | "name": "ElementaryTypeName", 641 | "src": "235:7:17" 642 | } 643 | ], 644 | "id": 677, 645 | "name": "VariableDeclaration", 646 | "src": "235:7:17" 647 | } 648 | ], 649 | "id": 678, 650 | "name": "ParameterList", 651 | "src": "234:9:17" 652 | }, 653 | { 654 | "children": [ 655 | { 656 | "children": [ 657 | { 658 | "attributes": { 659 | "argumentTypes": null, 660 | "isConstant": false, 661 | "isLValue": false, 662 | "isPure": false, 663 | "isStructConstructorCall": false, 664 | "lValueRequested": false, 665 | "names": [ 666 | null 667 | ], 668 | "type": "tuple()", 669 | "type_conversion": false 670 | }, 671 | "children": [ 672 | { 673 | "attributes": { 674 | "argumentTypes": [ 675 | { 676 | "typeIdentifier": "t_bool", 677 | "typeString": "bool" 678 | } 679 | ], 680 | "overloadedDeclarations": [ 681 | null 682 | ], 683 | "referencedDeclaration": 1185, 684 | "type": "function (bool) pure", 685 | "value": "assert" 686 | }, 687 | "id": 679, 688 | "name": "Identifier", 689 | "src": "250:6:17" 690 | }, 691 | { 692 | "attributes": { 693 | "argumentTypes": null, 694 | "commonType": { 695 | "typeIdentifier": "t_uint256", 696 | "typeString": "uint256" 697 | }, 698 | "isConstant": false, 699 | "isLValue": false, 700 | "isPure": false, 701 | "lValueRequested": false, 702 | "operator": ">=", 703 | "type": "bool" 704 | }, 705 | "children": [ 706 | { 707 | "attributes": { 708 | "argumentTypes": null, 709 | "overloadedDeclarations": [ 710 | null 711 | ], 712 | "referencedDeclaration": 672, 713 | "type": "uint256", 714 | "value": "x" 715 | }, 716 | "id": 680, 717 | "name": "Identifier", 718 | "src": "257:1:17" 719 | }, 720 | { 721 | "attributes": { 722 | "argumentTypes": null, 723 | "overloadedDeclarations": [ 724 | null 725 | ], 726 | "referencedDeclaration": 674, 727 | "type": "uint256", 728 | "value": "y" 729 | }, 730 | "id": 681, 731 | "name": "Identifier", 732 | "src": "262:1:17" 733 | } 734 | ], 735 | "id": 682, 736 | "name": "BinaryOperation", 737 | "src": "257:6:17" 738 | } 739 | ], 740 | "id": 683, 741 | "name": "FunctionCall", 742 | "src": "250:14:17" 743 | } 744 | ], 745 | "id": 684, 746 | "name": "ExpressionStatement", 747 | "src": "250:14:17" 748 | }, 749 | { 750 | "attributes": { 751 | "assignments": [ 752 | 686 753 | ] 754 | }, 755 | "children": [ 756 | { 757 | "attributes": { 758 | "constant": false, 759 | "name": "z", 760 | "scope": 694, 761 | "stateVariable": false, 762 | "storageLocation": "default", 763 | "type": "uint256", 764 | "value": null, 765 | "visibility": "internal" 766 | }, 767 | "children": [ 768 | { 769 | "attributes": { 770 | "name": "uint256", 771 | "type": "uint256" 772 | }, 773 | "id": 685, 774 | "name": "ElementaryTypeName", 775 | "src": "270:7:17" 776 | } 777 | ], 778 | "id": 686, 779 | "name": "VariableDeclaration", 780 | "src": "270:9:17" 781 | }, 782 | { 783 | "attributes": { 784 | "argumentTypes": null, 785 | "commonType": { 786 | "typeIdentifier": "t_uint256", 787 | "typeString": "uint256" 788 | }, 789 | "isConstant": false, 790 | "isLValue": false, 791 | "isPure": false, 792 | "lValueRequested": false, 793 | "operator": "-", 794 | "type": "uint256" 795 | }, 796 | "children": [ 797 | { 798 | "attributes": { 799 | "argumentTypes": null, 800 | "overloadedDeclarations": [ 801 | null 802 | ], 803 | "referencedDeclaration": 672, 804 | "type": "uint256", 805 | "value": "x" 806 | }, 807 | "id": 687, 808 | "name": "Identifier", 809 | "src": "282:1:17" 810 | }, 811 | { 812 | "attributes": { 813 | "argumentTypes": null, 814 | "overloadedDeclarations": [ 815 | null 816 | ], 817 | "referencedDeclaration": 674, 818 | "type": "uint256", 819 | "value": "y" 820 | }, 821 | "id": 688, 822 | "name": "Identifier", 823 | "src": "286:1:17" 824 | } 825 | ], 826 | "id": 689, 827 | "name": "BinaryOperation", 828 | "src": "282:5:17" 829 | } 830 | ], 831 | "id": 690, 832 | "name": "VariableDeclarationStatement", 833 | "src": "270:17:17" 834 | }, 835 | { 836 | "attributes": { 837 | "functionReturnParameters": 678 838 | }, 839 | "children": [ 840 | { 841 | "attributes": { 842 | "argumentTypes": null, 843 | "overloadedDeclarations": [ 844 | null 845 | ], 846 | "referencedDeclaration": 686, 847 | "type": "uint256", 848 | "value": "z" 849 | }, 850 | "id": 691, 851 | "name": "Identifier", 852 | "src": "300:1:17" 853 | } 854 | ], 855 | "id": 692, 856 | "name": "Return", 857 | "src": "293:8:17" 858 | } 859 | ], 860 | "id": 693, 861 | "name": "Block", 862 | "src": "244:62:17" 863 | } 864 | ], 865 | "id": 694, 866 | "name": "FunctionDefinition", 867 | "src": "183:123:17" 868 | }, 869 | { 870 | "attributes": { 871 | "constant": false, 872 | "implemented": true, 873 | "isConstructor": false, 874 | "modifiers": [ 875 | null 876 | ], 877 | "name": "safeMult", 878 | "payable": false, 879 | "scope": 727, 880 | "stateMutability": "nonpayable", 881 | "superFunction": null, 882 | "visibility": "public" 883 | }, 884 | "children": [ 885 | { 886 | "children": [ 887 | { 888 | "attributes": { 889 | "constant": false, 890 | "name": "x", 891 | "scope": 726, 892 | "stateVariable": false, 893 | "storageLocation": "default", 894 | "type": "uint256", 895 | "value": null, 896 | "visibility": "internal" 897 | }, 898 | "children": [ 899 | { 900 | "attributes": { 901 | "name": "uint256", 902 | "type": "uint256" 903 | }, 904 | "id": 695, 905 | "name": "ElementaryTypeName", 906 | "src": "328:7:17" 907 | } 908 | ], 909 | "id": 696, 910 | "name": "VariableDeclaration", 911 | "src": "328:9:17" 912 | }, 913 | { 914 | "attributes": { 915 | "constant": false, 916 | "name": "y", 917 | "scope": 726, 918 | "stateVariable": false, 919 | "storageLocation": "default", 920 | "type": "uint256", 921 | "value": null, 922 | "visibility": "internal" 923 | }, 924 | "children": [ 925 | { 926 | "attributes": { 927 | "name": "uint256", 928 | "type": "uint256" 929 | }, 930 | "id": 697, 931 | "name": "ElementaryTypeName", 932 | "src": "339:7:17" 933 | } 934 | ], 935 | "id": 698, 936 | "name": "VariableDeclaration", 937 | "src": "339:9:17" 938 | } 939 | ], 940 | "id": 699, 941 | "name": "ParameterList", 942 | "src": "327:22:17" 943 | }, 944 | { 945 | "children": [ 946 | { 947 | "attributes": { 948 | "constant": false, 949 | "name": "", 950 | "scope": 726, 951 | "stateVariable": false, 952 | "storageLocation": "default", 953 | "type": "uint256", 954 | "value": null, 955 | "visibility": "internal" 956 | }, 957 | "children": [ 958 | { 959 | "attributes": { 960 | "name": "uint256", 961 | "type": "uint256" 962 | }, 963 | "id": 700, 964 | "name": "ElementaryTypeName", 965 | "src": "358:7:17" 966 | } 967 | ], 968 | "id": 701, 969 | "name": "VariableDeclaration", 970 | "src": "358:7:17" 971 | } 972 | ], 973 | "id": 702, 974 | "name": "ParameterList", 975 | "src": "357:9:17" 976 | }, 977 | { 978 | "children": [ 979 | { 980 | "attributes": { 981 | "assignments": [ 982 | 704 983 | ] 984 | }, 985 | "children": [ 986 | { 987 | "attributes": { 988 | "constant": false, 989 | "name": "z", 990 | "scope": 726, 991 | "stateVariable": false, 992 | "storageLocation": "default", 993 | "type": "uint256", 994 | "value": null, 995 | "visibility": "internal" 996 | }, 997 | "children": [ 998 | { 999 | "attributes": { 1000 | "name": "uint256", 1001 | "type": "uint256" 1002 | }, 1003 | "id": 703, 1004 | "name": "ElementaryTypeName", 1005 | "src": "373:7:17" 1006 | } 1007 | ], 1008 | "id": 704, 1009 | "name": "VariableDeclaration", 1010 | "src": "373:9:17" 1011 | }, 1012 | { 1013 | "attributes": { 1014 | "argumentTypes": null, 1015 | "commonType": { 1016 | "typeIdentifier": "t_uint256", 1017 | "typeString": "uint256" 1018 | }, 1019 | "isConstant": false, 1020 | "isLValue": false, 1021 | "isPure": false, 1022 | "lValueRequested": false, 1023 | "operator": "*", 1024 | "type": "uint256" 1025 | }, 1026 | "children": [ 1027 | { 1028 | "attributes": { 1029 | "argumentTypes": null, 1030 | "overloadedDeclarations": [ 1031 | null 1032 | ], 1033 | "referencedDeclaration": 696, 1034 | "type": "uint256", 1035 | "value": "x" 1036 | }, 1037 | "id": 705, 1038 | "name": "Identifier", 1039 | "src": "385:1:17" 1040 | }, 1041 | { 1042 | "attributes": { 1043 | "argumentTypes": null, 1044 | "overloadedDeclarations": [ 1045 | null 1046 | ], 1047 | "referencedDeclaration": 698, 1048 | "type": "uint256", 1049 | "value": "y" 1050 | }, 1051 | "id": 706, 1052 | "name": "Identifier", 1053 | "src": "389:1:17" 1054 | } 1055 | ], 1056 | "id": 707, 1057 | "name": "BinaryOperation", 1058 | "src": "385:5:17" 1059 | } 1060 | ], 1061 | "id": 708, 1062 | "name": "VariableDeclarationStatement", 1063 | "src": "373:17:17" 1064 | }, 1065 | { 1066 | "children": [ 1067 | { 1068 | "attributes": { 1069 | "argumentTypes": null, 1070 | "isConstant": false, 1071 | "isLValue": false, 1072 | "isPure": false, 1073 | "isStructConstructorCall": false, 1074 | "lValueRequested": false, 1075 | "names": [ 1076 | null 1077 | ], 1078 | "type": "tuple()", 1079 | "type_conversion": false 1080 | }, 1081 | "children": [ 1082 | { 1083 | "attributes": { 1084 | "argumentTypes": [ 1085 | { 1086 | "typeIdentifier": "t_bool", 1087 | "typeString": "bool" 1088 | } 1089 | ], 1090 | "overloadedDeclarations": [ 1091 | null 1092 | ], 1093 | "referencedDeclaration": 1185, 1094 | "type": "function (bool) pure", 1095 | "value": "assert" 1096 | }, 1097 | "id": 709, 1098 | "name": "Identifier", 1099 | "src": "396:6:17" 1100 | }, 1101 | { 1102 | "attributes": { 1103 | "argumentTypes": null, 1104 | "commonType": { 1105 | "typeIdentifier": "t_bool", 1106 | "typeString": "bool" 1107 | }, 1108 | "isConstant": false, 1109 | "isLValue": false, 1110 | "isPure": false, 1111 | "lValueRequested": false, 1112 | "operator": "||", 1113 | "type": "bool" 1114 | }, 1115 | "children": [ 1116 | { 1117 | "attributes": { 1118 | "argumentTypes": null, 1119 | "isConstant": false, 1120 | "isInlineArray": false, 1121 | "isLValue": false, 1122 | "isPure": false, 1123 | "lValueRequested": false, 1124 | "type": "bool" 1125 | }, 1126 | "children": [ 1127 | { 1128 | "attributes": { 1129 | "argumentTypes": null, 1130 | "commonType": { 1131 | "typeIdentifier": "t_uint256", 1132 | "typeString": "uint256" 1133 | }, 1134 | "isConstant": false, 1135 | "isLValue": false, 1136 | "isPure": false, 1137 | "lValueRequested": false, 1138 | "operator": "==", 1139 | "type": "bool" 1140 | }, 1141 | "children": [ 1142 | { 1143 | "attributes": { 1144 | "argumentTypes": null, 1145 | "overloadedDeclarations": [ 1146 | null 1147 | ], 1148 | "referencedDeclaration": 696, 1149 | "type": "uint256", 1150 | "value": "x" 1151 | }, 1152 | "id": 710, 1153 | "name": "Identifier", 1154 | "src": "404:1:17" 1155 | }, 1156 | { 1157 | "attributes": { 1158 | "argumentTypes": null, 1159 | "hexvalue": "30", 1160 | "isConstant": false, 1161 | "isLValue": false, 1162 | "isPure": true, 1163 | "lValueRequested": false, 1164 | "subdenomination": null, 1165 | "token": "number", 1166 | "type": "int_const 0", 1167 | "value": "0" 1168 | }, 1169 | "id": 711, 1170 | "name": "Literal", 1171 | "src": "409:1:17" 1172 | } 1173 | ], 1174 | "id": 712, 1175 | "name": "BinaryOperation", 1176 | "src": "404:6:17" 1177 | } 1178 | ], 1179 | "id": 713, 1180 | "name": "TupleExpression", 1181 | "src": "403:8:17" 1182 | }, 1183 | { 1184 | "attributes": { 1185 | "argumentTypes": null, 1186 | "isConstant": false, 1187 | "isInlineArray": false, 1188 | "isLValue": false, 1189 | "isPure": false, 1190 | "lValueRequested": false, 1191 | "type": "bool" 1192 | }, 1193 | "children": [ 1194 | { 1195 | "attributes": { 1196 | "argumentTypes": null, 1197 | "commonType": { 1198 | "typeIdentifier": "t_uint256", 1199 | "typeString": "uint256" 1200 | }, 1201 | "isConstant": false, 1202 | "isLValue": false, 1203 | "isPure": false, 1204 | "lValueRequested": false, 1205 | "operator": "==", 1206 | "type": "bool" 1207 | }, 1208 | "children": [ 1209 | { 1210 | "attributes": { 1211 | "argumentTypes": null, 1212 | "commonType": { 1213 | "typeIdentifier": "t_uint256", 1214 | "typeString": "uint256" 1215 | }, 1216 | "isConstant": false, 1217 | "isLValue": false, 1218 | "isPure": false, 1219 | "lValueRequested": false, 1220 | "operator": "/", 1221 | "type": "uint256" 1222 | }, 1223 | "children": [ 1224 | { 1225 | "attributes": { 1226 | "argumentTypes": null, 1227 | "overloadedDeclarations": [ 1228 | null 1229 | ], 1230 | "referencedDeclaration": 704, 1231 | "type": "uint256", 1232 | "value": "z" 1233 | }, 1234 | "id": 714, 1235 | "name": "Identifier", 1236 | "src": "414:1:17" 1237 | }, 1238 | { 1239 | "attributes": { 1240 | "argumentTypes": null, 1241 | "overloadedDeclarations": [ 1242 | null 1243 | ], 1244 | "referencedDeclaration": 696, 1245 | "type": "uint256", 1246 | "value": "x" 1247 | }, 1248 | "id": 715, 1249 | "name": "Identifier", 1250 | "src": "416:1:17" 1251 | } 1252 | ], 1253 | "id": 716, 1254 | "name": "BinaryOperation", 1255 | "src": "414:3:17" 1256 | }, 1257 | { 1258 | "attributes": { 1259 | "argumentTypes": null, 1260 | "overloadedDeclarations": [ 1261 | null 1262 | ], 1263 | "referencedDeclaration": 698, 1264 | "type": "uint256", 1265 | "value": "y" 1266 | }, 1267 | "id": 717, 1268 | "name": "Identifier", 1269 | "src": "421:1:17" 1270 | } 1271 | ], 1272 | "id": 718, 1273 | "name": "BinaryOperation", 1274 | "src": "414:8:17" 1275 | } 1276 | ], 1277 | "id": 719, 1278 | "name": "TupleExpression", 1279 | "src": "413:10:17" 1280 | } 1281 | ], 1282 | "id": 720, 1283 | "name": "BinaryOperation", 1284 | "src": "403:20:17" 1285 | } 1286 | ], 1287 | "id": 721, 1288 | "name": "FunctionCall", 1289 | "src": "396:28:17" 1290 | } 1291 | ], 1292 | "id": 722, 1293 | "name": "ExpressionStatement", 1294 | "src": "396:28:17" 1295 | }, 1296 | { 1297 | "attributes": { 1298 | "functionReturnParameters": 702 1299 | }, 1300 | "children": [ 1301 | { 1302 | "attributes": { 1303 | "argumentTypes": null, 1304 | "overloadedDeclarations": [ 1305 | null 1306 | ], 1307 | "referencedDeclaration": 704, 1308 | "type": "uint256", 1309 | "value": "z" 1310 | }, 1311 | "id": 723, 1312 | "name": "Identifier", 1313 | "src": "437:1:17" 1314 | } 1315 | ], 1316 | "id": 724, 1317 | "name": "Return", 1318 | "src": "430:8:17" 1319 | } 1320 | ], 1321 | "id": 725, 1322 | "name": "Block", 1323 | "src": "367:76:17" 1324 | } 1325 | ], 1326 | "id": 726, 1327 | "name": "FunctionDefinition", 1328 | "src": "310:133:17" 1329 | } 1330 | ], 1331 | "id": 727, 1332 | "name": "ContractDefinition", 1333 | "src": "25:420:17" 1334 | } 1335 | ], 1336 | "id": 728, 1337 | "name": "SourceUnit", 1338 | "src": "0:446:17" 1339 | }, 1340 | "compiler": { 1341 | "name": "solc", 1342 | "version": "0.4.18+commit.9cf6e910.Emscripten.clang" 1343 | }, 1344 | "networks": {}, 1345 | "schemaVersion": "1.0.1", 1346 | "updatedAt": "2018-01-20T00:19:40.119Z" 1347 | } -------------------------------------------------------------------------------- /build/contracts/StorageOverride.json: -------------------------------------------------------------------------------- 1 | { 2 | "contractName": "StorageOverride", 3 | "abi": [ 4 | { 5 | "inputs": [], 6 | "payable": false, 7 | "stateMutability": "nonpayable", 8 | "type": "constructor" 9 | } 10 | ], 11 | "bytecode": "0x6060604052341561000f57600080fd5b6100176100a8565b60056040518059106100265750595b90808252806020026020018201604052509050600181600081518110151561004a57fe5b9060200190602002018181525050806001908051906020019061006e9291906100bc565b506000805414151561007c57fe5b600180600081548110151561008d57fe5b9060005260206000209001541415156100a257fe5b5061012e565b602060405190810160405280600081525090565b8280548282559060005260206000209081019282156100f8579160200282015b828111156100f75782518255916020019190600101906100dc565b5b5090506101059190610109565b5090565b61012b91905b8082111561012757600081600090555060010161010f565b5090565b90565b60358061013c6000396000f3006060604052600080fd00a165627a7a72305820566b10729de93f1f9e27c8f18d1e475b910533ec1560e6f7c1f034092ad51d260029", 12 | "deployedBytecode": "0x6060604052600080fd00a165627a7a72305820566b10729de93f1f9e27c8f18d1e475b910533ec1560e6f7c1f034092ad51d260029", 13 | "sourceMap": "25:317:18:-;;;195:145;;;;;;;;229:15;;:::i;:::-;258:1;247:13;;;;;;;;;;;;;;;;;;;;;;;;229:31;;273:1;266;268;266:4;;;;;;;;;;;;;;;;;:8;;;;;286:1;280:3;:7;;;;;;;;;;;;:::i;:::-;;308:1;301:3;;:8;294:16;;;;;;333:1;323:3;327:1;323:6;;;;;;;;;;;;;;;;;;;:11;316:19;;;;;;195:145;25:317;;;;;;;;;;;;;;;;;:::o;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;;;:::o;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;:::o;:::-;;;;;;;", 14 | "deployedSourceMap": "25:317:18:-;;;;;", 15 | "source": "pragma solidity ^0.4.4;\n\ncontract StorageOverride {\n uint foo;\n uint[] bar;\n\n /*\n // This will not work!\n function StorageOverride () {\n uint[] x;\n x.push(1);\n bar = x;\n }\n */\n\n function StorageOverride () {\n uint[] memory x = new uint[](5);\n x[0] = 1;\n bar = x;\n\n assert(foo == 0);\n assert(bar[0] == 1);\n }\n}\n", 16 | "sourcePath": "/Users/mota/Sandbox/solidity-idiosyncrasies/contracts/StorageOverride.sol", 17 | "ast": { 18 | "attributes": { 19 | "absolutePath": "/Users/mota/Sandbox/solidity-idiosyncrasies/contracts/StorageOverride.sol", 20 | "exportedSymbols": { 21 | "StorageOverride": [ 22 | 773 23 | ] 24 | } 25 | }, 26 | "children": [ 27 | { 28 | "attributes": { 29 | "literals": [ 30 | "solidity", 31 | "^", 32 | "0.4", 33 | ".4" 34 | ] 35 | }, 36 | "id": 729, 37 | "name": "PragmaDirective", 38 | "src": "0:23:18" 39 | }, 40 | { 41 | "attributes": { 42 | "baseContracts": [ 43 | null 44 | ], 45 | "contractDependencies": [ 46 | null 47 | ], 48 | "contractKind": "contract", 49 | "documentation": null, 50 | "fullyImplemented": true, 51 | "linearizedBaseContracts": [ 52 | 773 53 | ], 54 | "name": "StorageOverride", 55 | "scope": 774 56 | }, 57 | "children": [ 58 | { 59 | "attributes": { 60 | "constant": false, 61 | "name": "foo", 62 | "scope": 773, 63 | "stateVariable": true, 64 | "storageLocation": "default", 65 | "type": "uint256", 66 | "value": null, 67 | "visibility": "internal" 68 | }, 69 | "children": [ 70 | { 71 | "attributes": { 72 | "name": "uint", 73 | "type": "uint256" 74 | }, 75 | "id": 730, 76 | "name": "ElementaryTypeName", 77 | "src": "54:4:18" 78 | } 79 | ], 80 | "id": 731, 81 | "name": "VariableDeclaration", 82 | "src": "54:8:18" 83 | }, 84 | { 85 | "attributes": { 86 | "constant": false, 87 | "name": "bar", 88 | "scope": 773, 89 | "stateVariable": true, 90 | "storageLocation": "default", 91 | "type": "uint256[] storage ref", 92 | "value": null, 93 | "visibility": "internal" 94 | }, 95 | "children": [ 96 | { 97 | "attributes": { 98 | "length": null, 99 | "type": "uint256[] storage pointer" 100 | }, 101 | "children": [ 102 | { 103 | "attributes": { 104 | "name": "uint", 105 | "type": "uint256" 106 | }, 107 | "id": 732, 108 | "name": "ElementaryTypeName", 109 | "src": "66:4:18" 110 | } 111 | ], 112 | "id": 733, 113 | "name": "ArrayTypeName", 114 | "src": "66:6:18" 115 | } 116 | ], 117 | "id": 734, 118 | "name": "VariableDeclaration", 119 | "src": "66:10:18" 120 | }, 121 | { 122 | "attributes": { 123 | "constant": false, 124 | "implemented": true, 125 | "isConstructor": true, 126 | "modifiers": [ 127 | null 128 | ], 129 | "name": "StorageOverride", 130 | "payable": false, 131 | "scope": 773, 132 | "stateMutability": "nonpayable", 133 | "superFunction": null, 134 | "visibility": "public" 135 | }, 136 | "children": [ 137 | { 138 | "attributes": { 139 | "parameters": [ 140 | null 141 | ] 142 | }, 143 | "children": [], 144 | "id": 735, 145 | "name": "ParameterList", 146 | "src": "220:2:18" 147 | }, 148 | { 149 | "attributes": { 150 | "parameters": [ 151 | null 152 | ] 153 | }, 154 | "children": [], 155 | "id": 736, 156 | "name": "ParameterList", 157 | "src": "223:0:18" 158 | }, 159 | { 160 | "children": [ 161 | { 162 | "attributes": { 163 | "assignments": [ 164 | 740 165 | ] 166 | }, 167 | "children": [ 168 | { 169 | "attributes": { 170 | "constant": false, 171 | "name": "x", 172 | "scope": 772, 173 | "stateVariable": false, 174 | "storageLocation": "memory", 175 | "type": "uint256[] memory", 176 | "value": null, 177 | "visibility": "internal" 178 | }, 179 | "children": [ 180 | { 181 | "attributes": { 182 | "length": null, 183 | "type": "uint256[] storage pointer" 184 | }, 185 | "children": [ 186 | { 187 | "attributes": { 188 | "name": "uint", 189 | "type": "uint256" 190 | }, 191 | "id": 738, 192 | "name": "ElementaryTypeName", 193 | "src": "229:4:18" 194 | } 195 | ], 196 | "id": 739, 197 | "name": "ArrayTypeName", 198 | "src": "229:6:18" 199 | } 200 | ], 201 | "id": 740, 202 | "name": "VariableDeclaration", 203 | "src": "229:15:18" 204 | }, 205 | { 206 | "attributes": { 207 | "argumentTypes": null, 208 | "isConstant": false, 209 | "isLValue": false, 210 | "isPure": true, 211 | "isStructConstructorCall": false, 212 | "lValueRequested": false, 213 | "names": [ 214 | null 215 | ], 216 | "type": "uint256[] memory", 217 | "type_conversion": false 218 | }, 219 | "children": [ 220 | { 221 | "attributes": { 222 | "argumentTypes": [ 223 | { 224 | "typeIdentifier": "t_rational_5_by_1", 225 | "typeString": "int_const 5" 226 | } 227 | ], 228 | "isConstant": false, 229 | "isLValue": false, 230 | "isPure": true, 231 | "lValueRequested": false, 232 | "type": "function (uint256) pure returns (uint256[] memory)" 233 | }, 234 | "children": [ 235 | { 236 | "attributes": { 237 | "length": null, 238 | "type": "uint256[] storage pointer" 239 | }, 240 | "children": [ 241 | { 242 | "attributes": { 243 | "name": "uint", 244 | "type": "uint256" 245 | }, 246 | "id": 741, 247 | "name": "ElementaryTypeName", 248 | "src": "251:4:18" 249 | } 250 | ], 251 | "id": 742, 252 | "name": "ArrayTypeName", 253 | "src": "251:6:18" 254 | } 255 | ], 256 | "id": 743, 257 | "name": "NewExpression", 258 | "src": "247:10:18" 259 | }, 260 | { 261 | "attributes": { 262 | "argumentTypes": null, 263 | "hexvalue": "35", 264 | "isConstant": false, 265 | "isLValue": false, 266 | "isPure": true, 267 | "lValueRequested": false, 268 | "subdenomination": null, 269 | "token": "number", 270 | "type": "int_const 5", 271 | "value": "5" 272 | }, 273 | "id": 744, 274 | "name": "Literal", 275 | "src": "258:1:18" 276 | } 277 | ], 278 | "id": 745, 279 | "name": "FunctionCall", 280 | "src": "247:13:18" 281 | } 282 | ], 283 | "id": 746, 284 | "name": "VariableDeclarationStatement", 285 | "src": "229:31:18" 286 | }, 287 | { 288 | "children": [ 289 | { 290 | "attributes": { 291 | "argumentTypes": null, 292 | "isConstant": false, 293 | "isLValue": false, 294 | "isPure": false, 295 | "lValueRequested": false, 296 | "operator": "=", 297 | "type": "uint256" 298 | }, 299 | "children": [ 300 | { 301 | "attributes": { 302 | "argumentTypes": null, 303 | "isConstant": false, 304 | "isLValue": true, 305 | "isPure": false, 306 | "lValueRequested": true, 307 | "type": "uint256" 308 | }, 309 | "children": [ 310 | { 311 | "attributes": { 312 | "argumentTypes": null, 313 | "overloadedDeclarations": [ 314 | null 315 | ], 316 | "referencedDeclaration": 740, 317 | "type": "uint256[] memory", 318 | "value": "x" 319 | }, 320 | "id": 747, 321 | "name": "Identifier", 322 | "src": "266:1:18" 323 | }, 324 | { 325 | "attributes": { 326 | "argumentTypes": null, 327 | "hexvalue": "30", 328 | "isConstant": false, 329 | "isLValue": false, 330 | "isPure": true, 331 | "lValueRequested": false, 332 | "subdenomination": null, 333 | "token": "number", 334 | "type": "int_const 0", 335 | "value": "0" 336 | }, 337 | "id": 748, 338 | "name": "Literal", 339 | "src": "268:1:18" 340 | } 341 | ], 342 | "id": 749, 343 | "name": "IndexAccess", 344 | "src": "266:4:18" 345 | }, 346 | { 347 | "attributes": { 348 | "argumentTypes": null, 349 | "hexvalue": "31", 350 | "isConstant": false, 351 | "isLValue": false, 352 | "isPure": true, 353 | "lValueRequested": false, 354 | "subdenomination": null, 355 | "token": "number", 356 | "type": "int_const 1", 357 | "value": "1" 358 | }, 359 | "id": 750, 360 | "name": "Literal", 361 | "src": "273:1:18" 362 | } 363 | ], 364 | "id": 751, 365 | "name": "Assignment", 366 | "src": "266:8:18" 367 | } 368 | ], 369 | "id": 752, 370 | "name": "ExpressionStatement", 371 | "src": "266:8:18" 372 | }, 373 | { 374 | "children": [ 375 | { 376 | "attributes": { 377 | "argumentTypes": null, 378 | "isConstant": false, 379 | "isLValue": false, 380 | "isPure": false, 381 | "lValueRequested": false, 382 | "operator": "=", 383 | "type": "uint256[] storage ref" 384 | }, 385 | "children": [ 386 | { 387 | "attributes": { 388 | "argumentTypes": null, 389 | "overloadedDeclarations": [ 390 | null 391 | ], 392 | "referencedDeclaration": 734, 393 | "type": "uint256[] storage ref", 394 | "value": "bar" 395 | }, 396 | "id": 753, 397 | "name": "Identifier", 398 | "src": "280:3:18" 399 | }, 400 | { 401 | "attributes": { 402 | "argumentTypes": null, 403 | "overloadedDeclarations": [ 404 | null 405 | ], 406 | "referencedDeclaration": 740, 407 | "type": "uint256[] memory", 408 | "value": "x" 409 | }, 410 | "id": 754, 411 | "name": "Identifier", 412 | "src": "286:1:18" 413 | } 414 | ], 415 | "id": 755, 416 | "name": "Assignment", 417 | "src": "280:7:18" 418 | } 419 | ], 420 | "id": 756, 421 | "name": "ExpressionStatement", 422 | "src": "280:7:18" 423 | }, 424 | { 425 | "children": [ 426 | { 427 | "attributes": { 428 | "argumentTypes": null, 429 | "isConstant": false, 430 | "isLValue": false, 431 | "isPure": false, 432 | "isStructConstructorCall": false, 433 | "lValueRequested": false, 434 | "names": [ 435 | null 436 | ], 437 | "type": "tuple()", 438 | "type_conversion": false 439 | }, 440 | "children": [ 441 | { 442 | "attributes": { 443 | "argumentTypes": [ 444 | { 445 | "typeIdentifier": "t_bool", 446 | "typeString": "bool" 447 | } 448 | ], 449 | "overloadedDeclarations": [ 450 | null 451 | ], 452 | "referencedDeclaration": 1185, 453 | "type": "function (bool) pure", 454 | "value": "assert" 455 | }, 456 | "id": 757, 457 | "name": "Identifier", 458 | "src": "294:6:18" 459 | }, 460 | { 461 | "attributes": { 462 | "argumentTypes": null, 463 | "commonType": { 464 | "typeIdentifier": "t_uint256", 465 | "typeString": "uint256" 466 | }, 467 | "isConstant": false, 468 | "isLValue": false, 469 | "isPure": false, 470 | "lValueRequested": false, 471 | "operator": "==", 472 | "type": "bool" 473 | }, 474 | "children": [ 475 | { 476 | "attributes": { 477 | "argumentTypes": null, 478 | "overloadedDeclarations": [ 479 | null 480 | ], 481 | "referencedDeclaration": 731, 482 | "type": "uint256", 483 | "value": "foo" 484 | }, 485 | "id": 758, 486 | "name": "Identifier", 487 | "src": "301:3:18" 488 | }, 489 | { 490 | "attributes": { 491 | "argumentTypes": null, 492 | "hexvalue": "30", 493 | "isConstant": false, 494 | "isLValue": false, 495 | "isPure": true, 496 | "lValueRequested": false, 497 | "subdenomination": null, 498 | "token": "number", 499 | "type": "int_const 0", 500 | "value": "0" 501 | }, 502 | "id": 759, 503 | "name": "Literal", 504 | "src": "308:1:18" 505 | } 506 | ], 507 | "id": 760, 508 | "name": "BinaryOperation", 509 | "src": "301:8:18" 510 | } 511 | ], 512 | "id": 761, 513 | "name": "FunctionCall", 514 | "src": "294:16:18" 515 | } 516 | ], 517 | "id": 762, 518 | "name": "ExpressionStatement", 519 | "src": "294:16:18" 520 | }, 521 | { 522 | "children": [ 523 | { 524 | "attributes": { 525 | "argumentTypes": null, 526 | "isConstant": false, 527 | "isLValue": false, 528 | "isPure": false, 529 | "isStructConstructorCall": false, 530 | "lValueRequested": false, 531 | "names": [ 532 | null 533 | ], 534 | "type": "tuple()", 535 | "type_conversion": false 536 | }, 537 | "children": [ 538 | { 539 | "attributes": { 540 | "argumentTypes": [ 541 | { 542 | "typeIdentifier": "t_bool", 543 | "typeString": "bool" 544 | } 545 | ], 546 | "overloadedDeclarations": [ 547 | null 548 | ], 549 | "referencedDeclaration": 1185, 550 | "type": "function (bool) pure", 551 | "value": "assert" 552 | }, 553 | "id": 763, 554 | "name": "Identifier", 555 | "src": "316:6:18" 556 | }, 557 | { 558 | "attributes": { 559 | "argumentTypes": null, 560 | "commonType": { 561 | "typeIdentifier": "t_uint256", 562 | "typeString": "uint256" 563 | }, 564 | "isConstant": false, 565 | "isLValue": false, 566 | "isPure": false, 567 | "lValueRequested": false, 568 | "operator": "==", 569 | "type": "bool" 570 | }, 571 | "children": [ 572 | { 573 | "attributes": { 574 | "argumentTypes": null, 575 | "isConstant": false, 576 | "isLValue": true, 577 | "isPure": false, 578 | "lValueRequested": false, 579 | "type": "uint256" 580 | }, 581 | "children": [ 582 | { 583 | "attributes": { 584 | "argumentTypes": null, 585 | "overloadedDeclarations": [ 586 | null 587 | ], 588 | "referencedDeclaration": 734, 589 | "type": "uint256[] storage ref", 590 | "value": "bar" 591 | }, 592 | "id": 764, 593 | "name": "Identifier", 594 | "src": "323:3:18" 595 | }, 596 | { 597 | "attributes": { 598 | "argumentTypes": null, 599 | "hexvalue": "30", 600 | "isConstant": false, 601 | "isLValue": false, 602 | "isPure": true, 603 | "lValueRequested": false, 604 | "subdenomination": null, 605 | "token": "number", 606 | "type": "int_const 0", 607 | "value": "0" 608 | }, 609 | "id": 765, 610 | "name": "Literal", 611 | "src": "327:1:18" 612 | } 613 | ], 614 | "id": 766, 615 | "name": "IndexAccess", 616 | "src": "323:6:18" 617 | }, 618 | { 619 | "attributes": { 620 | "argumentTypes": null, 621 | "hexvalue": "31", 622 | "isConstant": false, 623 | "isLValue": false, 624 | "isPure": true, 625 | "lValueRequested": false, 626 | "subdenomination": null, 627 | "token": "number", 628 | "type": "int_const 1", 629 | "value": "1" 630 | }, 631 | "id": 767, 632 | "name": "Literal", 633 | "src": "333:1:18" 634 | } 635 | ], 636 | "id": 768, 637 | "name": "BinaryOperation", 638 | "src": "323:11:18" 639 | } 640 | ], 641 | "id": 769, 642 | "name": "FunctionCall", 643 | "src": "316:19:18" 644 | } 645 | ], 646 | "id": 770, 647 | "name": "ExpressionStatement", 648 | "src": "316:19:18" 649 | } 650 | ], 651 | "id": 771, 652 | "name": "Block", 653 | "src": "223:117:18" 654 | } 655 | ], 656 | "id": 772, 657 | "name": "FunctionDefinition", 658 | "src": "195:145:18" 659 | } 660 | ], 661 | "id": 773, 662 | "name": "ContractDefinition", 663 | "src": "25:317:18" 664 | } 665 | ], 666 | "id": 774, 667 | "name": "SourceUnit", 668 | "src": "0:343:18" 669 | }, 670 | "compiler": { 671 | "name": "solc", 672 | "version": "0.4.18+commit.9cf6e910.Emscripten.clang" 673 | }, 674 | "networks": {}, 675 | "schemaVersion": "1.0.1", 676 | "updatedAt": "2018-01-20T00:19:40.120Z" 677 | } -------------------------------------------------------------------------------- /contracts/AddressEmpty.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.4; 2 | 3 | contract MyContract { 4 | function isEmptyAddress(address addr) returns (bool) { 5 | return (addr == address(0)); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /contracts/AddressToString.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.4; 2 | 3 | contract MyContract { 4 | string public str; 5 | 6 | function MyContract() { 7 | str = toString(msg.sender); 8 | } 9 | 10 | function toString(address addr) returns (string) { 11 | bytes memory b = new bytes(20); 12 | for (uint i = 0; i < 20; i++) 13 | b[i] = byte(uint8(uint(addr) / (2**(8*(19 - i))))); 14 | return string(b); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /contracts/ArrayLiteralType.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.4; 2 | 3 | contract MyContract { 4 | function MyContract() { 5 | /* This creates a `TypeError` because uint8[3] memory 6 | * can't be converted to uint256[] memory. 7 | */ 8 | // uint[3] memory x = [1, 2, 3]; 9 | 10 | // This works, because it's the same common type. 11 | uint8[3] memory y = [1, 2, 3]; 12 | 13 | // This works, because it's the same common type. 14 | uint16[3] memory z = [256, 2, 3]; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /contracts/ArrayRemove.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.4; 2 | 3 | contract MyContract { 4 | uint[] array = [1,2,3]; 5 | 6 | function removeAtIndex(uint index) returns (uint[]) { 7 | if (index >= array.length) return; 8 | 9 | for (uint i = index; i < array.length-1; i++) { 10 | array[i] = array[i+1]; 11 | } 12 | 13 | array.length--; 14 | 15 | return array; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /contracts/BytesToAddress.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.4; 2 | 3 | contract MyContract { 4 | function bytesToAddress(bytes _address) public returns (address) { 5 | uint160 m = 0; 6 | uint160 b = 0; 7 | 8 | for (uint8 i = 0; i < 20; i++) { 9 | m *= 256; 10 | b = uint160(_address[i]); 11 | m += (b); 12 | } 13 | 14 | return address(m); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /contracts/DateSuffixes.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.4; 2 | 3 | contract MyContract { 4 | function MyContract() { 5 | assert(1 == 1 seconds); 6 | assert(1 minutes == 60 seconds); 7 | assert(1 hours == 60 minutes); 8 | assert(1 days == 24 hours); 9 | assert(1 weeks == 7 days); 10 | assert(1 years == 365 days); 11 | } 12 | 13 | function hasStarted(uint start, uint daysAfter) returns (bool) { 14 | return (now >= start + daysAfter * 1 days); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /contracts/DefaultDataTypes.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.4; 2 | 3 | contract MyContract { 4 | int n; // 0 5 | string str; // "" 6 | address addr; // 0x0000000000000000000000000000000000000000 7 | bool b; // false 8 | 9 | function MyContract() { 10 | assert(n == 0); 11 | assert(sha3(str) == ""); 12 | assert(addr == address(0)); 13 | assert(b == false); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /contracts/Enum.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.4; 2 | 3 | contract MyContract { 4 | enum MyEnum { 5 | Foo, 6 | Bar, 7 | Qux 8 | } 9 | 10 | function MyContract() { 11 | assert(uint(MyEnum.Foo) == 0); 12 | assert(uint(MyEnum.Bar) == 1); 13 | assert(uint(MyEnum.Qux) == 2); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /contracts/ExternalVsPublic.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.4; 2 | 3 | contract MyContract { 4 | function publicCalculate(uint[20] a) public returns (uint){ 5 | return a[10]*2; 6 | } 7 | 8 | function externalCalcuate(uint[20] a) external returns (uint){ 9 | return a[10]*2; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /contracts/IndexedEvents.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.4; 2 | 3 | contract MyContract { 4 | event Transfer(address indexed sender, address indexed recipient, uint256 amount); 5 | } 6 | -------------------------------------------------------------------------------- /contracts/InfiniteLoop.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.4; 2 | 3 | contract MyContract { 4 | function loop() { 5 | /* `i` will have max a max value of 255 (initialized as uint8), 6 | * causing an infinite loop. 7 | */ 8 | for (var i = 0; i < 1000; i++) { 9 | 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /contracts/MemoryArray.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.4; 2 | 3 | contract MemoryArray { 4 | uint[] foo; 5 | 6 | function MemoryArray () { 7 | uint[] memory bar = new uint[](5); 8 | bytes memory qux = new bytes(5); 9 | 10 | // dynamically resize storage array 11 | foo.length = 6; 12 | foo[5] = 1; 13 | assert(foo[5] == 1); 14 | 15 | // doesn't work 16 | // bar.length = 6; 17 | // qux.length = 6; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /contracts/Migrations.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.4; 2 | 3 | contract Migrations { 4 | address public owner; 5 | uint public last_completed_migration; 6 | 7 | modifier restricted() { 8 | if (msg.sender == owner) _; 9 | } 10 | 11 | function Migrations() { 12 | owner = msg.sender; 13 | } 14 | 15 | function setCompleted(uint completed) restricted { 16 | last_completed_migration = completed; 17 | } 18 | 19 | function upgrade(address new_address) restricted { 20 | Migrations upgraded = Migrations(new_address); 21 | upgraded.setCompleted(last_completed_migration); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /contracts/MultipleValuesReturn.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.4; 2 | 3 | contract MyContract { 4 | struct MyStruct { 5 | string str; 6 | uint i; 7 | } 8 | 9 | MyStruct myStruct; 10 | 11 | function MyContract() { 12 | myStruct = MyStruct("foo", 1); 13 | } 14 | 15 | function myMethod() external returns (string, uint) { 16 | return (myStruct.str, myStruct.i); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /contracts/Pragma.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.4; 2 | 3 | contract MyContract { 4 | 5 | } 6 | -------------------------------------------------------------------------------- /contracts/Random.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.4; 2 | 3 | contract MyContract { 4 | uint nonce = 0; 5 | 6 | function rand(uint min, uint max) public returns (uint) { 7 | return uint(block.blockhash(block.number-1))%(min+max)-min; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /contracts/ReturnVariables.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.4; 2 | 3 | contract MyContract { 4 | function MyContract() { 5 | assert(myMethod() == 10); 6 | } 7 | 8 | function myMethod() returns (uint num) { 9 | num = 10; 10 | return num; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /contracts/SafeMath.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.4; 2 | 3 | contract SafeMath { 4 | function safeAdd(uint256 x, uint256 y) returns(uint256) { 5 | uint256 z = x + y; 6 | assert((z >= x) && (z >= y)); 7 | return z; 8 | } 9 | 10 | function safeSubtract(uint256 x, uint256 y) returns(uint256) { 11 | assert(x >= y); 12 | uint256 z = x - y; 13 | return z; 14 | } 15 | 16 | function safeMult(uint256 x, uint256 y) returns(uint256) { 17 | uint256 z = x * y; 18 | assert((x == 0)||(z/x == y)); 19 | return z; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /contracts/StorageOverride.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.4; 2 | 3 | contract StorageOverride { 4 | uint foo; 5 | uint[] bar; 6 | 7 | /* 8 | // This will not work! 9 | function StorageOverride () { 10 | uint[] x; 11 | x.push(1); 12 | bar = x; 13 | } 14 | */ 15 | 16 | function StorageOverride () { 17 | uint[] memory x = new uint[](5); 18 | x[0] = 1; 19 | bar = x; 20 | 21 | assert(foo == 0); 22 | assert(bar[0] == 1); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /contracts/StringCompare.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.4; 2 | 3 | contract MyContract { 4 | function compare(string s1, string s2) returns (bool) { 5 | return (sha3(s1) == sha3(s2)); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /contracts/StringLength.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.4; 2 | 3 | contract MyContract { 4 | string str = "foo"; 5 | 6 | function MyContract() { 7 | assert(bytesSize(str) == 3); 8 | assert(size(str) == 3); 9 | } 10 | 11 | function bytesSize(string s) returns (uint) { 12 | return bytes(s).length; 13 | } 14 | 15 | function size(string s) returns (uint) { 16 | uint length = 0; 17 | uint i = 0; 18 | bytes memory strBytes = bytes(s); 19 | 20 | while (i < strBytes.length) { 21 | if (strBytes[i]>>7 == 0) { 22 | i+=1; 23 | } else if (strBytes[i]>>5 == 0x6) { 24 | i+=2; 25 | } else if (strBytes[i]>>4 == 0xE) { 26 | i+=3; 27 | } else if (strBytes[i]>>3 == 0x1E) { 28 | i+=4; 29 | } else { 30 | i+=1; 31 | } 32 | 33 | length++; 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /contracts/VariableScope.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.4; 2 | 3 | contract MyContract { 4 | function whileLoop() { 5 | uint i = 0; 6 | 7 | while (i++ < 1) { 8 | uint foo = 0; 9 | } 10 | 11 | /* 12 | while (i++ < 2) { 13 | // Illegal, second declaration of variable. 14 | uint foo = 0; 15 | } 16 | */ 17 | } 18 | 19 | function forLoop() { 20 | for (uint i = 0; i < 1; i ++) { 21 | 22 | } 23 | 24 | /* 25 | // Illegal, second declaration of variable. 26 | for (uint i = 0; i < 1; i++) { 27 | 28 | } 29 | */ 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /contracts/bytes32ToString.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.4; 2 | 3 | // Source: https://ethereum.stackexchange.com/a/2834/5093 4 | 5 | contract MyContract { 6 | bytes32 bts = "foo"; 7 | string str; 8 | 9 | function MyContract() { 10 | str = bytes32ToString(bts); 11 | } 12 | 13 | function bytes32ToString(bytes32 x) constant returns (string) { 14 | bytes memory bytesString = new bytes(32); 15 | uint charCount = 0; 16 | for (uint j = 0; j < 32; j++) { 17 | byte char = byte(bytes32(uint(x) * 2 ** (8 * j))); 18 | if (char != 0) { 19 | bytesString[charCount] = char; 20 | charCount++; 21 | } 22 | } 23 | bytes memory bytesStringTrimmed = new bytes(charCount); 24 | for (j = 0; j < charCount; j++) { 25 | bytesStringTrimmed[j] = bytesString[j]; 26 | } 27 | return string(bytesStringTrimmed); 28 | } 29 | 30 | function bytes32ArrayToString(bytes32[] data) returns (string) { 31 | bytes memory bytesString = new bytes(data.length * 32); 32 | uint urlLength; 33 | for (uint i=0; i