Skip to content

Conversation

@qnikst
Copy link
Contributor

@qnikst qnikst commented Nov 3, 2025

Introduced a new command that allows to generate a file.

While working on that I had to introduce a lots of helpers for encoding:

  • ByteStringSized (n::Nat) — bytestring with size known at the runtime
  • SomeByteStringSized — existential wrapper that allows to keep ByteStringSized of the different size and compare them (in the length-first order)
  • GenericCBOREntry n — an entry that is CBOR with a fixed size key, it's useful for reading entries and later verification
  • SomeCBOREntry — existential wrapper that allows to have GenericCBOREntries if the different key size in the same plan

Previously in a code we required entire value to have an Ord
instance. While it's possible to have such one it leads to problems
when we work with generic values of the types we do not know.

The other problem is that during the computation we should check
the equality for the keys only and do not allow two values with
the same key even if they are not equal. So the new type reflects
that properly.
ByteStringSized wrapper allows to store a ByteString of the
known size without prefixing it with a size.

It's expected to be used as a helper for storing keys
Introdunce two new types:
- GenericCBOREntry for storing and reading any CBOR Term stored in utxo
- SomeCBOREntry that is used only for generation, and allows to bypass
  the restriction that the types on all entries in the Plan should be the
  same. This restriction is problematic because namespaces should be able
  to use differently sized keys and as a result differrent types
Introduces API that allow to generate files using specification
for the namespaces defined. It can be used for implementation
testing and as for the node developemnet and other implementations

```
cabal run scls-util -- debug generate --help
Usage: scls-util debug generate FILE [--namespace NAMESPACE[:COUNT]]

  Generate a debug SCLS file with random data

Available options:
  FILE                     Path to SCLS file
  --namespace NAMESPACE[:COUNT]
                           Namespace and optional number of entries to generate,
                           default is 16
  -h,--help                Show this help text
```
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds a debug file generation utility to create SCLS files with random data for testing and debugging purposes. The implementation allows generating files with specified namespaces and entry counts.

Key changes:

  • Added generateDebugFile function that creates SCLS files with randomly generated keys and CBOR-encoded values based on namespace specifications
  • Enhanced serialization infrastructure to support generic CBOR entries with existential type wrappers
  • Modified sorting logic to use key-based comparison instead of full value comparison for better flexibility

Reviewed Changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
scls-util/src/Cardano/SCLS/Util/Debug.hs New module providing debug file generation functionality with random data
scls-util/app/Main.hs Added CLI commands for debug utilities, changed subparser to hsubparser
scls-format/src/Cardano/SCLS/Internal/Entry.hs Added GenericCBOREntry and SomeCBOREntry types for handling CBOR entries generically
scls-format/src/Cardano/SCLS/Internal/Serializer/MemPack.hs Added ByteStringSized, CBORTerm, and consumeBytes utilities for generic serialization
scls-format/src/Cardano/SCLS/Internal/Serializer/Reference/Impl.hs Changed constraint from Ord a to Ord (Key a) and updated sorting to use key-based comparison
scls-format/src/Cardano/SCLS/Internal/Serializer/External/Impl.hs Updated constraints and refactored sorting logic into finalizeVector helper
scls-util/scls-util.cabal Added dependencies: cborg, cuddle, random, scls-cddl
scls-format/scls-format.cabal Added cborg dependency

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.


{- | Generate a scls file with random data for debugging purposes.
Keys and values are deterministic pseudo-random hex strings derived from
Copy link

Copilot AI Nov 3, 2025

Choose a reason for hiding this comment

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

The documentation claims keys and values are 'deterministic pseudo-random hex strings', but the implementation uses uniformByteStringM with globalStdGen (line 76), which is not deterministic across runs, and the values are CBOR terms generated from the cuddle spec (line 77), not hex strings.

Copilot uses AI. Check for mistakes.
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