Skip to content

Commit

Permalink
common: ensure that EIPs enforce required EIPs are active
Browse files Browse the repository at this point in the history
  • Loading branch information
jochem-brouwer committed Jan 23, 2021
1 parent d12ad24 commit f0e4918
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/common/src/eips/2930.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"d": "Gas cost per storage key in an Access List transaction"
}
},
"requiredEIPs": [2718, 2929],
"vm": {},
"pow": {}
}
Expand Down
8 changes: 8 additions & 0 deletions packages/common/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,14 @@ export default class Common {
`${eip} cannot be activated on hardfork ${this.hardfork()}, minimumHardfork: ${minHF}`
)
}
if (EIPs[eip].requiredEIPs) {
// eslint-disable-next-line prettier/prettier
(<number[]>EIPs[eip].requiredEIPs).forEach((elem: number) => {
if (!eips.includes(elem)) {
throw new Error(`${eip} requires EIP ${elem}, but is not included in the EIP list`)
}
})
}
}
this._eips = eips
}
Expand Down
21 changes: 21 additions & 0 deletions packages/common/tests/eips.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,25 @@ tape('[Common]: Initialization / Chain params', function (t: tape.Test) {

st.end()
})

t.test(
'Should throw when trying to initialize with an EIP which requires certain EIPs, but which are not included on the EIP list',
function (st: tape.Test) {
const eips = [2930]
const msg =
'should throw when initializing with an EIP, which does not have required EIPs on the EIP list'
const f = () => {
new Common({ chain: 'mainnet', eips, hardfork: 'berlin' })
}
st.throws(f, msg)
st.end()
}
)

t.test('Should not throw when initializing with a valid EIP list', function (st: tape.Test) {
const eips = [2718, 2929, 2930]
new Common({ chain: 'mainnet', eips, hardfork: 'berlin' })
st.pass('initialized correctly')
st.end()
})
})

0 comments on commit f0e4918

Please sign in to comment.