-
Notifications
You must be signed in to change notification settings - Fork 262
Fix: wrong order of r-s-v concatenation for full signature; supplemented the explanation of v value during concatenation. #525
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
base: master
Are you sure you want to change the base?
Conversation
docs/mechanism-algorithm/account.md
Outdated
| * **Calculate the `r` value**: Randomly generate a temporary private key `k`, calculate the temporary public key `K = k × G` (`G`: curve base point), `r = K_x mod n`, that is, the abscissa of `K` modulo `n`, where `n` is the curve order (`n` and `G` satisfy `n × G = O`, and `O` is the zero point of the elliptic curve group on the finite field). `r` is 32 bytes. | ||
| * **Calculate the `s` value**: First calculate the modular inverse of the temporary private key `k` with respect to n, `k⁻¹`, that is, `k⁻¹` satisfies `k⁻¹ × k = 1 mod n`, then calculate the `s` value through the transaction's `hash`, the user's private key `d`, and the `r` value, `s = (k⁻¹ × (hash + d × r)) mod n`. `s` is 32 bytes. | ||
| * **Calculate the `v` value**: The `v` value is the recovery identifier. Since the `r` value undergoes a modulo operation and the symmetry of the elliptic curve, if there is only the `r` value, one `r` can recover up to four `K`s. The value range of `v` is four integers: `0, 1, 2, 3`. Historically, to be consistent with Ethereum, the final `v` value will be 27 added to `0, 1, 2, 3`, that is, the final value range of `v` is `27, 28, 29, 30`. With a determined `v`, the unique `K` can be recovered. `v` is 1 byte. | ||
| * **Calculate the `v` value**: Calculate the `recoveryId` first. Since the `r` value undergoes a modulo operation and the symmetry of the elliptic curve, if there is only the `r` value, one `r` can recover up to four `K`s. The value range of `recoveryId` is `0, 1, 2, 3`. The calculation of `v` value depends on `recoveryId`, historically, to be consistent with Ethereum, the `v` value will be `27` added to `recoveryId`, that is, the value range of `v` is `27, 28, 29, 30`. With a determined `v`, the unique `K` can be recovered. `v` is 1 byte. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some grammar suggestions;
Calculate the v value: Calculate the recoveryId first. Since the r value undergoes a modulo operation and the symmetry of the elliptic curve,
->>>>
Calculate the v value: Calculate the recoveryId first. Due to the modulo operation on the 'r' value and the symmetry of the elliptic curve,
, historically, to be consistent with Ethereum,
->>>>
. Historically, to remain consistent with Ethereum,
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thx. These grammatical errors, including the ones mentioned below, have been corrected.
docs/mechanism-algorithm/account.md
Outdated
| * **Calculate the `v` value**: Calculate the `recoveryId` first. Since the `r` value undergoes a modulo operation and the symmetry of the elliptic curve, if there is only the `r` value, one `r` can recover up to four `K`s. The value range of `recoveryId` is `0, 1, 2, 3`. The calculation of `v` value depends on `recoveryId`, historically, to be consistent with Ethereum, the `v` value will be `27` added to `recoveryId`, that is, the value range of `v` is `27, 28, 29, 30`. With a determined `v`, the unique `K` can be recovered. `v` is 1 byte. | ||
|
|
||
| 4. Append the concatenated signature results `r`, `s`, `v` to the transaction, in the order `v || r || s`. | ||
| 4. Concatenate the values of `r`, `s`, and `recoveryId` or `r`, `s`, and `v` to obtain the complete signature. The concatenation order shall be `r || s || recoveryId` / `r || s || v`. At present, both the transaction signing in the official client `wallet-cli` and the block signing in `java-tron` (during block production by SRs) adopt the scheme of concatenating the `recoveryId`, i.e., `signature = r || s || recoveryId`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
4.Concatenate the values of r, s, and recoveryId or r, s, and v
->>>>
4.Concatenate the values of r, s, and recoveryId (or r, s, and v)
shall be r || s || recoveryId / r || s || v.
->>>>
is either r || s || recoveryId or r || s || v.
adopt the scheme of concatenating the recoveryId, i.e., signature = r || s || recoveryId.
->>>>
adopt the recoveryId scheme, i.e., signature = r || s || recoveryId.
vivian1912
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approved.
…add an additional note.