ethereumjs-monorepo icon indicating copy to clipboard operation
ethereumjs-monorepo copied to clipboard

Util -> Account: upper bound nonce and balance

Open jochem-brouwer opened this issue 5 years ago • 7 comments

Linking https://github.com/ethereumjs/ethereumjs-vm/issues/464

The problem here is that we can artificially cause the VM to put BNs with more than 256 bits on the stack. StateManager will throw but we should never allow that this data ends up on the stack in the first place.

Account currently does some bound checks (checking if balance >= 0, for instance). However, we should also check that the balance does not exceed the max BN. Same goes for the nonce.

Just to verify here, it is allowed to change values of the Account? (balance, nonce, etc. are not marked as readonly?)

jochem-brouwer avatar Oct 23 '20 12:10 jochem-brouwer

@jochem-brouwer why do you need to change values if you just plan to add an additional check?

holgerd77 avatar Oct 23 '20 14:10 holgerd77

Is this still an issue?

holgerd77 avatar Aug 10 '21 12:08 holgerd77

Nonce is capped here https://github.com/ethereumjs/ethereumjs-monorepo/pull/1568. We should cap balance at 2^256-1 which is rather trivial.

jochem-brouwer avatar Dec 10 '21 10:12 jochem-brouwer

Actually it is not entirely trivial; we should use setters for both nonce and balance to verify that these do not exceed their maxima.

jochem-brouwer avatar Dec 10 '21 10:12 jochem-brouwer

Has some of this been addressed in #1568 ?

holgerd77 avatar Jan 13 '22 18:01 holgerd77

The nonce is bounded by the VM in the linked PR. But we might want to add these checks directly into util's account class; we can check there that nonce/balance does not exceed their maxima.

jochem-brouwer avatar Jan 13 '22 18:01 jochem-brouwer

There is a nonce check here, which is OK with this issue:

https://github.com/ethereumjs/ethereumjs-monorepo/blob/a87f179938d9b22902893dc4d1af0bf4b8b63e76/packages/tx/src/baseTransaction.ts#L119

However, I'm not sure about the balance check, should we interally limit to 32 bytes balance?

jochem-brouwer avatar Aug 27 '22 03:08 jochem-brouwer

Partly addressed and stale for a long time, will close, seems there is no pressing need to implement (might also be that we now have all checks anyhow, not 100% sure).

holgerd77 avatar Aug 01 '23 10:08 holgerd77