Skip to content
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

ECRECOVER precompiled contract should have stayed unaffected by EIP155 changes #305

Merged
merged 1 commit into from
Apr 23, 2018

Conversation

pirapira
Copy link
Member

@pirapira pirapira commented Apr 25, 2017

Before this PR, the definition of ECREC precompiled contract seemed to have changed during Homestead changes. The Homestead changes involved stricter checks on the signature, and on the Yellow Paper, that change also affected the recovering precompiled contract. However, the precompiled contract did not change in the implementations. I think it's about EIP155 replay protection. EIP155 should not change the ECDSARECOVER precompiled contract.

@pirapira pirapira changed the title ECRECOVER precompiled contract should stayed same during Homestead ECRECOVER precompiled contract should have stayed unaffected by Homestead changes Jul 14, 2017
@pirapira
Copy link
Member Author

Maybe this should be merged into homestead and then merged into more recent versions.

Paper.tex Outdated
@@ -1418,6 +1418,13 @@ \section{Signing Transactions}\label{app:signing}
%\mathtt{\tiny secp256k1p} &= 2^{256} - 2^{32} - 977\\
\end{align}

Note that $\mathtt{\small ECDSARECOVER}$ function does not follow the distinction of valid or invalid transactions defined here. $\mathtt{\small ECDSARECOVER}$ returns non-empty results if the following conditions are met (this is relevant in the definition of $\Xi_{\mathtt{ECREC}}$).
Copy link
Contributor

@jamesray1 jamesray1 Feb 21, 2018

Choose a reason for hiding this comment

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

Note that the ECDSARECOVER function... defined above ... definition of the precompile ...

Copy link
Member Author

Choose a reason for hiding this comment

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

What do you mean?

Copy link
Contributor

Choose a reason for hiding this comment

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

These are proposed edits.

Note that the $\mathtt{\small ECDSARECOVER}$ function does not follow the distinction of valid or invalid transactions defined above. $\mathtt{\small ECDSARECOVER}$ returns non-empty results if the following conditions are met (this is relevant in the definition of the precompile $\Xi_{\mathtt{ECREC}}$).

Copy link
Member Author

Choose a reason for hiding this comment

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

That looks better. I'll modify my branch.

Paper.tex Outdated
Note that $\mathtt{\small ECDSARECOVER}$ function does not follow the distinction of valid or invalid transactions defined here. $\mathtt{\small ECDSARECOVER}$ returns non-empty results if the following conditions are met (this is relevant in the definition of $\Xi_{\mathtt{ECREC}}$).
\begin{align}
0 < r &< \mathtt{\tiny secp256k1n} \\
0 < s &< \mathtt{\tiny secp256k1n} \\
Copy link
Contributor

Choose a reason for hiding this comment

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

Get rid of tiny.

Paper.tex Outdated
\begin{align}
0 < r &< \mathtt{\tiny secp256k1n} \\
0 < s &< \mathtt{\tiny secp256k1n} \\
v &\in \{27,28\}
Copy link
Contributor

@jamesray1 jamesray1 Feb 21, 2018

Choose a reason for hiding this comment

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

At first impression this seems to conflict with EIP-155 and https://ethereum.github.io/yellowpaper/paper.pdf#v. Wait a minute, I'm still checking.

Copy link
Contributor

@jamesray1 jamesray1 Feb 21, 2018

Choose a reason for hiding this comment

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

On an unrelated note to this PR but a correction in the section that I just linked to, you may also notice "These are formally defined in the literature, e.g. by ?." #630 should fix that.

Copy link
Contributor

Choose a reason for hiding this comment

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

Would be good to add to the build script to pick up Latex errors.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think I understand the conflict. Following are the two definitions of an invalid signature.

screenshot from 2018-02-21 19-28-07

screenshot from 2018-02-21 19-29-26

Copy link
Contributor

Choose a reason for hiding this comment

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

Wouldn't it also be good to update the implementations and the first of the above?

Copy link
Contributor

Choose a reason for hiding this comment

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

Noticed something else: #632.

Copy link
Contributor

Choose a reason for hiding this comment

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

Wouldn't it be better to update the EIP draft, implementations and then this paper for the first screenshot with the ECREC precompile so that an invalid signature is defined in accordance with the second screenshot in Appendix F?

Copy link
Member Author

Choose a reason for hiding this comment

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

That will be a hardfork, so, there needs to be a separate EIP proposing the fix.

Copy link
Contributor

@jamesray1 jamesray1 Feb 21, 2018

Choose a reason for hiding this comment

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

Copy link
Contributor

@jamesray1 jamesray1 left a comment

Choose a reason for hiding this comment

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

Left several comments.

@ldct
Copy link
Contributor

ldct commented Mar 27, 2018

LGTM. It is unfortunate that 2 different conditions for valid ECDSA verification need to be used.

@pirapira pirapira force-pushed the precompiled-ecrecover-unchanged branch from dd5edda to 601202f Compare April 3, 2018 13:21
@pirapira
Copy link
Member Author

pirapira commented Apr 3, 2018

@jamesray1 fixed my wording.

@pirapira
Copy link
Member Author

@nicksavers pointed out that, this PR explains ECRECOVER precompiled as some modification of transaction signing, but it should be the other way around. The transaction signature checking (considering replay attack prevention) should be a more complicated variant of ECRECOVER operation (that's used in the ECRECOVER precompiled). I agree with this pereference.

@pirapira
Copy link
Member Author

Since YP delegates the definition of ECRECOVER to a paper by Johnson, Menezes and Vanstone, I have to see first which v does the original ECRECOVER accept.

@pirapira
Copy link
Member Author

But this document explains signature generation and verification, not the recovery of the public key. I created an issue about that #688 . For this PR I assume that the original ECDSA doesn't care about the chain IDs.

@pirapira
Copy link
Member Author

@pirapira pirapira changed the title ECRECOVER precompiled contract should have stayed unaffected by Homestead changes [wip] ECRECOVER precompiled contract should have stayed unaffected by Homestead changes Apr 20, 2018
@pirapira
Copy link
Member Author

And also, the values except 27 and 28 should not appear https://github.com/ethereum/yellowpaper/pull/305/files#diff-9f702e1491c55da9d76a68d651278764R1711. They have to wait until we see signed transactions.

Before this PR, the definition of ECREC precompiled contract seemed to have changed during Homestead changes.  The Homestead changes involved stricter checks on the signature, and on the Yellow Paper, that change also affected the recovering precompiled contract.  However, the precompiled contract did not change in the implementations.
@pirapira pirapira force-pushed the precompiled-ecrecover-unchanged branch from 601202f to f2fd7a6 Compare April 20, 2018 14:40
@pirapira pirapira changed the title [wip] ECRECOVER precompiled contract should have stayed unaffected by Homestead changes ECRECOVER precompiled contract should have stayed unaffected by Homestead changes Apr 20, 2018
@pirapira
Copy link
Member Author

@nicksavers this should be better now.

@pirapira
Copy link
Member Author

pirapira commented Apr 20, 2018

Ah wait, I think this is still somehow wrong. So the precompiled contract should not check the value of v so strictly... (EDIT: well, this version should be ok. I saw in cpp-ethereum, the precompiled contract checks for {27, 28}.)

@pirapira pirapira changed the title ECRECOVER precompiled contract should have stayed unaffected by Homestead changes [wip] ECRECOVER precompiled contract should have stayed unaffected by Homestead changes Apr 20, 2018
@pirapira pirapira changed the title [wip] ECRECOVER precompiled contract should have stayed unaffected by Homestead changes ECRECOVER precompiled contract should have stayed unaffected by Homestead changes Apr 20, 2018
@pirapira pirapira changed the title ECRECOVER precompiled contract should have stayed unaffected by Homestead changes ECRECOVER precompiled contract should have stayed unaffected by EIP155 changes Apr 20, 2018
@pirapira pirapira merged commit b6e34df into ethereum:master Apr 23, 2018
@pirapira pirapira deleted the precompiled-ecrecover-unchanged branch April 23, 2018 08:41
jamesray1 pushed a commit to jamesray1/yellowpaper that referenced this pull request Nov 26, 2018
…nchanged

ECRECOVER precompiled contract should have stayed unaffected by EIP155 changes
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.

4 participants