-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #303 from OffchainLabs/secp256r1-precompile
Add Precompile for secp256r1 conditionally based on ArbOS version
- Loading branch information
Showing
10 changed files
with
5,563 additions
and
1 deletion.
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
Large diffs are not rendered by default.
Oops, something went wrong.
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,26 @@ | ||
package secp256r1 | ||
|
||
import ( | ||
"crypto/ecdsa" | ||
"crypto/elliptic" | ||
"math/big" | ||
) | ||
|
||
// Generates approptiate public key format from given coordinates | ||
func newPublicKey(x, y *big.Int) *ecdsa.PublicKey { | ||
// Check if the given coordinates are valid | ||
if x == nil || y == nil || !elliptic.P256().IsOnCurve(x, y) { | ||
return nil | ||
} | ||
|
||
// Check if the given coordinates are the reference point (infinity) | ||
if x.Sign() == 0 && y.Sign() == 0 { | ||
return nil | ||
} | ||
|
||
return &ecdsa.PublicKey{ | ||
Curve: elliptic.P256(), | ||
X: x, | ||
Y: y, | ||
} | ||
} |
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,21 @@ | ||
package secp256r1 | ||
|
||
import ( | ||
"crypto/ecdsa" | ||
"math/big" | ||
) | ||
|
||
// Verifies the given signature (r, s) for the given hash and public key (x, y). | ||
func Verify(hash []byte, r, s, x, y *big.Int) bool { | ||
// Create the public key format | ||
publicKey := newPublicKey(x, y) | ||
|
||
// Check if they are invalid public key coordinates | ||
if publicKey == nil { | ||
return false | ||
} | ||
|
||
// Verify the signature with the public key, | ||
// then return true if it's valid, false otherwise | ||
return ecdsa.Verify(publicKey, hash, r, s) | ||
} |
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
Submodule testdata
updated
from ee3fa4 to bac70c