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

Several EVM Precompile Clean-Ups & Renamings #3655

Merged
merged 10 commits into from
Sep 12, 2024

Conversation

holgerd77
Copy link
Member

@holgerd77 holgerd77 commented Sep 11, 2024

This PR does the following:

  • Renames the EVM bn254 precompiles (ec based names like ecAdd too generic, not consistent with bls12)
  • Makes usage of the precompile names canonical by only using the versions from precompiles/index.ts precompileEntries as a source of truth (this comes along with renamings as well as inconsistency fixes, e.g. Identity -> IDENTITY, some hex address additions, KZG -> KZG_POINT_EVALUATION)
  • Makes the (not fully exposed) getPrecompileName() a bit more flexible and comfortable, by left padding eventually left out 0s as well as return '' (instead of undefined) if no name available (simplifies typing, alternative would have been to just throw but decided that this might be a bit overblown for this type of method)
  • ec*Gas param names have also be renamed, to bn254*Gas
  • Bls12381*Gas param names have been renamed to bls12381*Gas (all our param names start with lower-case)

P.S.: Ignore the in-between hex reordering. I was confused. 🙂 🙃

Copy link

codecov bot commented Sep 11, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 0.00%. Comparing base (4470cc3) to head (ef6ccc9).
Report is 50 commits behind head on master.

❗ There is a different number of reports uploaded between BASE (4470cc3) and HEAD (ef6ccc9). Click for more details.

HEAD has 3 uploads less than BASE
Flag BASE (4470cc3) HEAD (ef6ccc9)
block 1 0
client 1 0
tx 1 0
Additional details and impacted files

Impacted file tree graph

Flag Coverage Δ
block ?
client ?
tx ?
wallet 0.00% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Copy link
Member

@jochem-brouwer jochem-brouwer left a comment

Choose a reason for hiding this comment

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

Two small comments

import type { ExecResult } from '../types.js'
import type { PrecompileInput } from './types.js'

export function precompile01(opts: PrecompileInput): ExecResult {
const pName = getPrecompileName('01')
Copy link
Member

Choose a reason for hiding this comment

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

This constant can be moved outside this method, such that it does not get called each time if this precompile gets called (micro-optimization). (For all precompiles)

Copy link
Member Author

Choose a reason for hiding this comment

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

Will do.

Copy link
Member Author

Choose a reason for hiding this comment

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

(and totally not so "micro", makes a lot of sense)

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, this does not seem to work, CI breaks on several occasions:

grafik

When looking at the code, I think this is due to circular imports (this whole precompile code is generally not so optimally organized, but I would not want to expand this into a full round refactor), so the precompiles/index.ts file is importing all the precompiles but is then itself exporting this getPrecompileName method, this does not seem to be able to be resolved.

Can we therefore please keep the non-optimized version? Will delete the respective commit again and re-push. I do not have an easy fix for this.

import { precompile08 } from './08-ecpairing.js'
import { precompile06 } from './06-bn254-add.js'
import { precompile07 } from './07-bn254-mul.js'
import { precompile08 } from './08-bn254-pairing.js'
Copy link
Member

Choose a reason for hiding this comment

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

I am confused now. The EIPs https://eips.ethereum.org/EIPS/eip-196 https://eips.ethereum.org/EIPS/eip-197 mention that these are "alt_bn128"? It seems that bn254 is an alias for this? 🤔

Copy link
Member

Choose a reason for hiding this comment

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

Yes, these are the same things. It was called bn128 when it had 128-bit security, but then researchers decreased security bits. So it's now bn254, because of 254-bit field

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, I followed Pauls advice here, also googling a bit and stumbling upon articles like https://hackmd.io/@jpw/bn254 for some confirmation that this is the "official" respectively "cryptographically correct" name now.

This naming confusion is a thing though, to add on this: there is even the name "bn256" (!!) around, this seems to be wrong and there is some explanation what happened to these two bits I forgot again. 😂 Geth is using this (wrong) name though, I just discovered yesterday (which should not bother us).

But let's stop here. This is really not something where we can clean up the mess. So: bn254 seems very much to be the best choice here.

@holgerd77 holgerd77 force-pushed the several-evm-precompile-clean-ups branch from 559b7e5 to 88ccf9c Compare September 12, 2024 09:10
@holgerd77
Copy link
Member Author

Ok, addressed, ready for re-review! 🙂

@holgerd77 holgerd77 force-pushed the several-evm-precompile-clean-ups branch from 88ccf9c to 23af1ac Compare September 12, 2024 09:42
@holgerd77 holgerd77 merged commit 4da6647 into master Sep 12, 2024
38 checks passed
@holgerd77 holgerd77 deleted the several-evm-precompile-clean-ups branch September 12, 2024 10:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants