Skip to content

[Peras 25.5] Introduce Bytes32RealPoint#2033

Open
agustinmista wants to merge 1 commit into
mainfrom
peras/bytes32realpoint
Open

[Peras 25.5] Introduce Bytes32RealPoint#2033
agustinmista wants to merge 1 commit into
mainfrom
peras/bytes32realpoint

Conversation

@agustinmista
Copy link
Copy Markdown
Contributor

This PR introduces a specialization of RealPoint for blocks where the header hash is always 32 bytes long.

@agustinmista agustinmista self-assigned this May 7, 2026
@agustinmista agustinmista marked this pull request as ready for review May 7, 2026 08:39
@agustinmista agustinmista force-pushed the peras/bytes32realpoint branch from 6b1337f to 0dfc5c8 Compare May 7, 2026 11:17
RealPoint blk ->
Bytes32RealPoint
toBytes32RealPoint (RealPoint s h) =
assert (ByteString.length (coerce h) == 32) $
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I am not sure this is how it should be. I think this is unsafe as assertions are not checked in production

Copy link
Copy Markdown
Contributor Author

@agustinmista agustinmista May 7, 2026

Choose a reason for hiding this comment

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

I would have expected this to be an invariant for any blk such that:

type instance HeaderHash blk = ShortByteString

But if that's not the case I guess we will need to deal with the partial conversion more explicitly.

Would you prefer this to be discharged with a Maybe or with an error?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

IIRC:

  • For any blk of a concrete era (OneEra x); or the HardForkBlock xs, HeaderHash blk is semantically isomorphic to a 32-byte bytestring, but it can take slightly more compact forms (e.g. 4 Word64 zipped together for some eras)
  • For other blks (e.g. TestBlock), we can't make any assumption on the shape of HeaderHash blk

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks @tbagrel1 for the extra context.

FTR: we still need to decide how to discharge errors when coercing from a (potentially) non-32bytes-long ShortByteString into Bytes32RealPoint, as this is not captured at the type level.

What we need to address concretely here is whether we:

  1. Capture this with a Maybe and let the client code (likely the HFC?) handle it.
  2. Assume it can't happen and put an error for the impossible case.
  3. Assume it can't happen and wrap the expression with an assertion.
  4. Something else?

Then (1) and (2) will come with some minor performance penalty (length check and optionally wrapping on Maybe) that we can avoid if we already know that forall blk. Coercible (HeaderHash blk) ShortByteString implies len(header_hash) == 32 in any production context where this function could be invoked. On the other hand (3) should have no performance penalty in production, while still being able to detect issues in testing.

I'm OK with any of these approaches, but I would like to hear back from @jasagredo before making any change :)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@jasagredo

Hey we just discussed this with @agustinmista, and here's a more refined context/question:

  1. We will only convert from (Real)Point blk to Bytes32RealPoint in contexts in which it's morally safe to do it; that is, for blk of a concrete era or the HardForkBlock. So ideally the conversion functions should probably NOT return a Maybe (to avoid having to deal with impossible cases at call site). Do you agree?
  2. Is it ok to assume that OneEra blk or AllEra blks (For HardForkBlock blks) are the right classes that carry the moral invariant that a header hash carries 32 bytes of information? If not, what would be the right class?
  3. If the previous one is correct, would it be ok to create a conversion class from (Real)Point blk to Bytes32RealPoint and add it as a superclass constraint for OneEra blk ? This way I think it would be easier to implement the converter for the different concrete shape of 32-bytes headerhash (e.g. Bytestring, 4 Word64s, etc)

@agustinmista agustinmista force-pushed the peras/bytes32realpoint branch from 0dfc5c8 to eb09af0 Compare May 11, 2026 08:37
@agustinmista agustinmista changed the base branch from main to peras/voting-committee-tests May 11, 2026 08:38
@agustinmista agustinmista changed the title Introduce Bytes32RealPoint [Peras 22.5] Introduce Bytes32RealPoint May 11, 2026
@agustinmista agustinmista changed the title [Peras 22.5] Introduce Bytes32RealPoint [Peras 25.5] Introduce Bytes32RealPoint May 11, 2026
@agustinmista agustinmista force-pushed the peras/bytes32realpoint branch from eb09af0 to 4fd81d9 Compare May 13, 2026 12:01
@agustinmista agustinmista force-pushed the peras/voting-committee-tests branch from 5236102 to ed23ba7 Compare May 13, 2026 12:01
@agustinmista agustinmista requested a review from jasagredo May 18, 2026 06:55
@agustinmista agustinmista force-pushed the peras/bytes32realpoint branch from 4fd81d9 to e204347 Compare May 19, 2026 08:27
@agustinmista agustinmista force-pushed the peras/voting-committee-tests branch from ed23ba7 to f47566d Compare May 19, 2026 08:27
This commit introduces a specialization of RealPoint for blocks where
the header hash is always 32 bytes long.
@agustinmista agustinmista force-pushed the peras/bytes32realpoint branch from e204347 to 186331b Compare May 19, 2026 13:46
@agustinmista agustinmista force-pushed the peras/voting-committee-tests branch from f47566d to f8288a3 Compare May 19, 2026 13:46
Base automatically changed from peras/voting-committee-tests to main May 19, 2026 15:56
@agustinmista
Copy link
Copy Markdown
Contributor Author

Hey @jasagredo! ✋

Do you think you could take a look at the remaining comment on this PR? This is currently blocking Peras 26 from being merged 😅

Thanks in advance!

CC @dnadales in case you have time to chime in instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement monomorphic (32byte long) real points

3 participants