Skip to content

Commit

Permalink
Account for all register costs for calls.
Browse files Browse the repository at this point in the history
  • Loading branch information
virgil-serbanuta committed Nov 27, 2017
1 parent 470502e commit c9f01ff
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions gas.md
Original file line number Diff line number Diff line change
Expand Up @@ -378,14 +378,30 @@ We assume that all operations interrogating the local state have complexity
Save the local context (including the current register stack memory
requirements), copy the arguments into the new context and jump to
the call site.

We're assuming that, in an efficient implementation, saving the caller's
registers is a small constant time operation. One way or another, an
efficient implementation will, in the general case, hold the actual register
data in memory, while, maybe, using machine registers for the machine
metadata. Regardless of how these optimizations are done, saving the caller
context and creating the callee context takes
constantTime + someConstant * registerCount, and a similar amount of memory.

```hs
computationCost(LOCALCALL(_, nARGS, _) _ rARGS) =
saveContextCost + wordCopyCost * (sum [registerSize r | r <- rARGS])
returnAddressSaveCost + wordSetCost * REGISTERS +
wordCopyCost * (sum [registerSize r | r <- rARGS])
+ jumpCost + callStackDepthCheckCost
requiredRegisterMemory(LOCALCALL(_, nARGS, _) _ rARGS) =
currentRegisterMemory + sum [registerSize(r) | r <- rVALUES]
memoryDelta(LOCALCALL(_, nARGS, _) _ rARGS) =
currentRegisterMemory + sum [registerSize(r) | r <- rARGS]
+ returnAddressSize -- return address
+ registerMetadataSize * REGISTERS -- unused register table
```

`REGISTERS` is the maximum number of registers as declared in the contract
prefix. TODO: Use the caller's actual register count or callee's max register
count instead.

* `RETURN`
Copy values from return registers to caller locations restore local context,
including (the current register stack memory requirements), mark registers'
Expand Down

0 comments on commit c9f01ff

Please sign in to comment.