Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
87 commits
Select commit Hold shift + click to select a range
75b4e8b
V7 update to master 1 (#2593)
acolytec3 Mar 20, 2023
63be503
First pass - most util changes
acolytec3 Mar 2, 2023
0f35c2f
Fix most account stuff
acolytec3 Mar 2, 2023
37a1820
Fix account test
acolytec3 Mar 3, 2023
80a23e8
Many byte fixes
acolytec3 Mar 3, 2023
e122daa
util: fix constants tests
acolytec3 Mar 3, 2023
735fcb6
remaining fixes
acolytec3 Mar 3, 2023
c67f079
Turn off ci jobs
acolytec3 Mar 3, 2023
94f4d71
monorepo: bigIntToUnpaddedBuffer -> bigIntToUnpaddedBytes
gabrocheleau Mar 5, 2023
816d956
util: update description of bytes exporT
gabrocheleau Mar 5, 2023
0b1e650
util: remove unused import
gabrocheleau Mar 5, 2023
375d032
common: use bytesToHex helper instead of toString('hex')
gabrocheleau Mar 5, 2023
03118c0
trie: refactor non-test files to Uint8Array
gabrocheleau Mar 5, 2023
8c96c6d
util: add binary string utils
gabrocheleau Mar 5, 2023
66eafa5
util: remove extra Uint8Array.from
gabrocheleau Mar 5, 2023
b605e44
util: remove arrToBufArray util
gabrocheleau Mar 5, 2023
1578e44
trie: adjust tests and fix outstanding issues
gabrocheleau Mar 6, 2023
726f9a2
util: remove binarystring utils and add compareBytes and randomBytes …
gabrocheleau Mar 6, 2023
aaf69f0
common: refactor common with Uint8Array
gabrocheleau Mar 6, 2023
556a5a5
util: accept 0x-prefixed and non-prefixed hex strings in toBytes
gabrocheleau Mar 6, 2023
7e207d1
tx: refactor Buffer -> Uint8Array
gabrocheleau Mar 6, 2023
09abad8
tx: remove unused import
gabrocheleau Mar 6, 2023
e173ed9
util: revert toBytes update
gabrocheleau Mar 6, 2023
6ce69ad
block: refactor Buffer -> uint8array
gabrocheleau Mar 6, 2023
731d369
block: adjust import
gabrocheleau Mar 6, 2023
0dd7a5b
trie: refactor remaining buffer instances
gabrocheleau Mar 8, 2023
7ee110e
move devp2p to uint8Array
acolytec3 Mar 7, 2023
7ef3ddc
statemanager: refactor buffer -> uint8array
gabrocheleau Mar 8, 2023
85d6213
util: simplify zeros
acolytec3 Mar 8, 2023
d4c1ef8
util: add concatBytesUnsafe
acolytec3 Mar 8, 2023
29bcb68
ethash: partial migration
acolytec3 Mar 8, 2023
6bd1aef
ethash: update examples
acolytec3 Mar 8, 2023
7c05bb6
ethash: wip fixes
acolytec3 Mar 9, 2023
817245f
ethash: more WIP
acolytec3 Mar 9, 2023
e733ad5
ethash: ensure fnv input is read from mix, not mixView
jochem-brouwer Mar 9, 2023
fb01eb5
blockchain: migrate to uint8array
acolytec3 Mar 9, 2023
02221ad
ethash: renable all tests
acolytec3 Mar 9, 2023
122cd69
ethash: fix bytesReverse
acolytec3 Mar 9, 2023
915ee29
Fix miner tests
acolytec3 Mar 9, 2023
34fc0ba
many hexToBytes moves
acolytec3 Mar 9, 2023
264425c
most of evm/vm moves
acolytec3 Mar 10, 2023
ff915e1
evm: Fix all tests
acolytec3 Mar 10, 2023
eb29f0b
vm: more fixes
acolytec3 Mar 10, 2023
429988e
More fixes
acolytec3 Mar 11, 2023
3f60a1a
vm: fix receipts encoding
acolytec3 Mar 11, 2023
293e741
vm: fix tester
acolytec3 Mar 11, 2023
b9c69d5
client: refactor buffer to uint8array
gabrocheleau Mar 11, 2023
50288fd
client: additional uint8 adjustments
gabrocheleau Mar 11, 2023
31a4bbb
client: fix most tests
gabrocheleau Mar 13, 2023
a529561
fix remaining client unit tests
acolytec3 Mar 13, 2023
a93ebcd
reactivate most CI
acolytec3 Mar 13, 2023
ae0e933
client: fix les test/protocol
acolytec3 Mar 13, 2023
5e36b25
turn client CI on
acolytec3 Mar 13, 2023
a6e04d4
util: fix name typo
acolytec3 Mar 13, 2023
f369283
lint
acolytec3 Mar 13, 2023
523ece3
Fix withdrawals
acolytec3 Mar 13, 2023
5a995be
remove buffarraytoarr
acolytec3 Mar 13, 2023
87249b6
Remove bufArrtoArr references
acolytec3 Mar 13, 2023
5176d41
Lint
acolytec3 Mar 13, 2023
8532dff
fix examples
acolytec3 Mar 13, 2023
de03bb3
Fix difficulty test
acolytec3 Mar 13, 2023
7c794cf
lint
acolytec3 Mar 14, 2023
5905c64
block: update randomBytes import
acolytec3 Mar 15, 2023
9f8b13f
replace randombytes import
acolytec3 Mar 15, 2023
f881400
client: fix sim test util
acolytec3 Mar 15, 2023
91879e6
vm: fix example
acolytec3 Mar 15, 2023
e906878
devp2p: update snappy typing and fix tests
acolytec3 Mar 15, 2023
56c2123
Fix tests
acolytec3 Mar 15, 2023
60f3974
Remove additional buffer references
acolytec3 Mar 15, 2023
d6bf2a6
rustbn fixes
acolytec3 Mar 16, 2023
5a33359
add 0x prefix to precompile address
acolytec3 Mar 16, 2023
603b7ed
Remove `node-ip` dependency and buffer references in devp2p
acolytec3 Mar 16, 2023
7c0700d
Switch slice to subarray
acolytec3 Mar 20, 2023
78f514c
evm: fix blake2f
jochem-brouwer Mar 20, 2023
beab716
Merge fixes
acolytec3 Mar 20, 2023
5c80a8c
more merge commit fixes
acolytec3 Mar 20, 2023
6c7ce68
more test fixes
acolytec3 Mar 20, 2023
54439f7
Address all the feedback
acolytec3 Mar 23, 2023
b2038a2
fix dns test
acolytec3 Mar 23, 2023
f00c834
Update packages/util/src/bytes.ts
acolytec3 Mar 24, 2023
5ef4ee7
Fix return type for baToJSON
acolytec3 Mar 24, 2023
20920e0
util: instantiate hexByByte array
jochem-brouwer Mar 26, 2023
90019e8
Remove baToJson
acolytec3 Mar 27, 2023
3f7fc75
rebase fixes
acolytec3 Mar 27, 2023
0c8308b
Fix event typing
acolytec3 Mar 27, 2023
1df3a55
Revert outdated initcode changes
acolytec3 Mar 27, 2023
6e1a80b
lint
acolytec3 Mar 27, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
48 changes: 16 additions & 32 deletions package-lock.json

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

59 changes: 29 additions & 30 deletions packages/block/src/block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ import { BlobEIP4844Transaction, Capability, TransactionFactory } from '@ethereu
import {
KECCAK256_RLP,
Withdrawal,
arrToBufArr,
bigIntToHex,
bufArrToArr,
bufferToHex,
bytesToHex,
equalsBytes,
intToHex,
isHexPrefixed,
ssz,
Expand All @@ -20,15 +19,15 @@ import { blockFromRpc } from './from-rpc'
import { BlockHeader } from './header'
import { getDataGasPrice } from './helpers'

import type { BlockBuffer, BlockData, BlockOptions, JsonBlock, JsonRpcBlock } from './types'
import type { BlockBytes, BlockData, BlockOptions, JsonBlock, JsonRpcBlock } from './types'
import type { Common } from '@ethereumjs/common'
import type {
FeeMarketEIP1559Transaction,
Transaction,
TxOptions,
TypedTransaction,
} from '@ethereumjs/tx'
import type { WithdrawalBuffer } from '@ethereumjs/util'
import type { WithdrawalBytes } from '@ethereumjs/util'

/**
* An object that represents the block.
Expand All @@ -49,7 +48,7 @@ export class Block {
public static async genWithdrawalsTrieRoot(wts: Withdrawal[], emptyTrie?: Trie) {
const trie = emptyTrie ?? new Trie()
for (const [i, wt] of wts.entries()) {
await trie.put(Buffer.from(RLP.encode(i)), arrToBufArr(RLP.encode(wt.raw())))
await trie.put(RLP.encode(i), RLP.encode(wt.raw()))
}
return trie.root()
}
Expand All @@ -70,7 +69,7 @@ export class Block {
public static async genTransactionsTrieRoot(txs: TypedTransaction[], emptyTrie?: Trie) {
const trie = emptyTrie ?? new Trie()
for (const [i, tx] of txs.entries()) {
await trie.put(Buffer.from(RLP.encode(i)), tx.serialize())
await trie.put(RLP.encode(i), tx.serialize())
}
return trie.root()
}
Expand Down Expand Up @@ -133,8 +132,8 @@ export class Block {
* @param serialized
* @param opts
*/
public static fromRLPSerializedBlock(serialized: Buffer, opts?: BlockOptions) {
const values = arrToBufArr(RLP.decode(Uint8Array.from(serialized))) as BlockBuffer
public static fromRLPSerializedBlock(serialized: Uint8Array, opts?: BlockOptions) {
const values = RLP.decode(Uint8Array.from(serialized)) as BlockBytes

if (!Array.isArray(values)) {
throw new Error('Invalid serialized block input. Must be array')
Expand All @@ -144,16 +143,16 @@ export class Block {
}

/**
* Static constructor to create a block from an array of Buffer values
* Static constructor to create a block from an array of Bytes values
*
* @param values
* @param opts
*/
public static fromValuesArray(values: BlockBuffer, opts?: BlockOptions) {
public static fromValuesArray(values: BlockBytes, opts?: BlockOptions) {
if (values.length > 4) {
throw new Error('invalid block. More values than expected were received')
}
const [headerData, txsData, uhsData, withdrawalsBuffer] = values
const [headerData, txsData, uhsData, withdrawalBytes] = values

const header = BlockHeader.fromValuesArray(headerData, opts)

Expand Down Expand Up @@ -189,7 +188,7 @@ export class Block {
uncleHeaders.push(BlockHeader.fromValuesArray(uncleHeaderData, uncleOpts))
}

const withdrawals = (withdrawalsBuffer as WithdrawalBuffer[])
const withdrawals = (withdrawalBytes as WithdrawalBytes[])
?.map(([index, validatorIndex, address, amount]) => ({
index,
validatorIndex,
Expand Down Expand Up @@ -302,27 +301,27 @@ export class Block {
}

/**
* Returns a Buffer Array of the raw Buffers of this block, in order.
* Returns a Array of the raw Bytes Arays of this block, in order.
*/
raw(): BlockBuffer {
const bufferArray = <BlockBuffer>[
raw(): BlockBytes {
const bytesArray = <BlockBytes>[
this.header.raw(),
this.transactions.map((tx) =>
tx.supports(Capability.EIP2718TypedTransaction) ? tx.serialize() : tx.raw()
) as Buffer[],
) as Uint8Array[],
this.uncleHeaders.map((uh) => uh.raw()),
]
const withdrawalsRaw = this.withdrawals?.map((wt) => wt.raw())
if (withdrawalsRaw) {
bufferArray.push(withdrawalsRaw)
bytesArray.push(withdrawalsRaw)
}
return bufferArray
return bytesArray
}

/**
* Returns the hash of the block.
*/
hash(): Buffer {
hash(): Uint8Array {
return this.header.hash()
}

Expand All @@ -336,8 +335,8 @@ export class Block {
/**
* Returns the rlp encoding of the block.
*/
serialize(): Buffer {
return Buffer.from(RLP.encode(bufArrToArr(this.raw())))
serialize(): Uint8Array {
return RLP.encode(this.raw())
}

/**
Expand All @@ -355,14 +354,14 @@ export class Block {
async validateTransactionsTrie(): Promise<boolean> {
let result
if (this.transactions.length === 0) {
result = this.header.transactionsTrie.equals(KECCAK256_RLP)
result = equalsBytes(this.header.transactionsTrie, KECCAK256_RLP)
return result
}

if (this.txTrie.root().equals(KECCAK256_RLP)) {
if (equalsBytes(this.txTrie.root(), KECCAK256_RLP)) {
await this.genTxTrie()
}
result = this.txTrie.root().equals(this.header.transactionsTrie)
result = equalsBytes(this.txTrie.root(), this.header.transactionsTrie)
return result
}

Expand Down Expand Up @@ -477,8 +476,8 @@ export class Block {
*/
validateUnclesHash(): boolean {
const uncles = this.uncleHeaders.map((uh) => uh.raw())
const raw = RLP.encode(bufArrToArr(uncles))
return Buffer.from(keccak256(raw)).equals(this.header.uncleHash)
const raw = RLP.encode(uncles)
return equalsBytes(keccak256(raw), this.header.uncleHash)
}

/**
Expand All @@ -489,7 +488,7 @@ export class Block {
throw new Error('EIP 4895 is not activated')
}
const withdrawalsRoot = await Block.genWithdrawalsTrieRoot(this.withdrawals!)
return withdrawalsRoot.equals(this.header.withdrawalsRoot!)
return equalsBytes(withdrawalsRoot, this.header.withdrawalsRoot!)
}

/**
Expand All @@ -513,7 +512,7 @@ export class Block {
}

// Header does not count an uncle twice.
const uncleHashes = this.uncleHeaders.map((header) => header.hash().toString('hex'))
const uncleHashes = this.uncleHeaders.map((header) => bytesToHex(header.hash()))
if (!(new Set(uncleHashes).size === uncleHashes.length)) {
const msg = this._errorMsg('duplicate uncles')
throw new Error(msg)
Expand Down Expand Up @@ -562,7 +561,7 @@ export class Block {
public errorStr() {
let hash = ''
try {
hash = bufferToHex(this.hash())
hash = bytesToHex(this.hash())
} catch (e: any) {
hash = 'error'
}
Expand Down
4 changes: 2 additions & 2 deletions packages/block/src/from-rpc.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { TransactionFactory } from '@ethereumjs/tx'
import { TypeOutput, setLengthLeft, toBuffer, toType } from '@ethereumjs/util'
import { TypeOutput, setLengthLeft, toBytes, toType } from '@ethereumjs/util'

import { blockHeaderFromRpc } from './header-from-rpc'

Expand All @@ -21,7 +21,7 @@ function normalizeTxParams(_txParams: any) {
// strict byte length checking
txParams.to =
txParams.to !== null && txParams.to !== undefined
? setLengthLeft(toBuffer(txParams.to), 20)
? setLengthLeft(toBytes(txParams.to), 20)
: null

txParams.v = toType(txParams.v, TypeOutput.BigInt)
Expand Down
Loading