Skip to content

Commit

Permalink
Tmp
Browse files Browse the repository at this point in the history
  • Loading branch information
virgil-serbanuta committed Nov 24, 2017
1 parent d4b72b1 commit 402def9
Showing 1 changed file with 29 additions and 4 deletions.
33 changes: 29 additions & 4 deletions gas.md
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,9 @@ NOTE: (continuation) The above may be too complex, so then we may want to have
pairs (currently we implicitly use a stack for total memory usage
in the 'return' cost).

* `RETURN`
* `RETURN` (local version)
A `RETURN` is a local one if the call stack is not empty.

Copy values from return registers to caller locations restore local context,
including (the current register stack memory requirements), mark registers'
data for reclaiming, and jump back to call site. Note that, since the
Expand All @@ -422,21 +424,44 @@ NOTE: (continuation) The above may be too complex, so then we may want to have
sum [registerLoadDelta(r, v) | (r, v) <- getReturns() `zip` rVALUES]
```

#### `INVALID`, `STOP`, `REVERT` and exceptions
#### `RETURN` (account call version), `INVALID`, `STOP`, `REVERT` and exceptions

A `RETURN` is a an account call one if the call stack is empty.

`INVALID` generates an exception, but many other things do, including being
out of gas, which means that there may not be any gas to pay for the exception.

* `STOP`
`STOP` is an explicit instruction, but reaching the end of a function would
also do an implicit stop.

TODO: Delete: All of `RETURN` (account), `INVALID`, `STOP`, `REVERT` and exceptions use the
return information from the caller (the output registers and the error register,
sometimes other information) and.

* `INVALID` and exceptions in general
```hs
computationCost(STOP) = stopCost() -- defined in terms of the current execution context
computationCost(STOP|INVALID|exception) =
environmentRestoreCost + wordCopyCost * (registersize 0)
```
* `STOP`.
```hs
computationCost(STOP|INVALID|exception) = environmentRestoreCost +
```
* `REVERT`
```hs
computationCost(REVERT(nRETURNS) rVALUES) = wordCopyCost * registerSize(rValues) +
revertCost() -- defined in terms of the current execution context.
```

environmentRestoreCost is the cost of re-establishing the callStack, worldState
and subState pointers to what they were before the current contract call.

TODO: Do we count any cost for freeing memory? This occurs at any operation
which resizes a register or a memory value, but it's most obvious at calls,
returns and similar things. I guess that it's better to include the memory
freeing cost in the allocation cost since all memory seems to be freed after the
top call finishes. We should check that this is the case.

TODO: Figure out more precise costs for these

#### `CALL`, `CALLCODE`, `DELEGATECALL` and `STATICCALL`
Expand Down

0 comments on commit 402def9

Please sign in to comment.