-
Notifications
You must be signed in to change notification settings - Fork 772
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
Keep the stack items as an instance of bn.js #159
Conversation
22f8d4d
to
906834c
Compare
2189881
to
d68b535
Compare
Down to:
|
60265f7
to
ce14b30
Compare
ce14b30
to
cd76a34
Compare
Rebased this locally over #174, will push once that is merged. |
dc3f1e0
to
3f43220
Compare
3f43220
to
e6a67a3
Compare
@jwasinger I think this should work now too. Rebased and fixed some bugs. |
e6a67a3
to
a9f7b72
Compare
Fixed returndatasize, returndatacopy, jumpi and log. Push may be broken. |
a9f7b72
to
dac24b2
Compare
dac24b2
to
a82a5d3
Compare
a82a5d3
to
5a34c08
Compare
Two other fixes, this is now down to 0 failures:
😄 Let's wait with merging at least until Monday though, maybe someone wants to have another one-step-back view on this. |
Short speed comparison (on local MacBook Air) running the state tests:
Hmm, seems this was more for easier reading than for speed though. |
lib/opFns.js
Outdated
// NOTE: we're using a 'trick' here to get the least significant byte | ||
byte = byte.toArrayLike(Buffer, 'le', 1) | ||
byte = byte.toArrayLike(Buffer, 'be', 32) | ||
byte = byte.slice(byte.length - 1) |
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.
Can you extract a case from the tests where this caused an issue? I'd like to figure out what is the actual reason.
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.
node tests/tester.js -s --test='randomStatetest237' --jsontrace
In Node console:
const utils = require('ethereumjs-util')
const BN = utils.BN
var bn = new BN('fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe', 'hex')
bn.toArrayLike(Buffer, 'le', 1)
gives
Error: byte array longer than desired length
at assert (/Users/hdrewes/Documents/DEV/EthereumJS/ethereumjs-vm/node_modules/bn.js/lib/bn.js:6:21)
at BN.toArrayLike (/Users/hdrewes/Documents/DEV/EthereumJS/ethereumjs-vm/node_modules/bn.js/lib/bn.js:527:5)
at repl:1:4
at ContextifyScript.Script.runInThisContext (vm.js:44:33)
at REPLServer.defaultEval (repl.js:239:29)
at bound (domain.js:301:14)
at REPLServer.runBound [as eval] (domain.js:314:12)
at REPLServer.onLine (repl.js:440:10)
at emitOne (events.js:120:20)
at REPLServer.emit (events.js:210:7)
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.
Actually this is failing for every Buffer with length > 1, e.g. also for var bn = new BN('fffe', 'hex')
.
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.
Ah true, didn't in the end added the truncation support to bn.js.
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.
Could still do Buffer.from(bn.andln(0xff))
@holgerd77 that optimisation works - do you want to double check it? |
Should we do a minor release after this is merged? @axic: I have to admit I'm not getting your new trick. 😎 😸 |
Sure, we can make a release. |
lib/opFns.js
Outdated
}, | ||
ISZERO: function (a, runState) { | ||
return new BN(a.isZero()) | ||
return new BN(a.isZero() ? 1 : 0) |
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.
I think these make sense, but were there actually causing an issue?
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.
Yes, creating a BN
instance from true
is actually resulting in another value initialization than with 1
.
> new BN(true)
<BN: 7d0e>
> new BN(1)
<BN: 1>
Not sure if this is an error in bn.js
. I find this more explicit and better to read anyway.
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.
True, we are till using an outdated bn.js version which treated everything as a number and did random things. Finally a recent version would throw an error of invalid digit for given number base :)
lib/opFns.js
Outdated
}, | ||
EQ: function (a, b, runState) { | ||
return new BN(a.cmp(b) === 0) | ||
return new BN(a.cmp(b) === 0 ? 1 : 0) |
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.
Oh this code was done way before the higher level helpers were added to bn.js. We could use a.eq(b)
here and above.
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.
Created a new PR for this.
@holgerd77 are you OK with squashing down the |
@axic Is it possible (and did you mean that variant) squashing the |
@holgerd77 I'll do the squashing of that one into the original, but leaving every other fix intact. Just asking if you are happy with the last solution? |
Yes. Just curious how you will do that (squashing into the original, skipping the in-between commits) Not seeing anything for that in interactive rebase command selection. Any trick? |
Try interactive rebase: |
Ah, this note "These lines can be re-ordered;" from the rebase instructions was the missing part for me, didn't know that. |
e91ce60
to
3e9b1da
Compare
@holgerd77 ok to accept? |
Yes (the "Yes" from above was also already answering this. Sorry maybe too hidden. :-)). |
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.
Looks good, can be merged when tests pass.
I think there should be a more measurable speed increase on running contracts doing arithmetics. See some of @gcolvin's benchmarks for rc5, division and exponentiation. |
ci: separate browser test to own actions run
Fixes #38. Depends on #167, #168 and #174.