-
Notifications
You must be signed in to change notification settings - Fork 998
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
Integer overflow considerations #224
Comments
In this particular instance it's an easy fix:
I will go through the spec and fix what I find. The "harder" underflows are regarding balances and penalties. The spec has the following notice, admittedly not completely satisfactory:
|
Thank you! :) I'll keep an eye out for your changes, then let you know if I notice any more. |
thanks @paulhauner! see also #160 - I found a few more of these but I'm also waiting for things to settle a bit given that there's lots of general bugfixing going on already :) A similar "category" of underflows to look out for is close to genesis, where we do things like |
So one idea is to have |
I'm not familiar enough with the spec to say that this is sufficient to fully solve underflows, but gut-feeling-wise, it seems.. brittle. Many of these issues happen in comparisons - another way to address those at least is to simply disallow subtraction and instead only allow addition. This solves the underflow problem, but not overflow problem. #192 expresses a desire to be able to make formal claims about overflows as well - for example, one could make a formal claim about the system being both under- and overflow-free up to slot X. |
Paging in @djrtwo.
What is the overflow problem? Can you point to an instance in the code? |
When you flip a conditional that might have underflowed due to subtraction, you always get a conditional that might theoretically overflow due to addition. That said, most of these issues had to do with subtracting small numbers from initial slots. If adding these small numbers to the slot causes an overflow, then we have more problems than that because we've exhausted our 64 bits worth of slots. |
Yup, agree it's theoretical at this stage - so it's more about understanding well what the bounds are, and thus being able to make good use of guarantees instead of hoping for the best :) |
Naive saturation has the effect that Assuming we don't want any attestations until the
|
Oops, I missed @paulhauner 's comment before doing #279. |
This still underflows, but good point about distinguishing "user data" from internal state, that presumably no longer is tainted. The way forwards here might be to specify the semantics under no-overflow conditions / unbounded integers (still avoiding underflows), and address the issue in an appendix instead, that may or may not come with the spec. |
attestations: avoid unsigned underflow (eth2.0-specs/issues/#224)
I assumed here that the spec uses Python for code examples and that This raises an interesting point that the spec uses an effectively undefined type for all
This could work. We could also define "saturating" methods that assume the Python the
Assuming |
python integers are essentially what are called unbounded bigints in statically typed languages - there's no concept of unsigned or bit length in python itself outside of its serialization/marshalling/interop modules - this is the translation friction we're encountering when trying to stuff what's in the spec into more limited types. |
While I have it in my head, I would jot down another common issue to watch out for with Not a direct issue for compiled languages and controlled environments, but it shuts out a class of ready-made web-tools tools - this will be of interest for the testing effort which currently is looking at YAML - in some languages, a custom YAML/JSON parser will need to be used, or the numbers in question will have to be encoded as strings instead. |
Closing as I think underflows and overflows are now handled (e.g. with the |
I'm considering integer overflows in Lighthouse and there are cases where I'm making some assumptions about what I think the spec means.
For example, consider this code in "verify attestations":
As all of these variables are declared as
uint64
it would be fair to assume that we're going to see potential under-flows in the first few blocks and the behavior of the function will be significantly different depending on whether or not the subtraction saturates or under-flows.From my perspective it would be nice to see some explicitness around what to do in the case of overflows.
Or maybe all overflow scenarios have been considered and I'm missing some other checks that are normalizing behavior?
The text was updated successfully, but these errors were encountered: