-
Notifications
You must be signed in to change notification settings - Fork 778
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
VM: Replace BN.js with bigints, Util helpers #1671
Conversation
packages/util/src/constants.ts
Outdated
* 2^256 | ||
*/ | ||
export const TWO_POW256_BIGINT = | ||
BigInt(0x10000000000000000000000000000000000000000000000000000000000000000) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cool, could we just do 2n ** 256n
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, is this wise if this always have to be recalculated? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that's a good question, if the calculation is run every time the constant is imported or if it is calculated once on init of the package.
To test:
constants.js
const TWO_POW256_BIGINT_HEX =
BigInt(0x10000000000000000000000000000000000000000000000000000000000000000);
const TWO_POW256_BIGINT_EXP = 2n ** 256n;
exports = [TWO_POW256_BIGINT_HEX, TWO_POW256_BIGINT_EXP];
index.js
const Benchmark = require("benchmark");
const BN = require("bn.js");
const suite = new Benchmark.Suite();
suite
.add("bigint init with hex", function () {
const { TWO_POW256_BIGINT_HEX } = require("./constants");
if (100n > TWO_POW256_BIGINT_HEX) return true;
})
.add("bigint init with exp", function () {
const { TWO_POW256_BIGINT_EXP } = require("./constants");
if (100n > TWO_POW256_BIGINT_EXP) return true;
})
.on("cycle", function (event) {
console.log(String(event.target));
})
.on("complete", function () {
console.log("Fastest is " + this.filter("fastest").map("name"));
})
.run({ async: true });
On my Macbook Air (M1, 2020) my results are always about even:
bigint init with hex x 6,561,811 ops/sec ±0.37% (97 runs sampled)
bigint init with exp x 6,573,137 ops/sec ±0.10% (99 runs sampled)
Fastest is bigint init with exp,bigint init with hex
I'm not quite sure if this exactly replicates our util setup, but thought I'd try it.
Let's compare this to inline definitions and not importing (snippet):
const TWO_POW256_BIGINT_HEX =
BigInt(0x10000000000000000000000000000000000000000000000000000000000000000);
const TWO_POW256_BIGINT_EXP = 2n ** 256n;
suite
.add("bigint init with hex", function () {
if (100n > TWO_POW256_BIGINT_HEX) return true;
})
.add("bigint init with exp", function () {
if (100n > TWO_POW256_BIGINT_EXP) return true;
})
Much faster 😄
bigint init with hex x 110,702,702 ops/sec ±0.12% (101 runs sampled)
bigint init with exp x 110,732,705 ops/sec ±0.12% (94 runs sampled)
Fastest is bigint init with exp,bigint init with hex
One last comparison, with requiring but only once in the file header (snippet):
const { TWO_POW256_BIGINT_HEX, TWO_POW256_BIGINT_EXP } = require("./constants");
suite
.add("bigint init with hex", function () {
if (100n > TWO_POW256_BIGINT_HEX) return true;
})
.add("bigint init with exp", function () {
if (100n > TWO_POW256_BIGINT_EXP) return true;
})
Results:
bigint init with hex x 85,243,817 ops/sec ±0.41% (90 runs sampled)
bigint init with exp x 86,028,773 ops/sec ±0.19% (97 runs sampled)
Fastest is bigint init with exp
One thing that is definitely broken is the EXP function handler. It seems to work in most instances but in some cases it's producing values out of range. Since I don't really understand the math that bn.js uses to do exponentiation, I can't comment on how the bigint version is different or why it is producing incorrect results for some state tests like some of these |
I was curious about BigInt conversion performance with the varying ways to do it, so I put together a small benchmarking setup, my results in the first comment: https://gist.github.com/ryanio/89cc842a7573dd077cbb7cfa4469f8ec |
Some small stuff I noticed, which we should look at (will edit this if I find more)
|
Codecov Report
Flags with carried forward coverage won't be shown. Click here to find out more. |
1f404bb
to
c59480a
Compare
Okay, I think this bigint PR is now ready for review at long last. All the tests are passing (except Hardhat which isn't surprising). Question for the group, do you want me to figure out which values Hardhat is failing on (looks like there are VM bigints that it's trying to reference) and put a BN wrapper around them or do we want to review as is, potentially merge, and then continue on with a bigint conversion across the whole monorepo. |
it's okay if hardhat isn't passing on |
packages/vm/src/buildBlock.ts
Outdated
@@ -228,7 +227,7 @@ export class BlockBuilder { | |||
const transactionsTrie = await this.transactionsTrie() | |||
const receiptTrie = await this.receiptTrie() | |||
const logsBloom = this.logsBloom() | |||
const gasUsed = this.gasUsed | |||
const gasUsed = new BN(this.gasUsed.toString(10), 10) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would suggest leaving the default values out when unneeded, i.e.
const gasUsed = new BN(this.gasUsed.toString(10), 10) | |
const gasUsed = new BN(this.gasUsed.toString()) |
const totalGasUsed = initialGas.sub(currentGas) | ||
st.equal(true, totalGasUsed.eq(new BN(test.totalGasUsed).addn(21000))) // Add tx upfront cost. | ||
const totalGasUsed = initialGas - currentGas | ||
st.equal(true, totalGasUsed === BigInt(test.totalGasUsed) + 21000n) // Add tx upfront cost. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
st.equal(true, totalGasUsed === BigInt(test.totalGasUsed) + 21000n) // Add tx upfront cost. | |
st.ok(totalGasUsed === BigInt(test.totalGasUsed) + 21000n, 'totalGasUsed should be correct') // Add tx upfront cost. |
awesome, thanks for doing that! let's move the three functions you added to edit: I'm still seeing a handful of places where these new functions aren't used (big pr 😄) do you want me add a commit to convert more of them over, or point them out in review comments, or you got them? |
I'll take another skim through it. I was just searching with VS Code so probably missed a couple of spots. Will just go line by line. |
I'm not sure I follow the logic on this one. These three are type conversion utilities between non |
good point, sounds good! |
Yes, these conversion function like If you do please make sure to clearly document somewhere, otherwise this will likely be forgotten on the release notes at some point. |
Ok, since this got another review from Paul I will merge this in now, then the subsequent BigInt (and other) work can be done on top (please: do by rebase 🙂). Thanks again @acolytec3 for this great work here and @jochem-brouwer and @paulmillr for the assistance and guidance on some things. Really cool! 🎉 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
* Replace BN.js with bigints in VM * Fix byteLength computation in EXP handler * Fix toTwos helper * Compute TWO_POWE256 using math instead of hex * Update packages/util/src/constants.ts Co-authored-by: Ryan Ghods <[email protected]> * Remove unused variable * Fix exponent byte length calc * Fix exp overflow * Fix precompile bigint conversions * Fix more bigint conversions * Fix EXP opcode handler * Fix logic bug in signextend * vm/gas: fix EXTCODECOPY gas * vm/gas: fix sha256 gas * vm/gas: sha256 const -> let * vm: lint * vm/logic: fix sdiv/smod and fromTwos/toTwos * vm/logic: fix SIGNEXTEND * vm/logic: fix CALLDATALOAD padding * vm/logic: remove weird comment * Fix SAR opcode handler * Use bufferToBigInt in Push opcode handler * use bufferToBigInt everywhere * Fix missing bufferToBigInt import * Check for edge case in expmod * Ignore prettier * Update browser tsconfig to es2020 lib * Remove dup ES2020 targets * attempt to dedupe "target" and "lib" tsconfig values * Update karma config to target es2020 in parser * Various test fixes * Lint and BN fixes * Add bigint helpers to util * lint fixes * various bigint helper additions * Lint fixes * Fix bnToBigInt * Lint/test fixes * Switch Xn to BigInt(X) * lint * lint * More Xn to BigInt(X) moves Co-authored-by: Ryan Ghods <[email protected]> Co-authored-by: Jochem Brouwer <[email protected]> Co-authored-by: Jochem Brouwer <[email protected]>
* Replace BN.js with bigints in VM * Fix byteLength computation in EXP handler * Fix toTwos helper * Compute TWO_POWE256 using math instead of hex * Update packages/util/src/constants.ts Co-authored-by: Ryan Ghods <[email protected]> * Remove unused variable * Fix exponent byte length calc * Fix exp overflow * Fix precompile bigint conversions * Fix more bigint conversions * Fix EXP opcode handler * Fix logic bug in signextend * vm/gas: fix EXTCODECOPY gas * vm/gas: fix sha256 gas * vm/gas: sha256 const -> let * vm: lint * vm/logic: fix sdiv/smod and fromTwos/toTwos * vm/logic: fix SIGNEXTEND * vm/logic: fix CALLDATALOAD padding * vm/logic: remove weird comment * Fix SAR opcode handler * Use bufferToBigInt in Push opcode handler * use bufferToBigInt everywhere * Fix missing bufferToBigInt import * Check for edge case in expmod * Ignore prettier * Update browser tsconfig to es2020 lib * Remove dup ES2020 targets * attempt to dedupe "target" and "lib" tsconfig values * Update karma config to target es2020 in parser * Various test fixes * Lint and BN fixes * Add bigint helpers to util * lint fixes * various bigint helper additions * Lint fixes * Fix bnToBigInt * Lint/test fixes * Switch Xn to BigInt(X) * lint * lint * More Xn to BigInt(X) moves Co-authored-by: Ryan Ghods <[email protected]> Co-authored-by: Jochem Brouwer <[email protected]> Co-authored-by: Jochem Brouwer <[email protected]>
* Replace BN.js with bigints in VM * Fix byteLength computation in EXP handler * Fix toTwos helper * Compute TWO_POWE256 using math instead of hex * Update packages/util/src/constants.ts Co-authored-by: Ryan Ghods <[email protected]> * Remove unused variable * Fix exponent byte length calc * Fix exp overflow * Fix precompile bigint conversions * Fix more bigint conversions * Fix EXP opcode handler * Fix logic bug in signextend * vm/gas: fix EXTCODECOPY gas * vm/gas: fix sha256 gas * vm/gas: sha256 const -> let * vm: lint * vm/logic: fix sdiv/smod and fromTwos/toTwos * vm/logic: fix SIGNEXTEND * vm/logic: fix CALLDATALOAD padding * vm/logic: remove weird comment * Fix SAR opcode handler * Use bufferToBigInt in Push opcode handler * use bufferToBigInt everywhere * Fix missing bufferToBigInt import * Check for edge case in expmod * Ignore prettier * Update browser tsconfig to es2020 lib * Remove dup ES2020 targets * attempt to dedupe "target" and "lib" tsconfig values * Update karma config to target es2020 in parser * Various test fixes * Lint and BN fixes * Add bigint helpers to util * lint fixes * various bigint helper additions * Lint fixes * Fix bnToBigInt * Lint/test fixes * Switch Xn to BigInt(X) * lint * lint * More Xn to BigInt(X) moves Co-authored-by: Ryan Ghods <[email protected]> Co-authored-by: Jochem Brouwer <[email protected]> Co-authored-by: Jochem Brouwer <[email protected]>
* Replace BN.js with bigints in VM * Fix byteLength computation in EXP handler * Fix toTwos helper * Compute TWO_POWE256 using math instead of hex * Update packages/util/src/constants.ts Co-authored-by: Ryan Ghods <[email protected]> * Remove unused variable * Fix exponent byte length calc * Fix exp overflow * Fix precompile bigint conversions * Fix more bigint conversions * Fix EXP opcode handler * Fix logic bug in signextend * vm/gas: fix EXTCODECOPY gas * vm/gas: fix sha256 gas * vm/gas: sha256 const -> let * vm: lint * vm/logic: fix sdiv/smod and fromTwos/toTwos * vm/logic: fix SIGNEXTEND * vm/logic: fix CALLDATALOAD padding * vm/logic: remove weird comment * Fix SAR opcode handler * Use bufferToBigInt in Push opcode handler * use bufferToBigInt everywhere * Fix missing bufferToBigInt import * Check for edge case in expmod * Ignore prettier * Update browser tsconfig to es2020 lib * Remove dup ES2020 targets * attempt to dedupe "target" and "lib" tsconfig values * Update karma config to target es2020 in parser * Various test fixes * Lint and BN fixes * Add bigint helpers to util * lint fixes * various bigint helper additions * Lint fixes * Fix bnToBigInt * Lint/test fixes * Switch Xn to BigInt(X) * lint * lint * More Xn to BigInt(X) moves Co-authored-by: Ryan Ghods <[email protected]> Co-authored-by: Jochem Brouwer <[email protected]> Co-authored-by: Jochem Brouwer <[email protected]>
author acolytec3 <[email protected]> 1648139433 -0400 committer Gabriel Rocheleau <[email protected]> 1648407705 -0400 Revert process code changes Common: method deprecations (new) (#1698) * common: delete deprecated hardforkBlock method * common: adapt tests to use hardforkBlockBN * common: delete deprecated nextHardforkBlock method * common/tests: rename nextHardforkBlock() calls to nextHardforkBlockBN() * common: adapt tests to use BN.eqn(number) * common: delete deprecated networkId() method * common: delete tests for networkId() * common: delete deprecated chainId() method * common: delete tests for .chainId() * delete deprecated forCustomChain meethod * common: delete forCustomChain() test * blockchain: switch forCustomChain to Common.custom * client: switch fromCustomChain to Common.custom * tx: switch forCustomChain to Common.custom * VM: switch forCustomChain to Common.custom * common: internalize _getInitializedChains() method * common: delete deprecaed chains/index.ts file * client: switch to Common._getInitializedChains * common: remove genesisStates/index.ts * common: remove test for genesisStates Common: Rename *BN methods to non-BN names (#1709) * common: rename nextHardforkBlockBN() to nextHardforkBlock() * common/tests: rename nextHardforkBlockBN() to nextHardforkBlock() * client: rename common.nextHardforkBlockBN() to common.nextHardforkBlock() * devp2p: rename common.nextHardforkBlockBN() to common.nextHardforkBlock() * common: rename hardforkBlockBN() to hardforkBlock() * common/tests: rename common.hardforkBlockBN() to common.hardforkBlock() * block: rename common.hardforkBlockBN() to common.hardforkBlock() * client: rename common.hardforkBlockBN() to common.hardforkBlock() * blockchain: rename common.hardforkBlockBN() to common.hardforkBlock() * devp2p: rename common.hardforkBlockBN() to common.hardforkBlock() * vm: rename common.hardforkBlockBN() to common.hardforkBlock() * common: rename chainIdBN() to chainId() * common/tests: rename common.chainIdBN() to common.chainId() * client: rename common.chainIdBN() to common.chainId() * blockchain: rename common.chainIdBN() to common.chainId() * devp2p: rename common.chainIdBN() to common.chainId() * tx: rename common.chainIdBN() to common.chainId() * vm: rename common.chainIdBN() to common.chainId() * common: rename networkIdBN() to networkId() * common/test: rename common.networkIdBN() to common.networkId() * client: rename common.networkIdBN() to common.networkId() * block: rename common.networkIdBN() to common.networkId() VM: Replace BN.js with bigints, Util helpers (#1671) * Replace BN.js with bigints in VM * Fix byteLength computation in EXP handler * Fix toTwos helper * Compute TWO_POWE256 using math instead of hex * Update packages/util/src/constants.ts Co-authored-by: Ryan Ghods <[email protected]> * Remove unused variable * Fix exponent byte length calc * Fix exp overflow * Fix precompile bigint conversions * Fix more bigint conversions * Fix EXP opcode handler * Fix logic bug in signextend * vm/gas: fix EXTCODECOPY gas * vm/gas: fix sha256 gas * vm/gas: sha256 const -> let * vm: lint * vm/logic: fix sdiv/smod and fromTwos/toTwos * vm/logic: fix SIGNEXTEND * vm/logic: fix CALLDATALOAD padding * vm/logic: remove weird comment * Fix SAR opcode handler * Use bufferToBigInt in Push opcode handler * use bufferToBigInt everywhere * Fix missing bufferToBigInt import * Check for edge case in expmod * Ignore prettier * Update browser tsconfig to es2020 lib * Remove dup ES2020 targets * attempt to dedupe "target" and "lib" tsconfig values * Update karma config to target es2020 in parser * Various test fixes * Lint and BN fixes * Add bigint helpers to util * lint fixes * various bigint helper additions * Lint fixes * Fix bnToBigInt * Lint/test fixes * Switch Xn to BigInt(X) * lint * lint * More Xn to BigInt(X) moves Co-authored-by: Ryan Ghods <[email protected]> Co-authored-by: Jochem Brouwer <[email protected]> Co-authored-by: Jochem Brouwer <[email protected]> monorepo: develop rebase 2022-02-23 fixes Develop Rebase Fixes (2022-03-05) Convert bn to bigint (#1771) * util: use bigints. Expose new secp constants * common: use bigints * tx: use bigints * lint: fix util, tx, common * tx: fix isSigned * update comment block style to be picked up by vscode * remove doc typo (extra `) * tx: add isSigned() tests to base.spec.ts to iterate across txTypes * block: bn to bigint changes wip block: finish header changes block: test updates block: test fixes Partial difficulty fixes * block: fix homestead difficulty * block: fix >= Byzantium difficulty * BigInt conversion fixes * block: update st.ok to st.equals * Update readme to use bigints * ethash: bn to bigint * blockchain: wip bn to bigint changes * devp2p: bn to bigint * vm: wip remaining bn -> bigint * vm: more test fixes * fix runTx negative value args test, ensure balance does not go negative when using skipBalance * vm: lint:fix * re-add newline * Blockchain: small rebase fix * vm: Fix API tests * client: bn to bigint updates in source * client: various fixes * client: last fixes * client: integration test fixes * replace st.ok usage with st.equal * normalize st.equals to st.equal * update toType cases * nits, lint * fix vm benchmarks * client: fix fullEthereumService tests * touch ups, fix miner integration test * use prefix increment * client: fix full sync test * test fixes * Fix reorg logic bug * bnTo... function renaming and cleanup * Goodbye bn.js * reverse changelog changes * nits * remove more BN, more nits * turn off restrict-plus-operands and remove disable overrides (does not work properly) * more nits, update package-lock * fix build errors, re-add @types/bn.js for rlp v2 export to fix build (will be removed in subsequent PR for rlp) * replace miller-rabin (bn.js) with bigint-crypto-utils isProbablyPrime * more nits / fixes * Fix misplaced paren * Fix miner test * more nits * fix buffer to big int * set expectedTests back to >= comparison * last fixes * Removed re-introduced Common methods Co-authored-by: Paul Miller <[email protected]> Co-authored-by: Ryan Ghods <[email protected]> Co-authored-by: acolytec3 <[email protected]> Co-authored-by: Jochem Brouwer <[email protected]>
* Replace BN.js with bigints in VM * Fix byteLength computation in EXP handler * Fix toTwos helper * Compute TWO_POWE256 using math instead of hex * Update packages/util/src/constants.ts Co-authored-by: Ryan Ghods <[email protected]> * Remove unused variable * Fix exponent byte length calc * Fix exp overflow * Fix precompile bigint conversions * Fix more bigint conversions * Fix EXP opcode handler * Fix logic bug in signextend * vm/gas: fix EXTCODECOPY gas * vm/gas: fix sha256 gas * vm/gas: sha256 const -> let * vm: lint * vm/logic: fix sdiv/smod and fromTwos/toTwos * vm/logic: fix SIGNEXTEND * vm/logic: fix CALLDATALOAD padding * vm/logic: remove weird comment * Fix SAR opcode handler * Use bufferToBigInt in Push opcode handler * use bufferToBigInt everywhere * Fix missing bufferToBigInt import * Check for edge case in expmod * Ignore prettier * Update browser tsconfig to es2020 lib * Remove dup ES2020 targets * attempt to dedupe "target" and "lib" tsconfig values * Update karma config to target es2020 in parser * Various test fixes * Lint and BN fixes * Add bigint helpers to util * lint fixes * various bigint helper additions * Lint fixes * Fix bnToBigInt * Lint/test fixes * Switch Xn to BigInt(X) * lint * lint * More Xn to BigInt(X) moves Co-authored-by: Ryan Ghods <[email protected]> Co-authored-by: Jochem Brouwer <[email protected]> Co-authored-by: Jochem Brouwer <[email protected]>
* Replace BN.js with bigints in VM * Fix byteLength computation in EXP handler * Fix toTwos helper * Compute TWO_POWE256 using math instead of hex * Update packages/util/src/constants.ts Co-authored-by: Ryan Ghods <[email protected]> * Remove unused variable * Fix exponent byte length calc * Fix exp overflow * Fix precompile bigint conversions * Fix more bigint conversions * Fix EXP opcode handler * Fix logic bug in signextend * vm/gas: fix EXTCODECOPY gas * vm/gas: fix sha256 gas * vm/gas: sha256 const -> let * vm: lint * vm/logic: fix sdiv/smod and fromTwos/toTwos * vm/logic: fix SIGNEXTEND * vm/logic: fix CALLDATALOAD padding * vm/logic: remove weird comment * Fix SAR opcode handler * Use bufferToBigInt in Push opcode handler * use bufferToBigInt everywhere * Fix missing bufferToBigInt import * Check for edge case in expmod * Ignore prettier * Update browser tsconfig to es2020 lib * Remove dup ES2020 targets * attempt to dedupe "target" and "lib" tsconfig values * Update karma config to target es2020 in parser * Various test fixes * Lint and BN fixes * Add bigint helpers to util * lint fixes * various bigint helper additions * Lint fixes * Fix bnToBigInt * Lint/test fixes * Switch Xn to BigInt(X) * lint * lint * More Xn to BigInt(X) moves Co-authored-by: Ryan Ghods <[email protected]> Co-authored-by: Jochem Brouwer <[email protected]> Co-authored-by: Jochem Brouwer <[email protected]>
* Replace BN.js with bigints in VM * Fix byteLength computation in EXP handler * Fix toTwos helper * Compute TWO_POWE256 using math instead of hex * Update packages/util/src/constants.ts Co-authored-by: Ryan Ghods <[email protected]> * Remove unused variable * Fix exponent byte length calc * Fix exp overflow * Fix precompile bigint conversions * Fix more bigint conversions * Fix EXP opcode handler * Fix logic bug in signextend * vm/gas: fix EXTCODECOPY gas * vm/gas: fix sha256 gas * vm/gas: sha256 const -> let * vm: lint * vm/logic: fix sdiv/smod and fromTwos/toTwos * vm/logic: fix SIGNEXTEND * vm/logic: fix CALLDATALOAD padding * vm/logic: remove weird comment * Fix SAR opcode handler * Use bufferToBigInt in Push opcode handler * use bufferToBigInt everywhere * Fix missing bufferToBigInt import * Check for edge case in expmod * Ignore prettier * Update browser tsconfig to es2020 lib * Remove dup ES2020 targets * attempt to dedupe "target" and "lib" tsconfig values * Update karma config to target es2020 in parser * Various test fixes * Lint and BN fixes * Add bigint helpers to util * lint fixes * various bigint helper additions * Lint fixes * Fix bnToBigInt * Lint/test fixes * Switch Xn to BigInt(X) * lint * lint * More Xn to BigInt(X) moves Co-authored-by: Ryan Ghods <[email protected]> Co-authored-by: Jochem Brouwer <[email protected]> Co-authored-by: Jochem Brouwer <[email protected]>
* Replace BN.js with bigints in VM * Fix byteLength computation in EXP handler * Fix toTwos helper * Compute TWO_POWE256 using math instead of hex * Update packages/util/src/constants.ts Co-authored-by: Ryan Ghods <[email protected]> * Remove unused variable * Fix exponent byte length calc * Fix exp overflow * Fix precompile bigint conversions * Fix more bigint conversions * Fix EXP opcode handler * Fix logic bug in signextend * vm/gas: fix EXTCODECOPY gas * vm/gas: fix sha256 gas * vm/gas: sha256 const -> let * vm: lint * vm/logic: fix sdiv/smod and fromTwos/toTwos * vm/logic: fix SIGNEXTEND * vm/logic: fix CALLDATALOAD padding * vm/logic: remove weird comment * Fix SAR opcode handler * Use bufferToBigInt in Push opcode handler * use bufferToBigInt everywhere * Fix missing bufferToBigInt import * Check for edge case in expmod * Ignore prettier * Update browser tsconfig to es2020 lib * Remove dup ES2020 targets * attempt to dedupe "target" and "lib" tsconfig values * Update karma config to target es2020 in parser * Various test fixes * Lint and BN fixes * Add bigint helpers to util * lint fixes * various bigint helper additions * Lint fixes * Fix bnToBigInt * Lint/test fixes * Switch Xn to BigInt(X) * lint * lint * More Xn to BigInt(X) moves Co-authored-by: Ryan Ghods <[email protected]> Co-authored-by: Jochem Brouwer <[email protected]> Co-authored-by: Jochem Brouwer <[email protected]>
* Replace BN.js with bigints in VM * Fix byteLength computation in EXP handler * Fix toTwos helper * Compute TWO_POWE256 using math instead of hex * Update packages/util/src/constants.ts Co-authored-by: Ryan Ghods <[email protected]> * Remove unused variable * Fix exponent byte length calc * Fix exp overflow * Fix precompile bigint conversions * Fix more bigint conversions * Fix EXP opcode handler * Fix logic bug in signextend * vm/gas: fix EXTCODECOPY gas * vm/gas: fix sha256 gas * vm/gas: sha256 const -> let * vm: lint * vm/logic: fix sdiv/smod and fromTwos/toTwos * vm/logic: fix SIGNEXTEND * vm/logic: fix CALLDATALOAD padding * vm/logic: remove weird comment * Fix SAR opcode handler * Use bufferToBigInt in Push opcode handler * use bufferToBigInt everywhere * Fix missing bufferToBigInt import * Check for edge case in expmod * Ignore prettier * Update browser tsconfig to es2020 lib * Remove dup ES2020 targets * attempt to dedupe "target" and "lib" tsconfig values * Update karma config to target es2020 in parser * Various test fixes * Lint and BN fixes * Add bigint helpers to util * lint fixes * various bigint helper additions * Lint fixes * Fix bnToBigInt * Lint/test fixes * Switch Xn to BigInt(X) * lint * lint * More Xn to BigInt(X) moves Co-authored-by: Ryan Ghods <[email protected]> Co-authored-by: Jochem Brouwer <[email protected]> Co-authored-by: Jochem Brouwer <[email protected]>
* Replace BN.js with bigints in VM * Fix byteLength computation in EXP handler * Fix toTwos helper * Compute TWO_POWE256 using math instead of hex * Update packages/util/src/constants.ts Co-authored-by: Ryan Ghods <[email protected]> * Remove unused variable * Fix exponent byte length calc * Fix exp overflow * Fix precompile bigint conversions * Fix more bigint conversions * Fix EXP opcode handler * Fix logic bug in signextend * vm/gas: fix EXTCODECOPY gas * vm/gas: fix sha256 gas * vm/gas: sha256 const -> let * vm: lint * vm/logic: fix sdiv/smod and fromTwos/toTwos * vm/logic: fix SIGNEXTEND * vm/logic: fix CALLDATALOAD padding * vm/logic: remove weird comment * Fix SAR opcode handler * Use bufferToBigInt in Push opcode handler * use bufferToBigInt everywhere * Fix missing bufferToBigInt import * Check for edge case in expmod * Ignore prettier * Update browser tsconfig to es2020 lib * Remove dup ES2020 targets * attempt to dedupe "target" and "lib" tsconfig values * Update karma config to target es2020 in parser * Various test fixes * Lint and BN fixes * Add bigint helpers to util * lint fixes * various bigint helper additions * Lint fixes * Fix bnToBigInt * Lint/test fixes * Switch Xn to BigInt(X) * lint * lint * More Xn to BigInt(X) moves Co-authored-by: Ryan Ghods <[email protected]> Co-authored-by: Jochem Brouwer <[email protected]> Co-authored-by: Jochem Brouwer <[email protected]>
* Replace BN.js with bigints in VM * Fix byteLength computation in EXP handler * Fix toTwos helper * Compute TWO_POWE256 using math instead of hex * Update packages/util/src/constants.ts Co-authored-by: Ryan Ghods <[email protected]> * Remove unused variable * Fix exponent byte length calc * Fix exp overflow * Fix precompile bigint conversions * Fix more bigint conversions * Fix EXP opcode handler * Fix logic bug in signextend * vm/gas: fix EXTCODECOPY gas * vm/gas: fix sha256 gas * vm/gas: sha256 const -> let * vm: lint * vm/logic: fix sdiv/smod and fromTwos/toTwos * vm/logic: fix SIGNEXTEND * vm/logic: fix CALLDATALOAD padding * vm/logic: remove weird comment * Fix SAR opcode handler * Use bufferToBigInt in Push opcode handler * use bufferToBigInt everywhere * Fix missing bufferToBigInt import * Check for edge case in expmod * Ignore prettier * Update browser tsconfig to es2020 lib * Remove dup ES2020 targets * attempt to dedupe "target" and "lib" tsconfig values * Update karma config to target es2020 in parser * Various test fixes * Lint and BN fixes * Add bigint helpers to util * lint fixes * various bigint helper additions * Lint fixes * Fix bnToBigInt * Lint/test fixes * Switch Xn to BigInt(X) * lint * lint * More Xn to BigInt(X) moves Co-authored-by: Ryan Ghods <[email protected]> Co-authored-by: Jochem Brouwer <[email protected]> Co-authored-by: Jochem Brouwer <[email protected]>
* Replace BN.js with bigints in VM * Fix byteLength computation in EXP handler * Fix toTwos helper * Compute TWO_POWE256 using math instead of hex * Update packages/util/src/constants.ts Co-authored-by: Ryan Ghods <[email protected]> * Remove unused variable * Fix exponent byte length calc * Fix exp overflow * Fix precompile bigint conversions * Fix more bigint conversions * Fix EXP opcode handler * Fix logic bug in signextend * vm/gas: fix EXTCODECOPY gas * vm/gas: fix sha256 gas * vm/gas: sha256 const -> let * vm: lint * vm/logic: fix sdiv/smod and fromTwos/toTwos * vm/logic: fix SIGNEXTEND * vm/logic: fix CALLDATALOAD padding * vm/logic: remove weird comment * Fix SAR opcode handler * Use bufferToBigInt in Push opcode handler * use bufferToBigInt everywhere * Fix missing bufferToBigInt import * Check for edge case in expmod * Ignore prettier * Update browser tsconfig to es2020 lib * Remove dup ES2020 targets * attempt to dedupe "target" and "lib" tsconfig values * Update karma config to target es2020 in parser * Various test fixes * Lint and BN fixes * Add bigint helpers to util * lint fixes * various bigint helper additions * Lint fixes * Fix bnToBigInt * Lint/test fixes * Switch Xn to BigInt(X) * lint * lint * More Xn to BigInt(X) moves Co-authored-by: Ryan Ghods <[email protected]> Co-authored-by: Jochem Brouwer <[email protected]> Co-authored-by: Jochem Brouwer <[email protected]>
* Replace BN.js with bigints in VM * Fix byteLength computation in EXP handler * Fix toTwos helper * Compute TWO_POWE256 using math instead of hex * Update packages/util/src/constants.ts Co-authored-by: Ryan Ghods <[email protected]> * Remove unused variable * Fix exponent byte length calc * Fix exp overflow * Fix precompile bigint conversions * Fix more bigint conversions * Fix EXP opcode handler * Fix logic bug in signextend * vm/gas: fix EXTCODECOPY gas * vm/gas: fix sha256 gas * vm/gas: sha256 const -> let * vm: lint * vm/logic: fix sdiv/smod and fromTwos/toTwos * vm/logic: fix SIGNEXTEND * vm/logic: fix CALLDATALOAD padding * vm/logic: remove weird comment * Fix SAR opcode handler * Use bufferToBigInt in Push opcode handler * use bufferToBigInt everywhere * Fix missing bufferToBigInt import * Check for edge case in expmod * Ignore prettier * Update browser tsconfig to es2020 lib * Remove dup ES2020 targets * attempt to dedupe "target" and "lib" tsconfig values * Update karma config to target es2020 in parser * Various test fixes * Lint and BN fixes * Add bigint helpers to util * lint fixes * various bigint helper additions * Lint fixes * Fix bnToBigInt * Lint/test fixes * Switch Xn to BigInt(X) * lint * lint * More Xn to BigInt(X) moves Co-authored-by: Ryan Ghods <[email protected]> Co-authored-by: Jochem Brouwer <[email protected]> Co-authored-by: Jochem Brouwer <[email protected]>
* Replace BN.js with bigints in VM * Fix byteLength computation in EXP handler * Fix toTwos helper * Compute TWO_POWE256 using math instead of hex * Update packages/util/src/constants.ts Co-authored-by: Ryan Ghods <[email protected]> * Remove unused variable * Fix exponent byte length calc * Fix exp overflow * Fix precompile bigint conversions * Fix more bigint conversions * Fix EXP opcode handler * Fix logic bug in signextend * vm/gas: fix EXTCODECOPY gas * vm/gas: fix sha256 gas * vm/gas: sha256 const -> let * vm: lint * vm/logic: fix sdiv/smod and fromTwos/toTwos * vm/logic: fix SIGNEXTEND * vm/logic: fix CALLDATALOAD padding * vm/logic: remove weird comment * Fix SAR opcode handler * Use bufferToBigInt in Push opcode handler * use bufferToBigInt everywhere * Fix missing bufferToBigInt import * Check for edge case in expmod * Ignore prettier * Update browser tsconfig to es2020 lib * Remove dup ES2020 targets * attempt to dedupe "target" and "lib" tsconfig values * Update karma config to target es2020 in parser * Various test fixes * Lint and BN fixes * Add bigint helpers to util * lint fixes * various bigint helper additions * Lint fixes * Fix bnToBigInt * Lint/test fixes * Switch Xn to BigInt(X) * lint * lint * More Xn to BigInt(X) moves Co-authored-by: Ryan Ghods <[email protected]> Co-authored-by: Jochem Brouwer <[email protected]> Co-authored-by: Jochem Brouwer <[email protected]>
Replaces BN.js with bigints across the VM and updated compilation targets for VM and util to ES2020
Implementation details:
evm
/StateManager
/etc.).bigint
inputs instead ofBN.js
and numeric outputs inexecResult
and similar VM outputs are passed asbigint
s instead ofBN
sutil
to convert BNs to bigints, buffers, and vice-versa.bigint
usagebigints
when passed from other packages into VM API (e.g. fromtx
andblock
objects in the State Manager)