-
Notifications
You must be signed in to change notification settings - Fork 31
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
Align core types with execution spec #733
Conversation
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'm all in for these changes that align more with the exec. spec., and have consistency with nimbus-eth2.
a157a70
to
f7a788d
Compare
470c8ac
to
eed6dd1
Compare
Since these types were written, we've gained an executable spec: https://github.com/ethereum/execution-specs This PR aligns some of the types we use with this spec to simplify comparisons and cross-referencing. Using a `distinct` type is a tradeoff between nim ergonomics, type safety and the ability to work around nim quirks and stdlib weaknesses. In particular, it allows us to overload common functions such as `hash` with correct and performant versions as well as maintain control over string conversions etc at the cost of a little bit of ceremony when instantiating them. Apart from distinct byte types, `Hash32`, is introduced in lieu of the existing `Hash256`, again aligning this commonly used type with the spec which picks bytes rather than bits in the name.
eed6dd1
to
b4d1ef5
Compare
|
||
template default*[N](T: type FixedBytes[N]): T = | ||
# Avoid bad codegen where fixed bytes are zeroed byte-by-byte at call site | ||
const def = system.default(T) |
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.
noticed anonConst
in stew/objects
, useful pattern to enshrine in general
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.
hm, yeah, didn't know about that one - one thing though is that it generates a new, separate const on every instantiation even if it's the same value/type which I'm not too happy about - ie each default(Bytes32)
would result in a separately declared constant in the generated code which is not great
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.
In theory especially with LTO these could be folded into a single constant. My understanding is that this is a typical linker optimization
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.
depends - for that to happen, it must determine that the address of the variable is not used for uniqueness / comparisons which doesn't necessarily happen and/or requires special flags.
status-im/nim-eth#733 updates `Hash256` to become an array instead of an object - unfortunately, nim does not allow constructing arrays with `name()`, so this PR changes it to `default` which works with both.
* init style for Hash256 status-im/nim-eth#733 updates `Hash256` to become an array instead of an object - unfortunately, nim does not allow constructing arrays with `name()`, so this PR changes it to `default` which works with both. * lint
Minimal changes neede for compatiblity with status-im/nim-eth#733 which aligns core types with execution spec.
Minimal changes needed for compatiblity with status-im/nim-eth#733 which aligns core types with execution spec.
Since these types were written, we've gained an executable spec:
https://github.com/ethereum/execution-specs
This PR aligns some of the types we use with this spec to simplify comparisons and cross-referencing.
Using a
distinct
type is a tradeoff between nim ergonomics, type safety and the ability to work around nim quirks and stdlib weaknesses.In particular, it allows us to overload common functions such as
hash
with correct and performant versions as well as maintain control over string conversions etc at the cost of a little bit of ceremony when instantiating them.Apart from distinct byte types,
Hash32
, is introduced in lieu of the existingHash256
, again aligning this commonly used type with the spec which picks bytes rather than bits in the name.