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

Random results #1334

Closed
mirek opened this issue Jan 29, 2018 · 5 comments
Closed

Random results #1334

mirek opened this issue Jan 29, 2018 · 5 comments
Assignees
Labels
Bug Addressing a bug

Comments

@mirek
Copy link

mirek commented Jan 29, 2018

// npm i -S web3@1.0.0-beta.29
// npm i -S ganache-core

const ganache = require('ganache-core')
const Web3 = require('web3')
const web3 = new Web3(ganache.provider())

void async function main() {

  const account = web3.eth.accounts.privateKeyToAccount(web3.utils.randomHex(32))

  const tx = {
    to: '0xF0109fC8DF283027b6285cc889F5aA624EaC1F55',
    value: '1000000000',
    gas: 2000000
  }

  const stx = await web3.eth.accounts.signTransaction(tx, account.privateKey)
  console.log(stx)

}().catch(_1 => console.error(_1.stack))

Running above code will give random results:

{ messageHash: '0x3bdbdaf7a04a7a41022369aee73d768203481fabdbaa5a0ca3f2e29715d1ccc3',
  v: undefined,
  r: undefined,
  s: undefined,
  rawTransaction: '0xf96f.8808504a817c800831e848094f0109fc8df283027b6285cc889f5aa624eac1f55843b9aca008085.82c28464040fa026285d7c95de32b1d45b70c2db83a4bfb8a3a454c23dd0857bfca6a9cf1477b8a0201193635ee090013b2dee2e9199e02705f52791fed60f25ccefcac3a9d58e90' }

Above result is completely incorrect, there are dots in the transaction, undefined etc.

{ messageHash: '0xf523118727591dfae42787c3ca5290f854fc53b8a9fdc871737490316ff9d2fb',
  v: '0x.82c28461f',
  r: '0x1b30f5ea6c19d449c2a501664d5335a303831817b20ca341bc657eca06b9159d3016e28600302612be6be100896340bf2f4ab9d39663f7ccb2e744002',
  s: undefined,
  rawTransaction: '0xf96f.8808504a817c800831e848094f0109fc8df283027b6285cc889f5aa624eac1f55843b9aca008085.82c28461fbd4a0813dd4fbd1b30f5ea6c19d449c2a501664d5335a303831817b20ca341bc657eca06b9159d3016e28600302612be6be100896340bf2f4ab9d39663f7ccb2e744002' }

similar to above, dot's in hex strings.

TypeError: hex.startsWith is not a function
    at trimLeadingZero (/Users/mirek/ab/sign/node_modules/web3-eth-accounts/src/index.js:45:23)
    at signed (/Users/mirek/ab/sign/node_modules/web3-eth-accounts/src/index.js:177:16)
    at /Users/mirek/ab/sign/node_modules/web3-eth-accounts/src/index.js:202:16
    at tryCatcher (/Users/mirek/ab/sign/node_modules/web3-eth-accounts/node_modules/bluebird/js/release/util.js:16:23)
    at Promise._settlePromiseFromHandler (/Users/mirek/ab/sign/node_modules/web3-eth-accounts/node_modules/bluebird/js/release/promise.js:497:31)
    at Promise._settlePromise (/Users/mirek/ab/sign/node_modules/web3-eth-accounts/node_modules/bluebird/js/release/promise.js:555:18)
    at Promise._settlePromise0 (/Users/mirek/ab/sign/node_modules/web3-eth-accounts/node_modules/bluebird/js/release/promise.js:600:10)
    at Promise._settlePromises (/Users/mirek/ab/sign/node_modules/web3-eth-accounts/node_modules/bluebird/js/release/promise.js:683:18)
    at Promise._fulfill (/Users/mirek/ab/sign/node_modules/web3-eth-accounts/node_modules/bluebird/js/release/promise.js:624:18)
    at PromiseArray._resolve (/Users/mirek/ab/sign/node_modules/web3-eth-accounts/node_modules/bluebird/js/release/promise_array.js:125:19)
    at PromiseArray._promiseFulfilled (/Users/mirek/ab/sign/node_modules/web3-eth-accounts/node_modules/bluebird/js/release/promise_array.js:143:14)
    at Promise._settlePromise (/Users/mirek/ab/sign/node_modules/web3-eth-accounts/node_modules/bluebird/js/release/promise.js:560:26)
    at Promise._settlePromise0 (/Users/mirek/ab/sign/node_modules/web3-eth-accounts/node_modules/bluebird/js/release/promise.js:600:10)
    at Promise._settlePromises (/Users/mirek/ab/sign/node_modules/web3-eth-accounts/node_modules/bluebird/js/release/promise.js:683:18)
    at Async._drainQueue (/Users/mirek/ab/sign/node_modules/web3-eth-accounts/node_modules/bluebird/js/release/async.js:125:16)
    at Async._drainQueues (/Users/mirek/ab/sign/node_modules/web3-eth-accounts/node_modules/bluebird/js/release/async.js:135:10)
    at Immediate.Async.drainQueues [as _onImmediate] (/Users/mirek/ab/sign/node_modules/web3-eth-accounts/node_modules/bluebird/js/release/async.js:16:14)
    at runCallback (timers.js:756:18)
    at tryOnImmediate (timers.js:717:5)
    at processImmediate [as _immediateCallback] (timers.js:697:5)

randomly it'll throw this exception instead.

@mirek mirek changed the title Random exceptions Random results Jan 29, 2018
@mirek
Copy link
Author

mirek commented Jan 29, 2018

It seems that this will consistently fail:

const web3 = new Web3(ganache.provider({ network_id: null }))

and this will consistently work:

const web3 = new Web3(ganache.provider({ network_id: 0x11 }))

@mirek
Copy link
Author

mirek commented Jan 29, 2018

Fun fact, using different chain ids will give different behavior:

column 1: chain id
column 2: invalid signature (dot in hex string)
column 3: exception thrown when trying to sign

  0   0%   0%
  1   0%   0%
...
100   0%   0%
101   0%   0%
102   0%   0%
103   0%   0%
104   0%   0%
105   0%   0%
106   0%   0%
107   0%   0%
108   0%   0%
109   0%   0%
110  41%   0%
111 100%   0%
112 100%   0%
113 100%   0%
114 100%   0%
115 100%   0%
116  65%  35%
117  24%  76%
118  92%   8%
119 100%   0%
120 100%   0%
121 100%   0%
122 100%   0%
123 100%   0%
124  66%  34%
125  30%  70%
126  91%   9%
127 100%   0%
128 100%   0%
129 100%   0%
130 100%   0%
131 100%   0%
132  75%  25%
133  36%  64%
134  91%   9%
135 100%   0%
136 100%   0%
137 100%   0%
138 100%   0%
139 100%   0%
140  58%  42%
141  32%  68%
142  92%   8%
143 100%   0%
144 100%   0%
145 100%   0%
146 100%   0%
147 100%   0%
148  64%  36%
149  33%  67%
150  91%   9%
...

...are there any limitations on chainId? It looks like 109 is the highest number you can go to have reliable signatures, anything above that fails in random ways. My favourite being 110 which fails just for 41% signatures and remaining 59% are valid.

What's going on?

@mirek
Copy link
Author

mirek commented Jan 29, 2018

It looks like it's related to EIP-155 https://github.com/ethereum/EIPs/blob/master/EIPS/eip-155.md as first failing chain number is 110, which is the first one overflowing 1 byte in chain_id * 2 + 36.

@davux
Copy link

davux commented Feb 20, 2018

Which versions of web3js are affected by this?

FWIW, I'm using web3js 0.20.0 and I'm getting weird behaviours, however I'm using chainId == 42 (even though it's a private chain).

@cgewecke
Copy link
Collaborator

cgewecke commented Mar 1, 2018

@mirek Was seeing this on .27 and now it seems to be gone on .30. Can you confirm if you have a chance?

@nivida nivida self-assigned this Aug 9, 2018
@nivida nivida added the Bug Addressing a bug label Aug 9, 2018
@nivida nivida closed this as completed Aug 16, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Addressing a bug
Projects
None yet
Development

No branches or pull requests

4 participants