Skip to content

feat(signing): put in agreement with styleguide and port code samples to Tolk#2127

Open
aigerimu wants to merge 6 commits into
mainfrom
pr-closes-2116-sign
Open

feat(signing): put in agreement with styleguide and port code samples to Tolk#2127
aigerimu wants to merge 6 commits into
mainfrom
pr-closes-2116-sign

Conversation

@aigerimu
Copy link
Copy Markdown
Contributor

@aigerimu aigerimu commented Apr 23, 2026

closes #2116
closes #2126

Summary by CodeRabbit

  • Documentation
    • Rewrote signing guide into a step-by-step "How to sign messages" flow for clarity.
    • Clarified hashing vs fixed-size input guidance and cell reference constraints.
    • Reordered and renumbered verification/signing sequences for easier follow-through.
    • Updated verification examples to Tolk-style syntax and adjusted method naming.
    • Simplified TypeScript setup (Node.js LTS) and labeled install as "Step 0".
    • Expanded mnemonic protection guidance and normalized terminology/capitalization.

@aigerimu aigerimu requested a review from a team as a code owner April 23, 2026 18:49
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 23, 2026

Warning

Rate limit exceeded

@aigerimu has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 6 minutes and 37 seconds before requesting another review.

To keep reviews running without waiting, you can enable usage-based add-on for your organization. This allows additional reviews beyond the hourly cap. Account admins can enable it under billing.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 5de64bc1-4e5a-4fa4-b399-10df734f37d6

📥 Commits

Reviewing files that changed from the base of the PR and between b71f7de and a7b5940.

📒 Files selected for processing (1)
  • contract-dev/techniques/signing.mdx
📝 Walkthrough

Walkthrough

Rewrites the "Signing messages" MDX page: restructures content into instructional sequences, converts FunC examples to Tolk with updated method calls, reorders verification methods, and adjusts wording/formatting throughout the document.

Changes

Cohort / File(s) Summary
Documentation: signing page
contract-dev/techniques/signing.mdx
Full rewrite of the signing guide: reorganized bullets into numbered steps; swapped CHKSIGNU/CHKSIGNS order; replaced FunC examples with Tolk equivalents and renamed hash methods (slice.hash(), cell.hash(), builder.hash() / b.hash()); refined explanations (hashing vs fixed-size inputs, cell reference constraints); normalized casing (key characteristics → lowercase); updated install/prereq and mnemonic protection wording; rephrased wallet interaction examples and gas/optimization notes.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested reviewers

  • novusnota

Poem

🐰 I hopped through docs with nimble paws,

turned FunC to Tolk without a pause.
Numbered steps and hashes neat,
CHKSIGs march in proper feet.
A little carrot, and the guide is sweet. 🥕

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title directly describes the main changes: aligning documentation with styleguide and converting code examples to Tolk language.
Linked Issues check ✅ Passed The PR successfully addresses both objectives from issue #2116: restructures content per styleguide guidelines and replaces FunC code examples with Tolk equivalents.
Out of Scope Changes check ✅ Passed All changes are scoped to the signing.mdx file and directly support styleguide alignment and Tolk migration objectives with no unrelated modifications.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch pr-closes-2116-sign

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
Review rate limit: 0/1 reviews remaining, refill in 6 minutes and 37 seconds.

Comment @coderabbitai help to get the list of available commands and usage tips.

@mintlify
Copy link
Copy Markdown

mintlify Bot commented Apr 23, 2026

Preview deployment for your docs. Learn more about Mintlify Previews.

Project Status Preview Updated (UTC)
mintlify-ton-docs 🟢 Ready View Preview Apr 23, 2026, 6:52 PM

💡 Tip: Enable Workflows to automatically generate PRs for you.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Nitpick comments (1)
contract-dev/techniques/signing.mdx (1)

73-79: LanguageTool: repeated sentence openings.

In both Example 1 (Lines 75-79) and Example 2 (Lines 98-101), four consecutive steps start with "Wallet contract …". Consider varying the subject (e.g., "It verifies …", "Then checks seqno …") or merging tightly related steps to improve readability. Low priority.

Also applies to: 93-101

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@contract-dev/techniques/signing.mdx` around lines 73 - 79, The steps list
repeats the subject "Wallet contract" several times in both Example 1 and
Example 2; update the step wording to improve flow by varying sentence openings
or merging closely related steps: for instance, change some "Wallet contract
verifies the signature." to "It verifies the signature.", merge "Wallet contract
checks seqno for replay protection." and "Wallet contract accepts the message
and pays gas..." into "It checks seqno for replay protection, accepts the
message, and pays gas from the wallet balance.", and/or reorder to combine
verification, seqno check and acceptance into one coherent step; apply similar
edits to the other example so the repeated "Wallet contract ..." phrasing is
reduced.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@contract-dev/techniques/signing.mdx`:
- Line 202: The sentence "This approach is used in preprocessed wallet v2,
highload wallet v3" is missing terminal punctuation; edit the line in
signing.mdx (the sentence text) to add a period (or other appropriate terminal
punctuation) at the end so it reads "This approach is used in preprocessed
wallet v2, highload wallet v3." and matches surrounding documentation style.
- Line 254: The sentence currently implies all TVM versions introduce builder
hashing; update the phrasing around `HASHBU` to align with the earlier "Recent
TVM versions" wording and, if possible, name the specific TVM release that added
`HASHBU` (e.g., "since TVM vX.Y.Z") or otherwise prefix with "Recent TVM
versions" and add a citation/reference; ensure the sentence mentions the
`HASHBU` instruction explicitly and clarifies that it is an optimization that
reduces gas cost by hashing builder data rather than treating it as a slice.
- Line 43: Edit the sentence in signing.mdx that states "consistent signing
time" for Ed25519; remove that phrase and rephrase to say Ed25519 signatures in
TON operate on hashes to ensure fixed-size input and to satisfy the 1016-bit /
ignored-refs limitation of CHKSIGNS (keep the existing CHKSIGNS explanation at
Line 61). Update the line mentioning Ed25519 so it only references fixed-size
input and the CHKSIGNS limitation, not timing implications.

---

Nitpick comments:
In `@contract-dev/techniques/signing.mdx`:
- Around line 73-79: The steps list repeats the subject "Wallet contract"
several times in both Example 1 and Example 2; update the step wording to
improve flow by varying sentence openings or merging closely related steps: for
instance, change some "Wallet contract verifies the signature." to "It verifies
the signature.", merge "Wallet contract checks seqno for replay protection." and
"Wallet contract accepts the message and pays gas..." into "It checks seqno for
replay protection, accepts the message, and pays gas from the wallet balance.",
and/or reorder to combine verification, seqno check and acceptance into one
coherent step; apply similar edits to the other example so the repeated "Wallet
contract ..." phrasing is reduced.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: dce42ec4-76a4-4105-bbc1-3ff11c4be72d

📥 Commits

Reviewing files that changed from the base of the PR and between 1f92393 and 3ab6493.

📒 Files selected for processing (1)
  • contract-dev/techniques/signing.mdx

Comment thread contract-dev/techniques/signing.mdx Outdated
Comment thread contract-dev/techniques/signing.mdx Outdated
Comment thread contract-dev/techniques/signing.mdx Outdated
Comment thread contract-dev/techniques/signing.mdx
@github-actions
Copy link
Copy Markdown
Contributor

Thanks for the updates to contract-dev/techniques/signing.mdx: there are a couple of suggestions to better align the how-to structure and prerequisites, so please apply the inline suggestions.


Per-comment submission: 1 posted, 1 failed.

Unposted inline comments (raw text):

  • contract-dev/techniques/signing.mdx:L281-L289

    [HIGH] Prerequisites under-specify required TypeScript environment and TON packages

    The TypeScript how-to section shows usage of @ton/core and @ton/crypto but the prerequisites list only mentions Node.js. This omits the need for a configured TypeScript environment and the specific TON packages, which can cause confusion or failures when readers run the examples without having the necessary tooling installed. Making these prerequisites explicit and concrete (with clear software items and installation steps) aligns with the style guidance for verifiable prerequisites.

    Please leave a reaction 👍/👎 to this suggestion to improve future reviews for everyone!

@aigerimu
Copy link
Copy Markdown
Contributor Author

/review

Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

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

Thanks for the improvements in contract-dev/techniques/signing.mdx: please apply the inline suggestion to keep the safety callout aligned with the documentation style.

Comment thread contract-dev/techniques/signing.mdx
@aigerimu aigerimu requested a review from Shvandre April 24, 2026 06:57
Comment thread contract-dev/techniques/signing.mdx Outdated
Comment thread contract-dev/techniques/signing.mdx Outdated
Comment thread contract-dev/techniques/signing.mdx Outdated
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

♻️ Duplicate comments (3)
contract-dev/techniques/signing.mdx (3)

61-61: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

cell references points to the wrong docs page.

This link targets the library-cell page, not general cell/reference behavior. Use the general cells page instead.

Suggested tweak
-Hash-based verification (`CHKSIGNU`) is preferred because `CHKSIGNS` only processes data from a single cell with a maximum size of 127 × 8 = 1016 bits and ignores [cell references](/foundations/serialization/library). For messages containing multiple cells or references, hashing the entire structure first is required.
+Hash-based verification (`CHKSIGNU`) is preferred because `CHKSIGNS` only processes data from a single cell with a maximum size of 127 × 8 = 1016 bits and ignores [cell references](/foundations/serialization/cells). For messages containing multiple cells or references, hashing the entire structure first is required.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@contract-dev/techniques/signing.mdx` at line 61, Update the markdown link
labeled "cell references" in the sentence referencing CHKSIGNU and CHKSIGNS so
it points to the general cells documentation page instead of the library-cell
page; locate the line mentioning "cell references" near the CHKSIGNU/CHKSIGNS
explanation and replace the current target URL with the general cells page URL
while keeping the link text unchanged.

2-3: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Sidebar label is still not action-oriented for a how-to page.

The title is task-based, but sidebarTitle: "Signing messages" is still noun-form. Prefer an action label for consistency with how-to navigation.

Suggested tweak
 title: "How to sign messages"
-sidebarTitle: "Signing messages"
+sidebarTitle: "Sign messages"
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@contract-dev/techniques/signing.mdx` around lines 2 - 3, The sidebarTitle
frontmatter is noun-form and should be action-oriented to match the how-to
title; update the sidebarTitle field (sidebarTitle: "Signing messages") to an
imperative/action label such as "Sign messages" or "How to sign messages" in the
file's frontmatter so the sidebar reads as a task — edit the sidebarTitle value
accordingly to maintain consistency with the page title.

195-195: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

HASHBU availability should name the exact TVM version consistently.

Line 195 says “Recent TVM versions,” while Line 254 says “TVM versions introduce...”. Since this was explicitly being clarified, use a concrete version (TVM v12) in both places.

Suggested tweak
-  Recent TVM versions support `builder.hash()` for efficient hashing. [Convert the slice to a builder and hash it](`#optimization-builder-hashing`) — this costs less than 100 gas total.
+  Starting with TVM v12, `builder.hash()` is available for efficient hashing. [Convert the slice to a builder and hash it](`#optimization-builder-hashing`) — this costs less than 100 gas total.
-TVM versions introduce builder hashing through the `HASHBU` instruction. This optimization reduces the gas cost of the signed data as a slice approach.
+Starting with TVM v12, builder hashing is available through the `HASHBU` instruction. This optimization reduces the gas cost of the "signed data as slice" approach.
In ton-blockchain/ton GlobalVersions.md, which TVM version introduced HASHBU, and what wording is best to document its availability in user docs?

Also applies to: 254-254

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@contract-dev/techniques/signing.mdx` at line 195, Replace the vague phrasing
that says “Recent TVM versions” and “TVM versions introduce...” with the
concrete version that introduced HASHBU: use “TVM v12” in both occurrences;
specifically edit the sentences mentioning builder.hash() and HASHBU (e.g., the
line referencing builder.hash() and the later sentence about TVM introducing
HASHBU) to read that HASHBU is available since TVM v12 so the doc consistently
names the exact version.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Duplicate comments:
In `@contract-dev/techniques/signing.mdx`:
- Line 61: Update the markdown link labeled "cell references" in the sentence
referencing CHKSIGNU and CHKSIGNS so it points to the general cells
documentation page instead of the library-cell page; locate the line mentioning
"cell references" near the CHKSIGNU/CHKSIGNS explanation and replace the current
target URL with the general cells page URL while keeping the link text
unchanged.
- Around line 2-3: The sidebarTitle frontmatter is noun-form and should be
action-oriented to match the how-to title; update the sidebarTitle field
(sidebarTitle: "Signing messages") to an imperative/action label such as "Sign
messages" or "How to sign messages" in the file's frontmatter so the sidebar
reads as a task — edit the sidebarTitle value accordingly to maintain
consistency with the page title.
- Line 195: Replace the vague phrasing that says “Recent TVM versions” and “TVM
versions introduce...” with the concrete version that introduced HASHBU: use
“TVM v12” in both occurrences; specifically edit the sentences mentioning
builder.hash() and HASHBU (e.g., the line referencing builder.hash() and the
later sentence about TVM introducing HASHBU) to read that HASHBU is available
since TVM v12 so the doc consistently names the exact version.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 84d6132c-38f3-43ba-a5c7-d58f3f61af18

📥 Commits

Reviewing files that changed from the base of the PR and between 3ab6493 and b71f7de.

📒 Files selected for processing (1)
  • contract-dev/techniques/signing.mdx

@aigerimu aigerimu marked this pull request as ready for review April 30, 2026 16:01
Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

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

Thanks for the improvements in contract-dev/techniques/signing.mdx: I’ve left a couple of suggestions to align the main heading and prerequisites with the documented How-to style, so please apply the inline suggestions.

Comment thread contract-dev/techniques/signing.mdx Outdated
Comment thread contract-dev/techniques/signing.mdx
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Copy link
Copy Markdown
Collaborator

@kay-is kay-is left a comment

Choose a reason for hiding this comment

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

From the style perspective, it looks good to me.

I just suggested titles for the code listings, as this guide uses multiple programming languages.

However, I can't say anything about the translated code.

Schema — Wallet v3r2:
Schema for wallet v3r2:

```tlb
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
```tlb
```tlb title="TL-B"

```func
slice signature = in_msg_body~load_bits(512);
slice signed_data = in_msg_body; // Remaining data
```tolk
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
```tolk
```tolk title="Tolk"

Schema — Preprocessed Wallet v2:
Schema for preprocessed wallet v2:

```tlb
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
```tlb
```tlb title="TL-B"

```func
slice signature = in_msg_body~load_bits(512);
cell signed_data = in_msg_body~load_ref(); // Signed data as cell
```tolk
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
```tolk
```tolk title="Tolk"

Choose the structure based on the contract design (see [Message structure for signing](#message-structure-for-signing) above):
Choose the structure based on the contract design:

```typescript
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
```typescript
```typescript title="TypeScript"


Build the message data that will be signed:

```typescript
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
```typescript title="TypeScript"


Sign the hash of the signed data:

```typescript
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
```typescript title="TypeScript"


Generate a new mnemonic:

```typescript
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
```typescript title="TypeScript"


Load an existing mnemonic:

```typescript
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
```typescript title="TypeScript"

```func
slice signature = in_msg_body~load_bits(512);
slice signed_data = in_msg_body;
```tolk
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
```tolk
```tolk title="Tolk"

Comment on lines +177 to 183
```tolk
val signature = inMsgBody.loadBits(512);
val signedData = inMsgBody; // remaining data

int hash = slice_hash(signed_data); // 526 gas
throw_unless(35, check_signature(hash, signature, public_key));
val hash = signedData.hash();
assert (isSignatureValid(hash, signature, publicKey)) throw 35;
```
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.

in Tolk, loadBits and loadRef are mutating slice methods (mutate self), so they need the receiver to be var, not val. as written inMsgBody is unbound here, and if a reader pastes this body into a contract handler where inMsgBody is the typical immutable parameter, the snippet fails to compile. could we either declare inMsgBody explicitly or call it out?

same fix needed at lines 236-242 (loadRef) and at lines 258-265

Suggested change
```tolk
val signature = inMsgBody.loadBits(512);
val signedData = inMsgBody; // remaining data
int hash = slice_hash(signed_data); // 526 gas
throw_unless(35, check_signature(hash, signature, public_key));
val hash = signedData.hash();
assert (isSignatureValid(hash, signature, publicKey)) throw 35;
```
```tolk
var inMsgBody = in.body;
val signature = inMsgBody.loadBits(512);
val signedData = inMsgBody; // remaining data
val hash = signedData.hash();
assert (isSignatureValid(hash, signature, publicKey)) throw 35;

- [Node.js](https://nodejs.org/en/download/) 18 or later LTS

Install required packages:
### Step 0: Install dependencies
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.

Step 0 is unusual - step lists in other how-tos on the site start from Step 1.the existing Step 1 onwards shifts up by one? keeps the page consistent with patterns like the first-smart-contract tutorial where setup is step 1

Suggested change
### Step 0: Install dependencies
### Step 1: Install dependencies

and bump the labels at lines 291 (Step 1 -> Step 2), 317 (Step 2 -> Step 3), 329 (Step 3 -> Step 4), 347 (Step 4 -> Step 5), 358 (Step 5 -> Step 6)

| [BLS12-381](https://en.wikipedia.org/wiki/BLS_digital_signature) | Pairing-based operations for signature aggregation and zero-knowledge proofs. |
| [Ristretto255](https://en.wikipedia.org/wiki/Curve25519#Ristretto) | Prime-order group over Curve25519 for advanced cryptographic constructions. |

For details, see crypto instructions in [TVM instructions](/tvm/instructions).
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.

tiny: crypto instructions in [TVM instructions] says "instructions" twice in a row

Suggested change
For details, see crypto instructions in [TVM instructions](/tvm/instructions).
For details, see the [cryptographic primitives in TVM instructions](/tvm/instructions#cryptography).

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

Labels

None yet

Projects

None yet

3 participants