Skip to content
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

Merged
merged 42 commits into from
Feb 22, 2022
Merged

VM: Replace BN.js with bigints, Util helpers #1671

merged 42 commits into from
Feb 22, 2022

Conversation

acolytec3
Copy link
Contributor

@acolytec3 acolytec3 commented Jan 27, 2022

Replaces BN.js with bigints across the VM and updated compilation targets for VM and util to ES2020
Implementation details:

  • Replaces BN.js with bigints in all calculations across all VM internals (evm/StateManager/etc.).
  • All VM exposed APIs now require bigint inputs instead of BN.js and numeric outputs in execResult and similar VM outputs are passed as bigints instead of BNs
  • Adds new helpers in util to convert BNs to bigints, buffers, and vice-versa.
  • Upgrades libraries to target ES2020 to support bigint usage
  • All BNs are currently converted to bigints when passed from other packages into VM API (e.g. from tx and block objects in the State Manager)

* 2^256
*/
export const TWO_POW256_BIGINT =
BigInt(0x10000000000000000000000000000000000000000000000000000000000000000)
Copy link
Contributor

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?

Copy link
Member

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? 🤔

Copy link
Contributor

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

@acolytec3
Copy link
Contributor Author

acolytec3 commented Jan 27, 2022

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 VMTests/vmArithmeticTest/exp.json

@ryanio
Copy link
Contributor

ryanio commented Jan 28, 2022

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

@jochem-brouwer jochem-brouwer added type: test all hardforks This special label enables VM state and blockchain tests for all hardforks on the respective PR. target: develop labels Jan 31, 2022
@jochem-brouwer
Copy link
Member

Some small stuff I noticed, which we should look at (will edit this if I find more)

  • npm i --workspaces fails on build
  • Browser build are failing on some packages
  • Coding style should be consistent, for instance gas = gas + 2n and gas += 2n are used mixed

@codecov
Copy link

codecov bot commented Feb 3, 2022

Codecov Report

Merging #1671 (1ddcc23) into develop (3627197) will increase coverage by 0.73%.
The diff coverage is 92.70%.

Impacted file tree graph

Flag Coverage Δ
block 85.33% <ø> (+0.31%) ⬆️
blockchain 83.55% <ø> (+0.26%) ⬆️
client 72.76% <33.33%> (+1.63%) ⬆️
common 93.40% <ø> (+0.28%) ⬆️
devp2p 82.90% <ø> (+0.39%) ⬆️
ethash 90.76% <ø> (ø)
rlp ?
trie 86.53% <ø> (+0.34%) ⬆️
tx 90.97% <ø> (+1.02%) ⬆️
util 89.91% <86.66%> (-0.09%) ⬇️
vm 82.10% <93.16%> (+0.77%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

@acolytec3
Copy link
Contributor Author

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.

@ryanio
Copy link
Contributor

ryanio commented Feb 7, 2022

it's okay if hardhat isn't passing on develop since it's the breaking changes, which is expected

@@ -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)
Copy link
Contributor

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.

Suggested change
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.
Copy link
Contributor

@ryanio ryanio Feb 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.

@ryanio
Copy link
Contributor

ryanio commented Feb 8, 2022

awesome, thanks for doing that!

let's move the three functions you added to types.ts over to bytes.ts, all of them there sounds good to me

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?

@acolytec3
Copy link
Contributor Author

edit: I'm still seeing a handful of places where these new functions aren't used (big pr smile) 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.

@acolytec3
Copy link
Contributor Author

let's move the three functions you added to types.ts over to bytes.ts, all of them there sounds good to me

I'm not sure I follow the logic on this one. These three are type conversion utilities between non Buffer types and we already have similar type converters for intToHex/bnToHex etc in the types section. Happy to move but it seems like it's more fitting for them to stay in types unless we're also going to move all the other type converters to bytes too (and I could make a case for that I think.

@ryanio
Copy link
Contributor

ryanio commented Feb 9, 2022

good point, sounds good!

@holgerd77
Copy link
Member

I'm not sure I follow the logic on this one. These three are type conversion utilities between non Buffer types and we already have similar type converters for intToHex/bnToHex etc in the types section. Happy to move but it seems like it's more fitting for them to stay in types unless we're also going to move all the other type converters to bytes too (and I could make a case for that I think.

Yes, these conversion function like bnToHex() in types.ts are totally misplaced and we should move, wonder if I have at some point already opened an issue on that (or at least mentioned somewhere some time ago)?

If you do please make sure to clearly document somewhere, otherwise this will likely be forgotten on the release notes at some point.

@holgerd77
Copy link
Member

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! 🎉
Let's go BigInt. 🚀

Copy link
Member

@holgerd77 holgerd77 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@holgerd77 holgerd77 changed the title Replace BN.js with bigints in VM VM, Util: Replace BN.js with bigints Feb 22, 2022
@holgerd77 holgerd77 changed the title VM, Util: Replace BN.js with bigints VM: Replace BN.js with bigints, Util helpers Feb 22, 2022
@holgerd77 holgerd77 merged commit a6e3496 into develop Feb 22, 2022
This was referenced Feb 22, 2022
holgerd77 pushed a commit that referenced this pull request Feb 23, 2022
* 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]>
holgerd77 pushed a commit that referenced this pull request Feb 23, 2022
* 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]>
holgerd77 pushed a commit that referenced this pull request Mar 5, 2022
* 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]>
holgerd77 pushed a commit that referenced this pull request Mar 24, 2022
* 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]>
gabrocheleau pushed a commit that referenced this pull request Mar 27, 2022
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]>
holgerd77 pushed a commit that referenced this pull request Apr 5, 2022
* 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]>
holgerd77 pushed a commit that referenced this pull request Apr 7, 2022
* 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]>
gabrocheleau pushed a commit that referenced this pull request Apr 21, 2022
* 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]>
g11tech pushed a commit that referenced this pull request Apr 29, 2022
* 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]>
holgerd77 pushed a commit that referenced this pull request May 4, 2022
* 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]>
g11tech pushed a commit that referenced this pull request Jun 2, 2022
* 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]>
g11tech pushed a commit that referenced this pull request Jun 2, 2022
* 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]>
g11tech pushed a commit that referenced this pull request Jun 2, 2022
* 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]>
g11tech pushed a commit that referenced this pull request Jun 3, 2022
* 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]>
holgerd77 pushed a commit that referenced this pull request Jun 8, 2022
* 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]>
@holgerd77 holgerd77 deleted the bigints branch June 30, 2022 12:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants