From 402def949155f6c1bb99c39692eb2bbe8fced112 Mon Sep 17 00:00:00 2001 From: Virgil Serbanuta Date: Fri, 24 Nov 2017 20:06:25 +0200 Subject: [PATCH] Tmp --- gas.md | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/gas.md b/gas.md index 9a0287902..ce478a134 100644 --- a/gas.md +++ b/gas.md @@ -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 @@ -422,14 +424,28 @@ 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 @@ -437,6 +453,15 @@ out of gas, which means that there may not be any gas to pay for the exception. 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`