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

EIP-1108: Reduce alt bn128 gas costs #1108

Merged

Conversation

Shadowfiend
Copy link
Contributor

Originally discussed in #1088 , this draft EIP proposes a 10x reduction in the gas cost for the ECADD precompile, 20x for ECMUL, and a 14x reduction in the per-pairing cost of the pairing check precompile alongside a modest 20% constant factor reduction, based on a recent switch to a significantly faster underlying implementation of these precompiles.

Please let me know if there are any adjustments to style/structures that need to be made here… I didn't see any previous EIPs in this vein, so tried to fit it to the EIP-1 structure and the template as best I could.

@Shadowfiend
Copy link
Contributor Author

One note that came out of the original discussion was that it's unclear where the constant factor in the pairing check gas costs comes from. I tried to look in the implementation threads and the original discussions around EIP-197, but didn't find a clear context. The suggestion in #1088 was that the constant factor be eliminated; I have not included that particular change in this PR yet, but would be interested in additional context/thoughts on that front. In particular, perhaps the original authors of EIP-197, @vbuterin and @chriseth, could chime in on what motivated that constant factor in the first place, so we can see if it makes sense to reduce it further based on the new implementations.

@jbaylina
Copy link
Contributor

jbaylina commented May 22, 2018

It's important to reduce the cost of the CALL opcode for precompiled smart contracts.
It does not make a sense that SHA256 costs 60 or ECADD costs 50 but the CALL costs 700

@chriseth
Copy link
Contributor

The constant term corresponds to the "final exponentiation" that is done after the miller loop and whose runtime does not depend on the number of factors.

Specific implementations should be tested in their runtime behaviour with regards to growing k. If they do not have this constant behaviour anymore, it can of course be dropped.

@Shadowfiend
Copy link
Contributor Author

@jbaylina while I don't necessarily disagree (I haven't looked into motivations behind the CALL cost), I think that's out of scope for this EIP, which is motivated by very specific implementation changes that have been benchmarked. Perhaps it would make sense to spin up a separate EIP regarding the CALL opcode?

@chriseth Really appreciate your chiming in with that additional context. I'll see if the referenced benchmarks show signs of this constant factor or not.

@jbaylina
Copy link
Contributor

@Shadowfiend it make sense...

I added #1109 for that.

@@ -0,0 +1,50 @@
---
```
Copy link
Contributor

Choose a reason for hiding this comment

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

Please remove the backticks here to comply with the standard formatting.

@@ -0,0 +1,50 @@
---
```
eip: <to be assigned>
Copy link
Contributor

Choose a reason for hiding this comment

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

Please rename to eip-1108.md and number 1108.

```
eip: <to be assigned>
title: Reduce alt_bn128 precompile gas costs
author: Antonio Salazar Cardozo (@shadowfiend) <antonio@keep.network>
Copy link
Contributor

Choose a reason for hiding this comment

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

Please supply either github username or email, not both.

@Shadowfiend Shadowfiend changed the title EIP: Reduce alt bn128 gas costs EIP 1108: Reduce alt bn128 gas costs May 23, 2018
@Shadowfiend Shadowfiend changed the title EIP 1108: Reduce alt bn128 gas costs EIP-1108: Reduce alt bn128 gas costs May 23, 2018
@mhluongo
Copy link
Contributor

Looks like comments were addressed- can you give this another look @Arachnid?

@mhluongo
Copy link
Contributor

For reference, here are the original and Cloudflare-based final exponentiation functions to compare. For details on Parity's implementation, check the PR implementing the pairing check EIP.

@Arachnid Arachnid merged commit 75b1416 into ethereum:master Jun 4, 2018
@Shadowfiend Shadowfiend deleted the eip-reduce-alt_bn128-gas-costs branch June 4, 2018 21:23
@shamatar
Copy link
Contributor

Good day, @Arachnid , @Shadowfiend

I think we have missed an important part regarding the different computational costs on G1 and G2 (roughly 4 times from naive estimation based on element sizes). May be gas price should be changed from the flat value to something like flat fee + price per 64 bytes of data size to distinguish G1 from G2 ops?

Sincerely, Alex

@Shadowfiend
Copy link
Contributor Author

Do you mean on ECMUL? The pairing check is already base + per-size multiplier.

@shamatar
Copy link
Contributor

Yes, ECMUL and ECADD. ECADD is 2 division and 2 multiplications mainly in affine cords for G1. In addition I’ll check the benchmarks for some linear price approximations

Arachnid pushed a commit to Arachnid/EIPs that referenced this pull request Jul 19, 2018
* Add draft of elliptic-curve gas cost reduction EIP

* Add status and EIP dependencies

* Lowercase preamble per observed practice

* Tweak EIP title to reflect core cause for cost reduction

The EIP listed out the precompiles, but really this is about reducing all
alt_bn128-related gas costs.

* Reduce constant factor in line with original EIP issue

For some reason this got missed when turning into PR form.

* Fix footnote formatting

* Drop extraneous code fence

* GitHub username only for EIP author line

* Label alt_bn128 gas cost EIP as EIP 1108
@Shadowfiend
Copy link
Contributor Author

Btw @shamatar we did update this EIP with some revised gas costs based on benchmarks across Ethereum and Parity @ #1452 .

@shamatar
Copy link
Contributor

shamatar commented Nov 4, 2018

Just as a side node - since EIP 1109 is unlikely to be ever accepted (in a form of new OPCODE at least), it may be more efficient (for end-users) to implement addition as manual point addition operation.

@benediamond
Copy link

@Shadowfiend has there been any movement on this recently...? Thanks.

@Shadowfiend
Copy link
Contributor Author

Absolutely! Some updates were recently added and it’s been added to EIP-1679, the meta-EIP for the forthcoming Istanbul hardfork, as a proposed EIP, thanks to @zac-williamson of @AztecProtocol.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants