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

Revert "ssz: bump (#5996)" #6037

Merged
merged 1 commit into from
Mar 7, 2024
Merged

Revert "ssz: bump (#5996)" #6037

merged 1 commit into from
Mar 7, 2024

Conversation

etan-status
Copy link
Contributor

@etan-status etan-status commented Mar 7, 2024

This reverts commit 21601f5.

Reason: /eth/v1/beacon/light_client/updates?start_period=0&count=128
provides malformed data. Reverting fixes it locally.

Download JSON and SSZ, then use this script to validate (Holesky).
Need to export some symbols for parsing.

import
  stew/io2,
  ./beacon_chain/spec/[digest, forks, helpers, presets],
  ./beacon_chain/spec/eth2_apis/[eth2_rest_serialization, rest_light_client_calls]

let jsonBytes = io2.readAllBytes("/Users/etan/Downloads/json_updates.json").get()

let
  (cfg, unknowns) = readRuntimeConfig("/Users/etan/Documents/Repos/nimbus-eth2/vendor/holesky/custom_config_data/config.yaml")
  genesis_validators_root = Eth2Digest.fromHex("0x9143aa7c615a7f7115e2b6aac319c03529df8242ae705fba9df39b79c59fa8b1")
  forkDigests = newClone ForkDigests.init(cfg, genesis_validators_root)

let updates = seq[ForkedLightClientUpdate].decodeJsonLightClientObjects(jsonBytes, cfg, forkDigests)

var entries = newSeqOfCap[RestVersioned[ForkedLightClientUpdate]](updates.len)
for update in updates:
  let
    contextEpoch = withForkyUpdate(update):
      when lcDataFork > LightClientDataFork.None:
        forkyUpdate.contextEpoch
      else:
        continue
    contextFork = cfg.consensusForkAtEpoch(contextEpoch)
  entries.add RestVersioned[ForkedLightClientUpdate](
    data: update,
    jsonVersion: contextFork,
    sszContext: forkDigests[].atconsensusFork(contextFork))

let res =
  block:
    var default: seq[byte]
    try:
      var stream = memoryOutput()
      for e in entries:
        withForkyUpdate(e.data):
          when lcDataFork > LightClientDataFork.None:
            var cursor = stream.delayFixedSizeWrite(sizeof(uint64))
            let initPos = stream.pos
            stream.write e.sszContext.data
            var writer = SszWriter.init(stream)
            writer.writeValue forkyUpdate
            cursor.finalWrite (stream.pos - initPos).uint64.toBytesLE()
      stream.getOutput(seq[byte])
    except SerializationError:
      default
    except IOError:
      default

let sszBytes = io2.readAllBytes("/Users/etan/Downloads/ssz_updates.ssz").get()

let sszUpdates = seq[ForkedLightClientUpdate].decodeSszLightClientObjects(res, cfg, forkDigests)
doAssert updates.len == sszUpdates.len
for i in 0 ..< updates.len:
  doAssert updates[i].kind == sszUpdates[i].kind
  withForkyUpdate(updates[i]):
    when lcDataFork > LightClientDataFork.None:
      doAssert forkyUpdate == sszUpdates[i].forky(lcDataFork)

doAssert sszBytes == res

This reverts commit 21601f5.

Reason: `/eth/v1/beacon/light_client/updates?start_period=0&count=128`
provides malformed data. Reverting fixes it locally.

Download JSON and SSZ, then use this script to validate (Holesky).
Need to export some symbols for parsing.

```nim
import
  stew/io2,
  ./beacon_chain/spec/[digest, forks, helpers, presets],
  ./beacon_chain/spec/eth2_apis/[eth2_rest_serialization, rest_light_client_calls]

let jsonBytes = io2.readAllBytes("/Users/etan/Downloads/json_updates.json").get()

let
  (cfg, unknowns) = readRuntimeConfig("/Users/etan/Documents/Repos/nimbus-eth2/vendor/holesky/custom_config_data/config.yaml")
  genesis_validators_root = Eth2Digest.fromHex("0x9143aa7c615a7f7115e2b6aac319c03529df8242ae705fba9df39b79c59fa8b1")
  forkDigests = newClone ForkDigests.init(cfg, genesis_validators_root)

let updates = seq[ForkedLightClientUpdate].decodeJsonLightClientObjects(jsonBytes, cfg, forkDigests)

var entries = newSeqOfCap[RestVersioned[ForkedLightClientUpdate]](updates.len)
for update in updates:
  let
    contextEpoch = withForkyUpdate(update):
      when lcDataFork > LightClientDataFork.None:
        forkyUpdate.contextEpoch
      else:
        continue
    contextFork = cfg.consensusForkAtEpoch(contextEpoch)
  entries.add RestVersioned[ForkedLightClientUpdate](
    data: update,
    jsonVersion: contextFork,
    sszContext: forkDigests[].atconsensusFork(contextFork))

let res =
  block:
    var default: seq[byte]
    try:
      var stream = memoryOutput()
      for e in entries:
        withForkyUpdate(e.data):
          when lcDataFork > LightClientDataFork.None:
            var cursor = stream.delayFixedSizeWrite(sizeof(uint64))
            let initPos = stream.pos
            stream.write e.sszContext.data
            var writer = SszWriter.init(stream)
            writer.writeValue forkyUpdate
            cursor.finalWrite (stream.pos - initPos).uint64.toBytesLE()
      stream.getOutput(seq[byte])
    except SerializationError:
      default
    except IOError:
      default

let sszBytes = io2.readAllBytes("/Users/etan/Downloads/ssz_updates.ssz").get()

let sszUpdates = seq[ForkedLightClientUpdate].decodeSszLightClientObjects(res, cfg, forkDigests)
doAssert updates.len == sszUpdates.len
for i in 0 ..< updates.len:
  doAssert updates[i].kind == sszUpdates[i].kind
  withForkyUpdate(updates[i]):
    when lcDataFork > LightClientDataFork.None:
      doAssert forkyUpdate == sszUpdates[i].forky(lcDataFork)

doAssert sszBytes == res
```
@etan-status etan-status enabled auto-merge (squash) March 7, 2024 19:35
@etan-status
Copy link
Contributor Author

@etan-status etan-status merged commit a299d17 into unstable Mar 7, 2024
12 checks passed
@etan-status etan-status deleted the dev/etan/rv-ssz branch March 7, 2024 22:37
@arnetheduck
Copy link
Member

status-im/nim-faststreams#51 should fix this

arnetheduck added a commit that referenced this pull request Mar 8, 2024
arnetheduck added a commit that referenced this pull request Mar 9, 2024
* Reapply "ssz: bump (#5996)" (#6037)

This reverts commit a299d17.

Fixed in status-im/nim-faststreams#51

* bump
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.

2 participants