Skip to content

feat: align HCS-27 with published draft#6

Merged
kantorcodes merged 7 commits intomainfrom
feat/hcs27-draft-alignment
Mar 20, 2026
Merged

feat: align HCS-27 with published draft#6
kantorcodes merged 7 commits intomainfrom
feat/hcs27-draft-alignment

Conversation

@kantorcodes
Copy link
Copy Markdown
Member

Summary

  • align the Go HCS-27 client with the published draft in feat: add hcs-27 transparency logs hiero-ledger/hiero-consensus-specifications#27
  • switch checkpoint treeSize fields to canonical decimal strings and update field names to rootHashB64u
  • remove the older batch_range dependency, require rfc9162, and add draft-shaped proof object helpers
  • update examples, docs, unit tests, and live integration fixtures for the new checkpoint envelope

Verification

  • go test ./pkg/hcs27/...
  • go test ./...
  • go test -run TestHCS27Integration ./pkg/hcs27 -v (skips in this shell because HEDERA_ACCOUNT_ID/HEDERA_PRIVATE_KEY are not exported)
  • RUN_INTEGRATION=1 go test -run TestHCS27Integration ./pkg/hcs27 -v (still skips here for the same missing exported credentials)

Draft deltas addressed

  • metadata.root.treeSize / metadata.prev.treeSize are canonical decimal strings
  • metadata.log.merkle is enforced as rfc9162
  • metadata.root.rootHashB64u / metadata.prev.rootHashB64u match the published field names
  • overflow payloads continue to use metadata as an HCS-1 reference plus optional metadata_digest
  • proof-object models now match the draft's off-ledger shapes

Signed-off-by: Michael Kantor <6068672+kantorcodes@users.noreply.github.com>
@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request refactors the HCS-27 client to conform to the latest draft specification. The primary goal is to standardize data representation and validation for checkpoint metadata, particularly by changing tree size fields to canonical string formats and updating hash field names. Additionally, it introduces new utilities for verifying proof objects, enhancing the client's capability to interact with the updated specification.

Highlights

  • Specification Alignment: The HCS-27 client has been updated to align with the latest published draft specification, ensuring compliance with evolving standards.
  • Data Type and Field Name Updates: Checkpoint treeSize fields are now represented as canonical decimal strings, and rootHashB64 fields have been renamed to rootHashB64u for consistency with the draft.
  • Removal of Batch Range: The batch_range dependency has been removed from the checkpoint metadata, simplifying the data structure.
  • Merkle Tree Standard Enforcement: The Merkle tree algorithm is now strictly enforced to use rfc9162.
  • Proof Object Helpers: New helper functions, VerifyInclusionProofObject and VerifyConsistencyProofObject, have been added to support draft-shaped proof objects.
  • Documentation and Test Updates: Examples, documentation, unit tests, and live integration fixtures have been updated to reflect these changes.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request successfully aligns the Go HCS-27 client with the published draft specification. Key changes include switching treeSize fields to canonical decimal strings, updating field names to rootHashB64u, removing the batch_range dependency, and enforcing rfc9162 for Merkle tree calculations. New helper functions for parsing canonical uint64 values from strings have been introduced, and proof object models now match the draft's off-ledger shapes. The changes are reflected across documentation, examples, and unit/integration tests, demonstrating a thorough update to the new specification.

I am having trouble creating individual review comments. Click here to see my feedback.

pkg/hcs27/types.go (27-28)

high

The TreeSize field in RootCommitment has been correctly updated from uint64 to string to align with the new specification requiring canonical decimal strings.

pkg/hcs27/validation_test.go (337-344)

high

The TestValidateMetadataTreeSizeCanonicalDecimal test is a valuable addition, specifically verifying that TreeSize values are canonical decimal strings, which is a new requirement in the specification.

pkg/hcs27/validation.go (127-129)

high

The validation logic for metadata.prev.treeSize now correctly compares the parsed uint64 values, ensuring previousTreeSize is not greater than rootTreeSize.

pkg/hcs27/client.go (412-418)

high

The introduction of parseCanonicalUint64 for metadata.root.treeSize is a critical change to correctly handle the new string representation of tree sizes. This ensures that the string is parsed into a uint64 for internal logic while validating its canonical format.

pkg/hcs27/client.go (431-437)

high

Similar to the root tree size, parseCanonicalUint64 is correctly applied to metadata.prev.treeSize to handle its string representation and validate its format. This is crucial for maintaining the integrity of the checkpoint chain validation.

pkg/hcs27/validation.go (120-123)

high

The metadata.prev.treeSize validation now correctly uses parseCanonicalUint64 to handle the string representation and ensure it's a valid canonical decimal string. This is a critical correctness improvement.

pkg/hcs27/validation.go (112-115)

high

The metadata.root.treeSize validation now correctly uses parseCanonicalUint64 to handle the string representation and ensure it's a valid canonical decimal string. This is a critical correctness improvement.

pkg/hcs27/integers.go (1-28)

high

The new integers.go file introduces parseCanonicalUint64 and canonicalUint64 functions. These are well-implemented helper functions that correctly handle the conversion and validation of canonical decimal string representations for uint64 values, which is essential for the updated HCS-27 specification.

pkg/hcs27/validation.go (109-110)

high

The validation for metadata.Log.Merkle has been correctly updated to explicitly enforce rfc9162, ensuring adherence to the new specification.

pkg/hcs27/types.go (56-73)

high

The addition of InclusionProof and ConsistencyProof structs is a significant improvement, providing structured types for handling proof objects as defined in the HCS-27 draft specification.

pkg/hcs27/types.go (32-33)

high

The TreeSize field in PreviousCommitment has been correctly updated from uint64 to string to align with the new specification requiring canonical decimal strings.

pkg/hcs27/merkle.go (135-157)

high

The new VerifyInclusionProofObject function correctly implements the verification logic for inclusion proofs based on the HCS-27 draft shape. It properly utilizes parseCanonicalUint64 for LeafIndex and TreeSize and validates TreeVersion.

pkg/hcs27/merkle.go (237-259)

high

The new VerifyConsistencyProofObject function correctly implements the verification logic for consistency proofs based on the HCS-27 draft shape. It properly utilizes parseCanonicalUint64 for OldTreeSize and NewTreeSize and validates TreeVersion.

pkg/hcs27/types.go (48)

medium

The BatchRange field has been removed from CheckpointMetadata, aligning with the updated specification.

pkg/hcs27/validation.go (127-131)

medium

The removal of BatchRange validation is consistent with the removal of the BatchRange struct from the metadata, streamlining the validation process.

pkg/hcs27/merkle_test.go (54-67)

medium

A new test case has been added for VerifyInclusionProofObject, which is crucial for ensuring the correctness of the newly introduced proof verification logic.

pkg/hcs27/integration_test.go (165-170)

medium

The overflow metadata in the integration test is updated to use rfc9162 for Merkle, canonicalUint64 for TreeSize, and RootHashB64u, ensuring consistency with the new specification.

pkg/hcs27/types.go (36-38)

medium

The BatchRange struct has been removed, which is consistent with the updated HCS-27 draft specification.

README.md (114-115)

medium

The example code in the README.md has been updated to reflect the new TreeSize as a string and the RootHashB64u field name, along with the removal of BatchRange. This is a good update to keep the documentation aligned with the latest specification.

pkg/hcs27/integration_test.go (92-101)

medium

The second checkpoint in the integration test also correctly reflects the updated Merkle algorithm, TreeSize as a canonical string, and RootHashB64u for both current and previous commitments.

pkg/hcs27/integration_test.go (63-68)

medium

The integration test for the first checkpoint correctly updates the Merkle algorithm to rfc9162, TreeSize to a canonical string using canonicalUint64, and RootHashB64u to match the new specification.

pkg/hcs27/doc.go (31)

medium

The example in the doc.go file has been updated to reflect the TreeSize as a string and the RootHashB64u field name, which is important for accurate documentation.

pkg/hcs27/validation.go (116-117)

medium

The field name RootHashB64 has been correctly updated to RootHashB64u in the validation logic, aligning with the specification.

pkg/hcs27/client_overflow_test.go (136-141)

medium

The test metadata has been updated to align with the new specification, using rfc9162 for Merkle, canonicalUint64 for TreeSize, and RootHashB64u. This ensures the overflow tests are run against the correct data structures.

pkg/hcs27/validation.go (124-125)

medium

The field name RootHashB64 has been correctly updated to RootHashB64u in the validation logic for previous commitments, aligning with the specification.

pkg/hcs27/client.go (399-400)

medium

The previousRecord struct has been updated to reflect the new RootHashB64u field name, ensuring consistency with the updated RootCommitment and PreviousCommitment types.

pkg/hcs27/merkle_test.go (85-98)

medium

A new test case has been added for VerifyConsistencyProofObject, which is crucial for ensuring the correctness of the newly introduced proof verification logic.

pkg/hcs27/validation_test.go (133-139)

medium

The buildValidMetadata helper function has been updated to reflect the new Leaf and Merkle values, TreeSize as a canonical string, and RootHashB64u field name, ensuring test data aligns with the specification.

pkg/hcs27/validation_test.go (226)

medium

The test case for invalid root hash has been updated to use RootHashB64u, correctly reflecting the field name change.

pkg/hcs27/validation_test.go (237-238)

medium

The test case for previous commitment now correctly uses canonicalUint64 for TreeSize and RootHashB64u for the hash, aligning with the updated types.

pkg/hcs27/validation_test.go (249-250)

medium

The test case for an invalid previous hash has been updated to use canonicalUint64 for TreeSize and RootHashB64u for the hash, ensuring the test targets the correct fields.

pkg/hcs27/validation_test.go (262-263)

medium

The test case for PreviousTreeSizeTooLarge now correctly uses canonicalUint64 for TreeSize and RootHashB64u for the hash, reflecting the updated types.

pkg/hcs27/validation_test.go (275-292)

medium

The removal of TestValidateMetadataBatchRangeInvalid and TestValidateMetadataBatchRangeEndExceedsTreeSize tests is appropriate, as the BatchRange struct has been removed from the specification.

examples/hcs27-publish-checkpoint/main.go (41-46)

medium

The example has been correctly updated to use rfc9162 for the Merkle algorithm, TreeSize as a string, and RootHashB64u as per the new specification. The removal of BatchRange is also consistent.

pkg/hcs27/validation_test.go (509-516)

medium

The ValidateCheckpointChain test cases have been updated to use canonicalUint64 for TreeSize and RootHashB64u for root hashes, ensuring they align with the new data types.

pkg/hcs27/validation_test.go (535-542)

medium

The ValidateCheckpointChainTreeSizeDecreased test case has been updated to use canonicalUint64 for TreeSize and RootHashB64u for root hashes, ensuring it aligns with the new data types.

pkg/hcs27/validation_test.go (561-567)

medium

The ValidateCheckpointChainMissingPrev test case has been updated to use canonicalUint64 for TreeSize and RootHashB64u for root hashes, ensuring it aligns with the new data types.

pkg/hcs27/validation_test.go (586-593)

medium

The ValidateCheckpointChainPrevTreeSizeMismatch test case has been updated to use canonicalUint64 for TreeSize and RootHashB64u for root hashes, ensuring it aligns with the new data types.

pkg/hcs27/validation_test.go (613-620)

medium

The ValidateCheckpointChainPrevRootHashMismatch test case has been updated to use canonicalUint64 for TreeSize and RootHashB64u for root hashes, ensuring it aligns with the new data types.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0bdacaa157

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@kilo-code-bot
Copy link
Copy Markdown

kilo-code-bot bot commented Mar 20, 2026

Code Review Summary

Status: 2 CRITICAL Issues Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 2
WARNING 0
SUGGESTION 0

Incremental Review (6c7815a437e4fd)

RESOLVED P2: The new commit fetches existing checkpoints before publishing, then waits for len(existingRecords)+2 records, fixing the race condition where the example could validate stale records from an existing topic.

Issue Details (UNRESOLVED)

CRITICAL

File Line Issue
pkg/hcs27/types.go 30 REGRESSION: Numeric treeSize decoding removed - The existing P1 comment asks to keep decoding numeric treeSize values, but the code removed the UnmarshalJSON functions that handled numeric treeSize. Checkpoints with "treeSize": 10 (numeric) will now fail to unmarshal entirely.
pkg/hcs27/validation.go 109 REGRESSION: Legacy merkle profile no longer accepted - The existing P1 comment asks to keep accepting the legacy merkle label (rfc6962) on reads, but validation only accepts "rfc9162". Checkpoints with "merkle": "rfc6962" will now be rejected.

Resolved Issues

File Line Resolution
examples/hcs27-publish-checkpoint/main.go 50-53, 125 RESOLVED - P2 issue fixed by fetching existing records and waiting for existing+2 records.
pkg/hcs27/merkle.go N/A RESOLVED - Added normalizeProofRootHash function that converts base64url to base64 before proof verification.

Files Reviewed (1 new file)

  • examples/hcs27-publish-checkpoint/main.go - Fixed P2 race condition issue

Signed-off-by: Michael Kantor <6068672+kantorcodes@users.noreply.github.com>
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6c629f75cb

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Signed-off-by: Michael Kantor <6068672+kantorcodes@users.noreply.github.com>
Signed-off-by: Michael Kantor <6068672+kantorcodes@users.noreply.github.com>
Signed-off-by: Michael Kantor <6068672+kantorcodes@users.noreply.github.com>
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: cafd0019aa

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Signed-off-by: Michael Kantor <6068672+kantorcodes@users.noreply.github.com>
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6c7815ab4c

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Signed-off-by: Michael Kantor <6068672+kantorcodes@users.noreply.github.com>
@kantorcodes kantorcodes merged commit 2a9097a into main Mar 20, 2026
12 checks passed
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.

1 participant