Skip to content

feat(stdlib): add ecrecover() and normalizeECDSARecoveryId() functions #2774

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

i582
Copy link
Member

@i582 i582 commented Apr 14, 2025

Issue

Closes #2733.

Checklist

  • I have updated CHANGELOG.md
  • I have documented my contribution in docs/ and made the build locally
  • I have added tests to demonstrate the contribution is correctly implemented: this usually includes both positive and negative tests, showing the happy path(s) and featuring intentionally broken cases

@i582 i582 requested a review from a team as a code owner April 14, 2025 11:59
@novusnota novusnota added this to the v1.6.6 milestone Apr 14, 2025
@novusnota
Copy link
Member

Do we want tests for this? :)

Copy link
Member

@anton-trunov anton-trunov left a comment

Choose a reason for hiding this comment

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

Tests needed :)

@novusnota novusnota self-requested a review April 14, 2025 12:30
@@ -180,6 +180,56 @@ sha256(someVariableElsewhere); // will try to resolve at compile-time,

:::

## normalizeECDSARecoveryId
Copy link
Contributor

Choose a reason for hiding this comment

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

Abbreviations in camelcase must be capitalized as regular words, i.e. normalizeEcdsaRecoveryId

///
/// Note: This function uses the TVM `ECRECOVER` instruction and therefore requires `v` to
/// be already normalized with [`normalizeECDSARecoveryId()`](#normalizeecdsarecoveryid).
asm fun ecrecover(hash: Int, v: Int, r: Int, s: Int): EcrecoverKey? {
Copy link
Contributor

Choose a reason for hiding this comment

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

We shouldn't name functions in standard library after assembly instructions. ECRECOVER is a misnomer, as we're not recovering elliptic cryptography with it.

Copy link
Member

@novusnota novusnota Apr 14, 2025

Choose a reason for hiding this comment

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

There's a builtin ecrecover() function in Solidity, and people know that ecrecover and reference it elsewhere.

image

But I agree that we might need to change the name since ECRECOVER on TON does a slightly different thing

@anton-trunov anton-trunov removed this from the v1.6.6 milestone Apr 16, 2025
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.

Add stdlib function for ECRECOVER
4 participants