Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create pure_call.md #195

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions EIPS/eip_195_pure_call.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
### Parameters

* BASE_GAS_COST: 80
* CODE_BYTES_PER_GAS: 15
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assuming we want to switch to EVM 1.5 - is that really the amount of gas we want to charge? Or shall we completely revise the scheme with 1.5?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What revisions do you have in mind?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps to add some more explanation: In EVM1.5, code that is about to be executed needs to be analyzed and sightly processed first. For regular contracts, this is done once at creation time and we can use the gas from the code deposit to pay for this preprocessing. Here, 15 bytes per gas could be too low for that.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. Not sure what the right amount is, as the preprocessing can run from simple validation to full compilation.


### Specification

At `0xf5`, add an opcode `PURE_CALL` that takes seven arguments from the stack: GAS, CODESTART, CODELENGTH, DATASTART, DATALENGTH, OUTPUTSTART, OUTPUTLENGTH.

Let:

* `gas_cost = BASE_GAS_COST + floor(CODELENGTH / CODE_BYTES_PER_GAS)`.
* `input_gas` be the remaining gas in the current context, minus gas costs for expanding memory to cover the three memory slices given above.

Fail if `input_gas < gas_cost` or if `CODELENGTH > 24000`; otherwise execute a call with code equal to the memory slice `CODESTART...CODESTART + CODELENGTH - 1`, input data equal to the memory slice `DATASTART...DATASTART + DATALENGTH - 1`, gas equal to `min(GAS, (input_gas - gas_cost) - floor((input_gas - gas_cost) / 64))` and value 0. The inner context may NOT read state, write state or make any sub-calls except to non-state-changing precompiles; any attempt to do so throws an exception. If execution succeeds, fill the memory slice `OUTPUTSTART...OUTPUTSTART + OUTPUTLENGTH - 1` with the return data with similar rules to how this is handled in CALL, CALLCODE and DELEGATECALL, and push 1 onto the stack. If execution fails, push 0 onto the stack.

### Rationale

This is useful for:

* Adding functional programming features for higher-level languages
* Generally allowing for forms of computation that are safer and can be efficiently optimized/memoized due to their state-independence
* Processing validation code for Casper validators in the future
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please waive the copyright with CC0.