Skip to content

Commit 1f8f8c7

Browse files
monorepo: upgrade ethereum-crypography and reduce reliance on it (#4030)
* monorepo: migrate keccak256 to noble hashes instead of ethereum-cryptography * monorepo: refactor sha256 usage * monorepo: refactor more ethereum-crypto usage * monorepo: upgrade noble packages and ethereum-crypto * chore: remove .js suffix from noble imports * chore: fix mpt blake2b issue * fix: docker build * chore: attempt to fix docker * chore: alternative ripemd160 import --------- Co-authored-by: acolytec3 <[email protected]>
1 parent f10cb80 commit 1f8f8c7

File tree

95 files changed

+530
-264
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

95 files changed

+530
-264
lines changed

package-lock.json

Lines changed: 294 additions & 38 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/binarytree/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@
5858
"@ethereumjs/util": "^10.0.0-rc.1",
5959
"@noble/hashes": "^1.7.2",
6060
"debug": "^4.4.0",
61-
"ethereum-cryptography": "^3.1.0",
6261
"lru-cache": "11.0.2"
6362
},
6463
"engines": {

packages/block/examples/clrequests.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Common, Hardfork, Mainnet } from '@ethereumjs/common'
22
import { CLRequestType, bytesToHex, createCLRequest, hexToBytes } from '@ethereumjs/util'
3-
import { sha256 } from 'ethereum-cryptography/sha256.js'
3+
import { sha256 } from '@noble/hashes/sha2'
44

55
import { createBlock, genRequestsRoot } from '../src'
66

packages/block/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@
5555
"@ethereumjs/mpt": "^10.0.0-rc.1",
5656
"@ethereumjs/tx": "^10.0.0-rc.1",
5757
"@ethereumjs/util": "^10.0.0-rc.1",
58-
"ethereum-cryptography": "^3.1.0"
58+
"@noble/hashes": "1.8.0",
59+
"@noble/curves": "1.9.0"
5960
},
6061
"devDependencies": {
6162
"@ethereumjs/testdata": "1.0.0",

packages/block/src/block/block.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import {
1010
bytesToHex,
1111
equalsBytes,
1212
} from '@ethereumjs/util'
13-
import { keccak256 } from 'ethereum-cryptography/keccak.js'
14-
import { sha256 } from 'ethereum-cryptography/sha256.js'
13+
import { sha256 } from '@noble/hashes/sha2'
14+
import { keccak_256 } from '@noble/hashes/sha3'
1515

1616
import type { Common } from '@ethereumjs/common'
1717
import type { FeeMarket1559Tx, LegacyTx, TypedTransaction } from '@ethereumjs/tx'
@@ -90,7 +90,7 @@ export class Block {
9090
) {
9191
this.header = header ?? new BlockHeader({}, opts)
9292
this.common = this.header.common
93-
this.keccakFunction = this.common.customCrypto.keccak256 ?? keccak256
93+
this.keccakFunction = this.common.customCrypto.keccak256 ?? keccak_256
9494
this.sha256Function = this.common.customCrypto.sha256 ?? sha256
9595

9696
this.transactions = transactions

packages/block/src/consensus/clique.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
equalsBytes,
1616
setLengthLeft,
1717
} from '@ethereumjs/util'
18-
import { secp256k1 } from 'ethereum-cryptography/secp256k1.js'
18+
import { secp256k1 } from '@noble/curves/secp256k1'
1919

2020
import type { CliqueConfig } from '@ethereumjs/common'
2121
import type { BlockHeader } from '../index.ts'

packages/block/src/header/header.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import {
2020
hexToBytes,
2121
toType,
2222
} from '@ethereumjs/util'
23-
import { keccak256 } from 'ethereum-cryptography/keccak.js'
23+
import { keccak_256 } from '@noble/hashes/sha3'
2424

2525
import {
2626
CLIQUE_EXTRA_SEAL,
@@ -102,7 +102,7 @@ export class BlockHeader {
102102
}
103103
this.common.updateParams(opts.params ?? paramsBlock)
104104

105-
this.keccakFunction = this.common.customCrypto.keccak256 ?? keccak256
105+
this.keccakFunction = this.common.customCrypto.keccak256 ?? keccak_256
106106

107107
const skipValidateConsensusFormat = opts.skipConsensusFormatValidation ?? false
108108

packages/block/src/helpers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ export function genRequestsRoot(
189189
}
190190

191191
// def compute_requests_hash(list):
192-
// return keccak256(rlp.encode([rlp.encode(req) for req in list]))
192+
// return keccak_256(rlp.encode([rlp.encode(req) for req in list]))
193193

194194
let flatRequests = new Uint8Array()
195195
for (const req of requests) {

packages/block/test/clrequests.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Common, Hardfork, Mainnet } from '@ethereumjs/common'
22
import { CLRequestType, createCLRequest, equalsBytes, hexToBytes } from '@ethereumjs/util'
3-
import { sha256 } from 'ethereum-cryptography/sha256.js'
3+
import { sha256 } from '@noble/hashes/sha2'
44
import { assert, describe, it } from 'vitest'
55

66
import { createBlock, genRequestsRoot } from '../src/index.ts'

packages/blockchain/test/blockValidation.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Common, ConsensusAlgorithm, Hardfork, Mainnet } from '@ethereumjs/commo
33
import { Ethash } from '@ethereumjs/ethash'
44
import { RLP } from '@ethereumjs/rlp'
55
import { bytesToHex } from '@ethereumjs/util'
6-
import { keccak256 } from 'ethereum-cryptography/keccak.js'
6+
import { keccak_256 } from '@noble/hashes/sha3'
77
import { assert, describe, expect, it } from 'vitest'
88

99
import { EthashConsensus, createBlockchain } from '../src/index.ts'
@@ -304,7 +304,7 @@ describe('[Blockchain]: Block validation tests', () => {
304304
common: new Common({ chain: Mainnet, hardfork: Hardfork.Berlin }),
305305
})
306306

307-
forkBlockHeaderData.uncleHash = bytesToHex(keccak256(RLP.encode([uncleHeader.raw()])))
307+
forkBlockHeaderData.uncleHash = bytesToHex(keccak_256(RLP.encode([uncleHeader.raw()])))
308308

309309
const forkBlock_ValidCommon = createBlock(
310310
{

0 commit comments

Comments
 (0)