-
Notifications
You must be signed in to change notification settings - Fork 67
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 contract upgrade #414
Closed
Closed
Changes from 14 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
0f15282
Test demonstrating ECRECOVER code
codingupastorm 94bcb4d
Formatting
codingupastorm fdb13a9
1 instead of 0
codingupastorm aa89b62
Code mostly complete just need to fix tests
codingupastorm 0738617
Soln building
codingupastorm b1c9ec8
ECRecover Progress
codingupastorm 09de8df
WIP
zeptin 36305e5
Use augmented signature format for recId
zeptin 8f0d9e3
Merge branch 'master' into ec-contract-upgrade
YakupIpek bbe4288
Version upgraded
YakupIpek aba3b96
Fix Seeder (#425)
fassadlr d446432
Fix AddressIndexer Console (#426)
fassadlr a57bf78
Update ConnectionManager.cs (#427)
fassadlr fcc8925
Merge commit 'a57bf78f73e246014da1b6d2cf92b05eee1147c5' into ec-contr…
YakupIpek e014e50
Improved address conversation
YakupIpek 50203a1
Removed network parameter
YakupIpek 69631f3
Merge branch 'master' into ec-contract-upgrade
YakupIpek File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
using NBitcoin; | ||
using NBitcoin.Crypto; | ||
using Stratis.SmartContracts.Core.Hashing; | ||
|
||
namespace Stratis.SmartContracts.CLR | ||
{ | ||
/// <summary> | ||
/// Holds logic for the equivalent of the ECRECOVER opcode. | ||
/// | ||
/// This is static for now but when we know more about how we are going to use it we will adjust as necessary. | ||
/// </summary> | ||
public class EcRecoverProvider : IEcRecoverProvider | ||
{ | ||
private readonly Network network; | ||
|
||
public EcRecoverProvider(Network network) | ||
{ | ||
this.network = network; | ||
} | ||
|
||
private static uint256 GetUint256FromMessage(byte[] message) | ||
{ | ||
return new uint256(HashHelper.Keccak256(message)); | ||
} | ||
|
||
/// <summary> | ||
/// Retrieves the base58 address of the signer of an ECDSA signature. | ||
/// </summary> | ||
/// <param name="message"></param> | ||
/// <param name="signature">The ECDSA signature prepended with header information specifying the correct value of recId.</param> | ||
/// <returns>The base58 address for the signer of a signature.</returns> | ||
public Address GetSigner(byte[] message, byte[] signature) | ||
{ | ||
// TODO: Error handling for incorrect signature format etc. | ||
|
||
uint256 hashedUint256 = GetUint256FromMessage(message); | ||
PubKey pubKey = PubKey.RecoverCompact(hashedUint256, signature); | ||
|
||
return pubKey.GetAddress(this.network).ToString().ToAddress(this.network); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps this conversion can be done without using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed |
||
} | ||
|
||
/// <summary> | ||
/// Signs a message, returning an ECDSA signature. | ||
/// </summary> | ||
/// <param name="privateKey">The private key used to sign the message.</param> | ||
/// <param name="message">The complete message to be signed.</param> | ||
/// <returns>The ECDSA signature prepended with header information specifying the correct value of recId.</returns> | ||
public static byte[] SignMessage(Key privateKey, byte[] message) | ||
{ | ||
uint256 hashedUint256 = GetUint256FromMessage(message); | ||
|
||
return privateKey.SignCompact(hashedUint256); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I think this needs to be resolved before this can be used in production.
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.
@rowandh PubKey.RecoverCompact already detects incorrect format and raise an exception.
There is something else to do in here ?