Skip to content

Commit 44c433f

Browse files
author
Docs Syncer
committed
CI: 2f855a5
1 parent b1bf0f1 commit 44c433f

File tree

1 file changed

+102
-8
lines changed

1 file changed

+102
-8
lines changed

docs/reference/contracts/libs/crypto/Schnorr256.md

Lines changed: 102 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ library Schnorr256
1010

1111
Cryptography module
1212

13-
This library provides functionality for Schnorr signature verification over any 256-bit curve.
13+
This library provides functionality for Schnorr signature verification over any 256-bit curve,
14+
together with secret extraction from a standard/adaptor Schnorr signature pair.
1415
## Errors info
1516

1617
### LengthIsNot64
@@ -27,6 +28,13 @@ error LengthIsNot96()
2728
```
2829

2930

31+
### InvalidSignatureScalar
32+
33+
```solidity
34+
error InvalidSignatureScalar()
35+
```
36+
37+
3038
## Functions info
3139

3240
### verify
@@ -40,14 +48,100 @@ function verify(
4048
) internal view returns (bool)
4149
```
4250

43-
The function to verify the Schnorr signature
51+
The function to verify the Schnorr signature.
4452

4553

4654
Parameters:
4755

48-
| Name | Type | Description |
49-
| :------------- | :----------------- | :---------------------------------------------------------------- |
50-
| ec | struct EC256.Curve | the 256-bit curve parameters. |
51-
| hashedMessage_ | bytes32 | the already hashed message to be verified. |
52-
| signature_ | bytes | the Schnorr signature. Equals to `bytes(R) + bytes(e)`. |
53-
| pubKey_ | bytes | the full public key of a signer. Equals to `bytes(x) + bytes(y)`. |
56+
| Name | Type | Description |
57+
| :------------- | :----------------- | :----------------------------------------------------------------- |
58+
| ec | struct EC256.Curve | the 256-bit curve parameters. |
59+
| hashedMessage_ | bytes32 | the already hashed message to be verified. |
60+
| signature_ | bytes | the Schnorr signature. Equals to `bytes(R) + bytes(e)`. |
61+
| pubKey_ | bytes | the full public key of a signer. Equals to `bytes(x) + bytes(y)`. |
62+
63+
64+
Return values:
65+
66+
| Name | Type | Description |
67+
| :--- | :--- | :----------------------------------------------- |
68+
| [0] | bool | True if the signature is valid, false otherwise. |
69+
70+
### adaptorVerify
71+
72+
```solidity
73+
function adaptorVerify(
74+
EC256.Curve memory ec,
75+
bytes32 hashedMessage_,
76+
bytes memory signature_,
77+
bytes memory pubKey_,
78+
EC256.APoint memory t_
79+
) internal view returns (bool)
80+
```
81+
82+
The function to verify the adaptor Schnorr signature.
83+
84+
The adaptor Schnorr signature is expected to be computed as:
85+
86+
c = H(P || (R + T) || m)
87+
e' = (r + c * privKey) mod n
88+
signature = (R, e')
89+
90+
91+
92+
Parameters:
93+
94+
| Name | Type | Description |
95+
| :------------- | :------------------ | :------------------------------------------------------------------------- |
96+
| ec | struct EC256.Curve | the 256-bit curve parameters. |
97+
| hashedMessage_ | bytes32 | the already hashed message to be verified. |
98+
| signature_ | bytes | The adaptor Schnorr signature. Equals to `bytes(R) + bytes(e′)`. |
99+
| pubKey_ | bytes | the full public key of a signer. Equals to `bytes(x) + bytes(y)`. |
100+
| t_ | struct EC256.APoint | the adaptor secret point added to the nonce in the challenge computation. |
101+
102+
103+
Return values:
104+
105+
| Name | Type | Description |
106+
| :--- | :--- | :------------------------------------------------------- |
107+
| [0] | bool | True if the adaptor signature is valid, false otherwise. |
108+
109+
### extract
110+
111+
```solidity
112+
function extract(
113+
EC256.Curve memory ec,
114+
bytes memory signature_,
115+
bytes memory adaptorSignature_
116+
) internal pure returns (uint256)
117+
```
118+
119+
The function to extract the adaptor secret from a pair of Schnorr signatures.
120+
121+
This function does not verify the validity of either signature.
122+
Callers are responsible for verifying both the standard and adaptor signatures
123+
separately via `verify` and `adaptorVerify` before extraction.
124+
125+
The standard Schnorr signature is expected to be computed from the adaptor one as:
126+
e = e' + t = (r + t + c * privKey) mod n
127+
signature = (R + T, e)
128+
129+
Secret extraction is performed as follows:
130+
t = (e - e') mod n
131+
132+
133+
134+
Parameters:
135+
136+
| Name | Type | Description |
137+
| :---------------- | :----------------- | :---------------------------------------------------------------- |
138+
| ec | struct EC256.Curve | the 256-bit curve parameters. |
139+
| signature_ | bytes | the Schnorr signature. Equals to `bytes(R + T) + bytes(e)`. |
140+
| adaptorSignature_ | bytes | the adaptor Schnorr signature. Equals to `bytes(R) + bytes(e')`. |
141+
142+
143+
Return values:
144+
145+
| Name | Type | Description |
146+
| :--- | :------ | :--------------------------------------- |
147+
| [0] | uint256 | The secret scalar used in the signature. |

0 commit comments

Comments
 (0)