Skip to content

Commit

Permalink
Update ethereum-cryptography (#3859)
Browse files Browse the repository at this point in the history
* upgrade eth-crypto to 3.1

* use noble/curves in evm

* Remove duplicate type
  • Loading branch information
acolytec3 authored Jan 30, 2025
1 parent 3e22e7d commit e4d55d3
Show file tree
Hide file tree
Showing 14 changed files with 136 additions and 78 deletions.
159 changes: 115 additions & 44 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/block/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"@ethereumjs/mpt": "^7.0.0-alpha.1",
"@ethereumjs/tx": "^6.0.0-alpha.1",
"@ethereumjs/util": "^10.0.0-alpha.1",
"ethereum-cryptography": "^3.0.0"
"ethereum-cryptography": "^3.1.0"
},
"devDependencies": {
"@paulmillr/trusted-setups": "^0.1.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
"connect": "^3.7.0",
"cors": "^2.8.5",
"debug": "^4.3.3",
"ethereum-cryptography": "^3.0.0",
"ethereum-cryptography": "^3.1.0",
"eventemitter3": "^5.0.1",
"jayson": "^4.0.0",
"level": "^8.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/devp2p/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
"@ethereumjs/util": "^10.0.0-alpha.1",
"@scure/base": "^1.1.7",
"debug": "^4.3.3",
"ethereum-cryptography": "^3.0.0",
"ethereum-cryptography": "^3.1.0",
"eventemitter3": "^5.0.1",
"lru-cache": "10.1.0",
"scanf": "1.1.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/ethash/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"@ethereumjs/rlp": "^6.0.0-alpha.1",
"@ethereumjs/util": "^10.0.0-alpha.1",
"bigint-crypto-utils": "^3.2.2",
"ethereum-cryptography": "^3.0.0"
"ethereum-cryptography": "^3.1.0"
},
"devDependencies": {
"@ethereumjs/common": "^5.0.0-alpha.1"
Expand Down
3 changes: 2 additions & 1 deletion packages/evm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,10 @@
"@ethereumjs/common": "^5.0.0-alpha.1",
"@ethereumjs/statemanager": "^3.0.0-alpha.1",
"@ethereumjs/util": "^10.0.0-alpha.1",
"@noble/curves": "^1.8.1",
"@types/debug": "^4.1.9",
"debug": "^4.3.3",
"ethereum-cryptography": "^3.0.0",
"ethereum-cryptography": "^3.1.0",
"eventemitter3": "^5.0.1"
},
"devDependencies": {
Expand Down
19 changes: 5 additions & 14 deletions packages/evm/src/precompiles/bls12_381/noble.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
equalsBytes,
setLengthLeft,
} from '@ethereumjs/util'
import { bls12_381 } from 'ethereum-cryptography/bls.js'
import { bls12_381 } from '@noble/curves/bls12-381'

import { ERROR, EvmError } from '../../exceptions.js'

Expand All @@ -21,17 +21,8 @@ import {
} from './constants.js'

import type { EVMBLSInterface } from '../../types.js'

// Copied from @noble/curves/bls12-381 (only local declaration)
type Fp2 = {
c0: bigint
c1: bigint
}
// Copied from @noble/curves/abstract/curve.ts (not exported in ethereum-cryptography)
type AffinePoint<T> = {
x: T
y: T
} & { z?: never; t?: never }
import type { Fp2 } from '@noble/curves/abstract/tower'
import type { AffinePoint } from '@noble/curves/abstract/weierstrass'

const G1_ZERO = bls12_381.G1.ProjectivePoint.ZERO
const G2_ZERO = bls12_381.G2.ProjectivePoint.ZERO
Expand All @@ -58,7 +49,7 @@ function BLS12_381_ToFp2Point(fpXCoordinate: Uint8Array, fpYCoordinate: Uint8Arr
* @returns Noble G1 point
*/
function BLS12_381_ToG1Point(input: Uint8Array, verifyOrder = true) {
if (equalsBytes(input, BLS_G1_INFINITY_POINT_BYTES)) {
if (equalsBytes(input, BLS_G1_INFINITY_POINT_BYTES) === true) {
return G1_ZERO
}

Expand Down Expand Up @@ -96,7 +87,7 @@ function BLS12_381_FromG1Point(input: AffinePoint<bigint>): Uint8Array {
* @returns Noble G2 point
*/
function BLS12_381_ToG2Point(input: Uint8Array, verifyOrder = true) {
if (equalsBytes(input, BLS_G2_INFINITY_POINT_BYTES)) {
if (equalsBytes(input, BLS_G2_INFINITY_POINT_BYTES) === true) {
return G2_ZERO
}

Expand Down
Loading

0 comments on commit e4d55d3

Please sign in to comment.