Skip to content

Commit

Permalink
upgrade ethereumjs-util to v7.0.8 and use new Address.equals(address)…
Browse files Browse the repository at this point in the history
… method
  • Loading branch information
ryanio committed Feb 4, 2021
1 parent 11689d0 commit 9db72c2
Show file tree
Hide file tree
Showing 17 changed files with 1,550 additions and 11,830 deletions.
13,292 changes: 1,515 additions & 11,777 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/block/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"@ethereumjs/trie": "^4.0.0",
"@ethereumjs/tx": "^3.0.0",
"@types/bn.js": "^4.11.6",
"ethereumjs-util": "^7.0.7"
"ethereumjs-util": "^7.0.8"
},
"devDependencies": {
"@ethereumjs/config-coverage": "^2.0.0",
Expand Down
8 changes: 3 additions & 5 deletions packages/block/src/header.ts
Original file line number Diff line number Diff line change
Expand Up @@ -396,9 +396,7 @@ export class BlockHeader {
// abort if signers are unavailable
return true
}
const signerIndex = signers.findIndex((address: Address) =>
address.toBuffer().equals(this.cliqueSigner().toBuffer())
)
const signerIndex = signers.findIndex((address: Address) => address.equals(this.cliqueSigner()))
const inTurn = this.number.modn(signers.length) === signerIndex
if (
(inTurn && this.difficulty.eq(CLIQUE_DIFF_INTURN)) ||
Expand Down Expand Up @@ -673,9 +671,9 @@ export class BlockHeader {
*/
cliqueVerifySignature(signerList: Address[]): boolean {
this._requireClique('cliqueVerifySignature')
const signerAddress = this.cliqueSigner().toBuffer()
const signerAddress = this.cliqueSigner()
const signerFound = signerList.find((signer) => {
return signer.toBuffer().equals(signerAddress)
return signer.equals(signerAddress)
})
return !!signerFound
}
Expand Down
5 changes: 1 addition & 4 deletions packages/block/test/clique.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,7 @@ tape('[Header]: Clique PoA Functionality', function (t) {

st.equal(header.extraData.length, 97)
st.ok(header.cliqueVerifySignature([A.address]), 'should verify signature')
st.ok(
header.cliqueSigner().toBuffer().equals(A.address.toBuffer()),
'should recover the correct signer address'
)
st.ok(header.cliqueSigner().equals(A.address), 'should recover the correct signer address')

st.end()
})
Expand Down
2 changes: 1 addition & 1 deletion packages/block/test/header.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ tape('[Block]: Header functions', function (t) {
function compareDefaultHeader(st: tape.Test, header: BlockHeader) {
st.ok(header.parentHash.equals(zeros(32)))
st.ok(header.uncleHash.equals(KECCAK256_RLP_ARRAY))
st.ok(header.coinbase.buf.equals(Address.zero().buf))
st.ok(header.coinbase.equals(Address.zero()))
st.ok(header.stateRoot.equals(zeros(32)))
st.ok(header.transactionsTrie.equals(KECCAK256_RLP))
st.ok(header.receiptTrie.equals(KECCAK256_RLP))
Expand Down
2 changes: 1 addition & 1 deletion packages/blockchain/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"@ethereumjs/block": "^3.0.0",
"@ethereumjs/common": "^2.0.0",
"@ethereumjs/ethash": "^1.0.0",
"ethereumjs-util": "^7.0.7",
"ethereumjs-util": "^7.0.8",
"level-mem": "^5.0.1",
"lru-cache": "^5.1.1",
"rlp": "^2.2.3",
Expand Down
25 changes: 10 additions & 15 deletions packages/blockchain/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -431,8 +431,7 @@ export default class Blockchain implements BlockchainInterface {
let signers = this._cliqueLatestBlockSigners
signers = signers.slice(signers.length < limit ? 0 : 1)
signers.push([header.number, header.cliqueSigner()])
const seen = signers.filter((s) => s[1].toBuffer().equals(header.cliqueSigner().toBuffer()))
.length
const seen = signers.filter((s) => s[1].equals(header.cliqueSigner())).length
return seen > 1
}

Expand Down Expand Up @@ -502,9 +501,7 @@ export default class Blockchain implements BlockchainInterface {

const alreadyVoted = this._cliqueLatestVotes.find((vote) => {
return (
vote[1][0].toBuffer().equals(signer.toBuffer()) &&
vote[1][1].toBuffer().equals(beneficiary.toBuffer()) &&
vote[1][2].equals(nonce)
vote[1][0].equals(signer) && vote[1][1].equals(beneficiary) && vote[1][2].equals(nonce)
)
})
? true
Expand All @@ -519,8 +516,8 @@ export default class Blockchain implements BlockchainInterface {
this._cliqueLatestVotes = this._cliqueLatestVotes.filter(
(vote) =>
!(
vote[1][0].toBuffer().equals(signer.toBuffer()) &&
vote[1][1].toBuffer().equals(beneficiary.toBuffer()) &&
vote[1][0].equals(signer) &&
vote[1][1].equals(beneficiary) &&
vote[1][2].equals(oppositeNonce)
)
)
Expand All @@ -534,13 +531,13 @@ export default class Blockchain implements BlockchainInterface {
const beneficiaryVotesAuth = this._cliqueLatestVotes.filter(
(vote) =>
vote[0].gte(lastEpochBlockNumber) &&
vote[1][1].toBuffer().equals(beneficiary.toBuffer()) &&
vote[1][1].equals(beneficiary) &&
vote[1][2].equals(CLIQUE_NONCE_AUTH)
)
const beneficiaryVotesDrop = this._cliqueLatestVotes.filter(
(vote) =>
vote[0].gte(lastEpochBlockNumber) &&
vote[1][1].toBuffer().equals(beneficiary.toBuffer()) &&
vote[1][1].equals(beneficiary) &&
vote[1][2].equals(CLIQUE_NONCE_DROP)
)
const limit = this.cliqueSignerLimit()
Expand All @@ -555,16 +552,14 @@ export default class Blockchain implements BlockchainInterface {
activeSigners.push(beneficiary)
// Discard votes for added signer
this._cliqueLatestVotes = this._cliqueLatestVotes.filter(
(vote) => !vote[1][1].toBuffer().equals(beneficiary.toBuffer())
(vote) => !vote[1][1].equals(beneficiary)
)
} else {
// Drop signer
activeSigners = activeSigners.filter(
(signer) => !signer.toBuffer().equals(beneficiary.toBuffer())
)
activeSigners = activeSigners.filter((signer) => !signer.equals(beneficiary))
// Discard votes from removed signer
this._cliqueLatestVotes = this._cliqueLatestVotes.filter(
(vote) => !vote[1][0].toBuffer().equals(beneficiary.toBuffer())
(vote) => !vote[1][0].equals(beneficiary)
)
}
const newSignerState: CliqueSignerState = [header.number, activeSigners]
Expand Down Expand Up @@ -892,7 +887,7 @@ export default class Blockchain implements BlockchainInterface {
const checkpointSigners = header.cliqueEpochTransitionSigners()
const activeSigners = this.cliqueActiveSigners()
for (const [i, cSigner] of checkpointSigners.entries()) {
if (!activeSigners[i] || !activeSigners[i].toBuffer().equals(cSigner.toBuffer())) {
if (!activeSigners[i] || !activeSigners[i].equals(cSigner)) {
throw new Error(
`checkpoint signer not found in active signers list at index ${i}: ${cSigner.toString()}`
)
Expand Down
4 changes: 1 addition & 3 deletions packages/blockchain/test/clique.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,7 @@ tape('Clique: Initialization', (t) => {

// calculate difficulty
const signers = blockchain.cliqueActiveSigners()
const signerIndex = signers.findIndex((address: Address) =>
address.toBuffer().equals(signer.address.toBuffer())
)
const signerIndex = signers.findIndex((address: Address) => address.equals(signer.address))
const inTurn = number % signers.length === signerIndex
blockData.header.difficulty = inTurn ? new BN(2) : new BN(1)

Expand Down
18 changes: 6 additions & 12 deletions packages/blockchain/test/reorg.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,7 @@ tape('reorg tests', (t) => {

let signerStates = (blockchain as any)._cliqueLatestSignerStates
t.ok(
!signerStates.find(
(s: any) => s[0].eqn(2) && s[1][1].toBuffer().equals(beneficiary1.toBuffer())
),
!signerStates.find((s: any) => s[0].eqn(2) && s[1][1].equals(beneficiary1)),
'should not find reorged signer state'
)

Expand All @@ -188,8 +186,8 @@ tape('reorg tests', (t) => {
!signerVotes.find(
(v: any) =>
v[0].eqn(2) &&
v[1][0].toBuffer().equals(block1_low.header.cliqueSigner().toBuffer()) &&
v[1][1].toBuffer().equals(beneficiary1.toBuffer()) &&
v[1][0].equals(block1_low.header.cliqueSigner()) &&
v[1][1].equals(beneficiary1) &&
v[1][2].equals(CLIQUE_NONCE_AUTH)
),
'should not find reorged clique vote'
Expand All @@ -198,17 +196,14 @@ tape('reorg tests', (t) => {
let blockSigners = (blockchain as any)._cliqueLatestBlockSigners
t.ok(
!blockSigners.find(
(s: any) =>
s[0].eqn(1) && s[1].toBuffer().equals(block1_low.header.cliqueSigner().toBuffer())
(s: any) => s[0].eqn(1) && s[1].equals(block1_low.header.cliqueSigner())
),
'should not find reorged block signer'
)

signerStates = (blockchain as any)._cliqueLatestSignerStates
t.ok(
!!signerStates.find(
(s: any) => s[0].eqn(2) && s[1][1].toBuffer().equals(beneficiary2.toBuffer())
),
!!signerStates.find((s: any) => s[0].eqn(2) && s[1][1].equals(beneficiary2)),
'should find reorged signer state'
)

Expand All @@ -218,8 +213,7 @@ tape('reorg tests', (t) => {
blockSigners = (blockchain as any)._cliqueLatestBlockSigners
t.ok(
!!blockSigners.find(
(s: any) =>
s[0].eqn(2) && s[1].toBuffer().equals(block2_high.header.cliqueSigner().toBuffer())
(s: any) => s[0].eqn(2) && s[1].equals(block2_high.header.cliqueSigner())
),
'should find reorged block signer'
)
Expand Down
2 changes: 1 addition & 1 deletion packages/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"@ethereumjs/trie": "^4.0.0",
"@ethereumjs/vm": "^5.0.0",
"chalk": "^2.4.2",
"ethereumjs-util": "^7.0.7",
"ethereumjs-util": "^7.0.8",
"fs-extra": "^7.0.1",
"jayson": "^3.3.4",
"level": "^6.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/ethash/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"dependencies": {
"@types/levelup": "^4.3.0",
"buffer-xor": "^2.0.1",
"ethereumjs-util": "^7.0.7",
"ethereumjs-util": "^7.0.8",
"miller-rabin": "^4.0.0"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/trie/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"license": "MPL-2.0",
"dependencies": {
"@types/levelup": "^4.3.0",
"ethereumjs-util": "^7.0.7",
"ethereumjs-util": "^7.0.8",
"level-mem": "^5.0.1",
"level-ws": "^2.0.0",
"readable-stream": "^3.6.0",
Expand Down
5 changes: 3 additions & 2 deletions packages/tx/examples/custom-chain-tx.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { privateToAddress } from 'ethereumjs-util'
import { Address } from 'ethereumjs-util'
import Common from '@ethereumjs/common'
import { Transaction } from '../src'

Expand Down Expand Up @@ -38,8 +38,9 @@ const privateKey = Buffer.from(
)

const signedTx = tx.sign(privateKey)
const address = Address.fromPrivateKey(privateKey)

if (signedTx.validate() && signedTx.getSenderAddress().buf.equals(privateToAddress(privateKey))) {
if (signedTx.validate() && signedTx.getSenderAddress().equals(address)) {
console.log('Valid signature')
} else {
console.log('Invalid signature')
Expand Down
2 changes: 1 addition & 1 deletion packages/tx/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"license": "MPL-2.0",
"dependencies": {
"@ethereumjs/common": "^2.0.0",
"ethereumjs-util": "^7.0.7"
"ethereumjs-util": "^7.0.8"
},
"devDependencies": {
"@ethereumjs/config-coverage": "^2.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/vm/lib/evm/eei.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export default class EEI {
*/
async getExternalBalance(address: Address): Promise<BN> {
// shortcut if current account
if (address.buf.equals(this._env.address.buf)) {
if (address.equals(this._env.address)) {
return this._env.contract.balance
}

Expand Down
2 changes: 1 addition & 1 deletion packages/vm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"@ethereumjs/blockchain": "^5.0.0",
"@ethereumjs/common": "^2.0.0",
"@ethereumjs/tx": "^3.0.0",
"ethereumjs-util": "^7.0.7",
"ethereumjs-util": "^7.0.8",
"functional-red-black-tree": "^1.0.1",
"rustbn.js": "~0.2.0",
"util.promisify": "^1.0.1",
Expand Down
5 changes: 2 additions & 3 deletions packages/vm/tests/api/runCall.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,8 @@ tape('Constantinople: EIP-1014 CREATE2 creates the right contract address', asyn
// run the actual call
const res = await vm.runCall(runCallArgs)
// retrieve the return value and convert it to an address (remove the first 12 bytes from the 32-byte return value)
const executionReturnValue = res.execResult.returnValue.slice(12)
if (!expectedAddress.buf.equals(executionReturnValue)) {
console.log('not equal')
const executionReturnValue = new Address(res.execResult.returnValue.slice(12))
if (!expectedAddress.equals(executionReturnValue)) {
t.fail('contract address not equal')
}
}
Expand Down

0 comments on commit 9db72c2

Please sign in to comment.