Skip to content

Commit

Permalink
MLOAD and MSTORE.
Browse files Browse the repository at this point in the history
  • Loading branch information
virgil-serbanuta committed Nov 29, 2017
1 parent 4ea5d71 commit b2c36ba
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions gas.md
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,13 @@ of the logged registers.
computationCost(MLOAD rREG wINDEX) = mLoadCost + mloadWordCost * memoryCellSize(value wIndex)
estimatedResultSize(MLOAD rREG wINDEX) = memoryCellSize(value wIndex)
```
* `MLOADN`
```hs
computationCost(MLOADN rREG, wINDEX1, wINDEX2, wWIDTH) =
mLoadNCost + mLoadWordCost * wWIDTH
memoryDelta(MLOADN rREG, wINDEX1, wINDEX2, wWIDTH) =
wWIDTH - registerSize rREG
```
* `MSTORE` when we store a new value over an old one, we compute the difference
in size between the two values. Similar to changes to registers, this difference is used to update the
current memory requirements, and, if it increases, it might update the top
Expand All @@ -722,6 +729,20 @@ of the logged registers.
memoryCost(MSTORE wINDEX wVALUE) =
(registerSize wVALUE - storeCellSize(value wIndex))
```
* `MSTOREN`
TODO: This assumes that mstoren inserts stuff at index2. If so, what happens
when INDEX2 does not point into the current memory value? Does the unused
space get filled with 0?
TODO: Check that I understood the semantics.

```hs
computationCost(MSTOREN wINDEX1 wINDEX2 wVALUE wWIDTH) =
mStoreNCost +
mStoreWordCost * max(0, wINDEX2 - storeCellSize(value wIINDEX1))
mStoreWordCost * wWIDTH
memoryDelta(MSTOREN wINDEX1 wINDEX2 wVALUE wWIDTH) =
wWIDTH + max(0, wINDEX2 - storeCellSize(value wIINDEX1))
```

#### Register manipulations
* `MOVE` copies a value from one register to another
Expand Down Expand Up @@ -847,14 +868,13 @@ Definitions
* Check that GMP can give number of limbs in constant time or update costs accordingly
* Check that all background costs are accounted for (e.g. updating a register's)
metadata after an assignment.
* Check that memory deltas are used properly everywhere (e.g. MLOAD).

### TODOS: Instructions to add

* EXTCODESIZE
* CREATE
* SELFDESTRUCT
* MLOADN
* MSTOREN
* COPYCREATE

### TODOS: Instructions to consider if they should be added
Expand Down

0 comments on commit b2c36ba

Please sign in to comment.