Skip to content

Feat/ed25519-verify#7196

Open
rob-stacks wants to merge 12 commits into
stacks-network:pox-wf-integrationfrom
rob-stacks:feat/ed25519-verify
Open

Feat/ed25519-verify#7196
rob-stacks wants to merge 12 commits into
stacks-network:pox-wf-integrationfrom
rob-stacks:feat/ed25519-verify

Conversation

@rob-stacks
Copy link
Copy Markdown
Contributor

@rob-stacks rob-stacks commented May 11, 2026

Description

This patch adds the ed25519-verify clarity function as well as an infrastructure for ed25519 curves.

(ed25519-verify 0x68656c6c6f20776f726c64 0x7e8346b0d9ef1151608df9d436c646b9df23758b292e0df400032f2603417724a25997d81a95a8997a55252813589b9409893df1ec75249a5b6f38753232810e 0xec172b93ad5e563bf49683c1397357b1af93d4e937abda610c10ccc6112217c0)

It expects "(buff 1024), (buff 64), (buff 32)" and returns bool (if the signature is verified)

The message buffer can be between 0 and 1024 bytes.

The signature is 64 bytes.

The public key is 32 bytes.

Cost has been profiled to 7880 units and veries very little based on the size of the message (can be between 0 and 1024) so probably it could be kept as fixed and not linear as soon as the clarity6 costs table is pushed.

Applicable issues

  • fixes #

Additional info (benefits, drawbacks, caveats)

Checklist

  • Test coverage for new or modified code paths
  • For new Clarity features or consensus changes, add property tests (see docs/property-testing.md)
  • Changelog fragment(s) or "no changelog" label added (see changelog.d/README.md)
  • Required documentation changes (e.g., rpc/openapi.yaml for RPC endpoints, event-dispatcher.md for new events)
  • New clarity functions have corresponding PR in clarity-benchmarking repo

@rob-stacks rob-stacks marked this pull request as ready for review May 11, 2026 13:45
@coveralls
Copy link
Copy Markdown

coveralls commented May 11, 2026

Coverage Report for CI Build 26276018838

Coverage decreased (-38.4%) to 47.571%

Details

  • Coverage decreased (-38.4%) from the base build.
  • Patch coverage: 240 uncovered changes across 13 files (0 of 240 lines covered, 0.0%).
  • 88560 coverage regressions across 344 files.

Uncovered Changes

Top 10 Files by Coverage Impact Changed Covered %
stacks-common/src/util/ed25519.rs 156 0 0.0%
clarity/src/vm/functions/crypto.rs 50 0 0.0%
clarity/src/vm/analysis/type_checker/v2_1/natives/mod.rs 12 0 0.0%
clarity/src/vm/costs/costs_1.rs 3 0 0.0%
clarity/src/vm/costs/costs_2.rs 3 0 0.0%
clarity/src/vm/costs/costs_2_testnet.rs 3 0 0.0%
clarity/src/vm/costs/costs_3.rs 3 0 0.0%
clarity/src/vm/costs/costs_4.rs 3 0 0.0%
clarity/src/vm/costs/costs_5.rs 3 0 0.0%
clarity/src/vm/analysis/arithmetic_checker/mod.rs 1 0 0.0%

Coverage Regressions

88560 previously-covered lines in 344 files lost coverage.

Top 10 Files by Coverage Loss Lines Losing Coverage Coverage
stackslib/src/chainstate/stacks/db/transactions.rs 8105 7.51%
stackslib/src/chainstate/stacks/db/blocks.rs 4478 35.57%
stackslib/src/chainstate/stacks/transaction.rs 4313 9.87%
stackslib/src/chainstate/burn/db/sortdb.rs 4193 42.89%
stackslib/src/chainstate/stacks/boot/mod.rs 3564 13.75%
stackslib/src/net/chat.rs 3146 27.62%
stackslib/src/chainstate/burn/operations/leader_block_commit.rs 2580 18.78%
stackslib/src/net/db.rs 1960 28.99%
stacks-signer/src/signerdb.rs 1578 35.21%
stackslib/src/chainstate/stacks/index/test/node.rs 1317 0.0%

Coverage Stats

Coverage Status
Relevant Lines: 220740
Covered Lines: 105008
Line Coverage: 47.57%
Coverage Strength: 13025160.57 hits per line

💛 - Coveralls

Comment thread clarity/src/vm/docs/mod.rs Outdated
Comment thread clarity/src/vm/docs/mod.rs Outdated
Comment thread stacks-common/src/util/ed25519.rs Outdated
args: &[SymbolicExpression],
context: &TypingContext,
) -> Result<TypeSignature, StaticCheckError> {
check_argument_count(3, args)?;
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.

Same comment from #7187: If #7179 merges before this, it could use the new functions described #7179 (comment).

) -> Result<Value, VmExecutionError> {
// (ed25519-verify message signature public-key)
// message: (buff MAX_VALUE_SIZE), signature: (buff 64), public-key: (buff 32)
check_argument_count(3, args)?;
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.

If #7179 merges before this, it could use the new functions described #7179 (comment).

// message: (buff MAX_VALUE_SIZE), signature: (buff 64), public-key: (buff 32)
check_argument_count(3, args)?;

runtime_cost(ClarityCostFunction::Ed25519verify, exec_state, 0)?;
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 think this should pass in the message length.

Comment thread stacks-common/src/util/ed25519.rs Outdated
Comment thread clarity/src/vm/tests/crypto.rs
SpecialFunction("native_secp256r1-verify", &crypto::special_secp256r1_verify)
}
Ed25519Verify => {
SpecialFunction("native_ed25519-verify", &crypto::special_ed25519_verify)
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.

To steal Aaron's comment from my PR, could this be implemented with a NativeFunction205 instead of a SpecialFunction?

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented May 20, 2026

CLA assistant check
All committers have signed the CLA.

@jbencin-stacks
Copy link
Copy Markdown
Contributor

I was updating the Clarity 6 SIP draft (stacksgov/sips#267) with this function, and noticed that example you use in the PR description and docs is invalid:

(ed25519-verify
  0x68656c6c6f20776f726c64 
  0x7e8346b0d9ef1151608df9d436c646b9df23758b292e0df400032f2603417724a25997d81a95a8997a55252813589b9409893df1ec75249a5b6f38753232810e
  0xec172b93ad5e563bf49683c1397357b1af93d4e937abda610c10ccc6112217c0
)

You can see for yourself here: https://cyphr.me/ed25519_tool/ed.html

We should make sure this example fails in the unit tests, and we should use the official test vectors from RFC 8032 (link) in our docs instead, and make sure we have them as part of our unit tests

@rob-stacks
Copy link
Copy Markdown
Contributor Author

@jbencin-stacks examples updated and added a test for all of the rfc-provided vectors (i added more tests for non-conforming cases too)

Secp256r1Verify => "(secp256r1-verify 0xc3abef6a775793dfbc8e0719e7a1de1fc2f90d37a7912b1ce8e300a5a03b06a8 0xf2b8c0645caa7250e3b96d633cf40a88456e4ffbddffb69200c4e019039dfd310eac59293c23e6d6aa8b0c5d9e4e48fa4c4fdf1ace2ba618dc0263b5e90a0903 0x031e18532fd4754c02f3041d9c75ceb33b83ffd81ac7ce4fe882ccb1c98bc5896e)",
VerifyMerkleProof => "(verify-merkle-proof 0x0000000000000000000000000000000000000000000000000000000000000000 0x0000000000000000000000000000000000000000000000000000000000000000 u0 u1 (list))",
GetBitcoinTxOutput => "(get-bitcoin-tx-output? 0x0100000001000000000000000000000000000000000000000000000000000000000000000000000000ffffffff01e80300000000000016001400000000000000000000000000000000000000000000000000 u0)",
Ed25519Verify => "(ed25519-verify 0x68656c6c6f20776f726c64 0x7e8346b0d9ef1151608df9d436c646b9df23758b292e0df400032f2603417724a25997d81a95a8997a55252813589b9409893df1ec75249a5b6f38753232810e 0xec172b93ad5e563bf49683c1397357b1af93d4e937abda610c10ccc6112217c0)",
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.

We are still using the invalid signature here (and in the PR description). Is this intentional?

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.

5 participants