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

Reduced gas cost for static calls made to precompiles #2046

Merged
merged 6 commits into from
May 23, 2019
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions EIPS/eip-1679.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ This meta-EIP specifies the changes included in the Ethereum hardfork named Ista
- [EIP-1884](https://eips.ethereum.org/EIPS/eip-1884): Repricing for trie-size-dependent opcodes
- [EIP-1930](https://eips.ethereum.org/EIPS/eip-1930): CALLs with strict gas semantic. Revert if not enough gas available.
- [EIP-2028](https://eips.ethereum.org/EIPS/eip-2028): Calldata gas cost reduction
- [EIP-2046](https://eips.ethereum.org/EIPS/eip-2046): Reduced gas cost for static calls made to precompiles

## Timeline

Expand Down
69 changes: 69 additions & 0 deletions EIPS/eip-2046.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
---
eip: 2046
title: Reduced gas cost for static calls made to precompiles
author: Alex Beregszaszi (@axic)
discussions-to: https://ethereum-magicians.org/t/eip-2046-reduced-gas-cost-for-static-calls-made-to-precompiles/3291
status: Draft
type: Standards Track
category: Core
created: 2019-05-17
requires: 214, 1352
---

## Simple Summary

This change reduces the gas cost of using precompiled contracts.

## Abstract

Reduce the base gas cost of calling precompiles using `STATICCALL` from 700 to 40. This should allow more efficient use of precompiles as well as precompiles with a total cost below 700.

## Motivation

The Spurious Dragon hard fork increased the cost of calls significantly to account for loading contract code from the state without making an exception for precompiles, whose "code" is always loaded.

This made use of certain precompiles impractical.

FIXME: extend this with recent reasoning about ECC repricings.

## Specification

After block `HF` the `STATICCALL` (`0xfa`) instruction charges different basic gas cost (G<sub>call</sub> in [Yellow Paper]'s notation) depending on the destination address provided:
- for precompiles (address range as per [EIP-1352]) the cost is `40`
- for every other address the cost remains unchanged (`700`)

## Rationale

Only the `STATICCALL` instruction was changed to reduce the impact of the change. This should not be a limiting factor, given precompiles (currently) do not have a state and cannot change the state.
However, contracts created and deployed before Byzantium likely will not use `STATICCALL` and as a result this change will not reduce their costs.

Contrary to EIP-1109 gas reduction to `0` is not proposed. The cost `40` is kept as a cost representing the context switching needed.

## Backwards Compatibility

This EIP should be backwards compatible. The only effect is that the cost is reduced. Since the cost is not reduced to zero, it should not be possible for a malicious proxy contract, when deployed before
the `HF`, to do any state changing operation.

## Test Cases

TBA

## Implementation

TBA

## References

This has been previously suggested as part of [EIP-1109](https://github.com/ethereum/EIPs/pull/1109) and [EIP-1231](https://github.com/ethereum/EIPs/pull/1231).
However EIP-1109 was later changed to a very different approach. The author [has suggested to change EIP-1109](https://ethereum-magicians.org/t/eip-1109-remove-call-costs-for-precompiled-contracts/447/7).

## Acknowledgements

Jordi Baylina (@jbaylina) and Matthew Di Ferrante (@mattdf) who have proposed this before.

## Copyright

Copyright and related rights waived via [CC0](https://creativecommons.org/publicdomain/zero/1.0/).

[Yellow Paper]: https://github.com/ethereum/yellowpaper
[EIP-1352]: https://eips.ethereum.org/EIPS/eip-1352