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

use correct minimum size when reading block / state headers #6263

Merged
merged 4 commits into from
May 25, 2024

Conversation

etan-status
Copy link
Contributor

sizeof also includes padding between fields, while SSZ defines fixedPortionSize (on type) or sszSize (on value) to denote required bytes to encode. Switch forked block/state readers to SSZ size. As blocks/states are much larger than the padding, this doesn't affect practical use cases but is slightly more correct this way.

`sizeof` also includes padding between fields, while SSZ defines
`fixedPortionSize` (on type) or `sszSize` (on value) to denote
required bytes to encode. Switch forked block/state readers to SSZ size.
As blocks/states are much larger than the padding, this doesn't affect
practical use cases but is slightly more correct this way.
Copy link

github-actions bot commented May 4, 2024

Unit Test Results

         9 files  ±0    1 325 suites  ±0   26m 4s ⏱️ - 6m 54s
  4 984 tests ±0    4 636 ✔️ ±0  348 💤 ±0  0 ±0 
20 808 runs  ±0  20 404 ✔️ ±0  404 💤 ±0  0 ±0 

Results for commit 220b882. ± Comparison against base commit c7bf6fb.

♻️ This comment has been updated with latest results.

@tersec
Copy link
Contributor

tersec commented May 4, 2024

nim-lang/Nim#23568

@tersec
Copy link
Contributor

tersec commented May 4, 2024

Updating to latest unstable should get this building again


# TODO https://github.com/nim-lang/Nim/issues/19357
result = readSszForkedHashedBeaconState(cfg, header.slot, data)
readSszForkedHashedBeaconState(cfg, header.slot, data)
Copy link
Contributor

@tersec tersec May 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In theory, this result = is to work around nim-lang/Nim#19357 despite its being less-than-ideal code style. #3050 appears to have introduced this, and notes:

  • fix several cases of states being stored on stack in tests, causing
    random failures on some platforms

Maybe it's not necessary, but the referenced Nim issue has not been resolved/closed.

If it's not necessary anymore in this situation, that would be better, but that would require some evidence of the codegen improvement.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

finding out requires going to the c code and looking for copies - it's a messy process - at some point, this should probably be pursued as a task, ie codegen quality review, with upstream .. including tests.

raise (ref MalformedSszError)(msg: "Not enough data for BeaconState header")
const numHeaderBytes = fixedPortionSize(BeaconStateHeader)
if data.len() < numHeaderBytes:
raise (ref MalformedSszError)(msg: "Incomplete BeaconState header")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we even need this raise? feels like SSZ.decode should already raise when there's not enough data

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we only pass toOpenArray(0, numHeaderBytes - 1), which would possibly Defect without the check.

@arnetheduck arnetheduck merged commit 0efc81d into unstable May 25, 2024
15 checks passed
@arnetheduck arnetheduck deleted the dev/etan/sf-paddingskip branch May 25, 2024 05:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants