Skip to content

Commit

Permalink
Memory estimates for account calls
Browse files Browse the repository at this point in the history
  • Loading branch information
virgil-serbanuta committed Nov 29, 2017
1 parent 0a1aff4 commit f2b09d4
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion gas.md
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,9 @@ not include the code loading cost.

Also, it may seem counterintuitive to pay for the code loading cost, one may
expect to pay a flat fee as in the EVM model. A flat fee is usually less
efficient, so we're using a size-based fee.
efficient, so we're using a size-based fee. There is a similar memory
consumption associated with loading the code which, arguably, might be included
in a flat-fee cost.

```hs
-- CALLOP in [CALL, CALLCODE, DELEGATECALL, STATICCALL]
Expand Down Expand Up @@ -528,8 +530,37 @@ efficient, so we're using a size-based fee.

newAccountSetupCost(CALL) = accountCreationCost + accountTransferCost
newAccountSetupCost(CALLCODE|DELEGATECALL|STATICCALL) = 0

-- Memory increase/decrease follows a similar pattern

memoryDelta(early-failling, CALLOP) =
registerSize 0 - registerSize REG
memoryDelta(inexistent-account-late-failure) =
registerSize 0 - registerSize REG
memoryDelta(inexistent-account-success) = 0
registerSize 0 - registerSize REG

-- Temporary memory increase, i.e. the memory increases until the error is
-- detected, then it goes back to its initial value. I.e. it might be a good
-- idea to just update the max memory usage (if needed) and not the currently
-- used memory.
memorySpikeSize(existent-account-late-failure) = codeSize
-- The spike is followed by a normal memory delta.
memoryDelta(existent-account-late-failure) =
registerSize 0 - registerSize REG

memoryDeltaCaller(existent-account-success) = codeSize + constantMemorySize
memorySizeCallee(existent-account-success) = callDataSize
```

The calee starts with a memory usage of memorySizeCallee (absolute, not a
delta). There is a free memory allowance for each new contract call, equal to
the maximum EVM stack size, that will be taken into account separately.

`constantMemorySize` is the size of whatever is part of the saved state
except for the code and callData (calldepth, callValue, id, gas, caller,
static)

TODO: I (virgil) think that these costs are more reasonable than some costs
which follow the semantics in detail. However, we should be able to use
them inside the semantics, so we should make sure that this is possible.
Expand Down

0 comments on commit f2b09d4

Please sign in to comment.