-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
test: add more secp256k1 test vectors #14756
test: add more secp256k1 test vectors #14756
Conversation
Would like @ValarDragon to sign off before merge |
How are these vectors generated? Whats something I should use to verify them? Happy to get a sage script going for it |
Those were generated with import (
"encoding/hex"
"fmt"
"github.com/cosmos/btcutil/base58"
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
)
func main() {
priv := secp256k1.GenPrivKey()
encPriv := make([]byte, len(priv.Key)*2)
hex.Encode(encPriv, priv.Key)
fmt.Println(fmt.Sprintf("PrivKey: %v", string(encPriv)))
pub := priv.PubKey()
encPub := make([]byte, len(pub.Bytes())*2)
hex.Encode(encPub, pub.Bytes())
fmt.Println(fmt.Sprintf("PubKey: %v", string(encPub)))
addr := pub.Address()
fmt.Println(fmt.Sprintf("Address: %v", base58.CheckEncode(addr, 0)))
} |
can we add a test or small function to do this in the code? that way if anything changes it's easy to fix it |
Hrmm, ok. However I personally wouldn't mark the issue as closed (or would make a second issue) for test vectors then. |
@ValarDragon would be enough to generate some test cases with import (
"crypto/ecdsa"
"crypto/sha256"
"encoding/hex"
"fmt"
"github.com/btcsuite/btcutil/base58"
"github.com/ethereum/go-ethereum/crypto"
"golang.org/x/crypto/ripemd160"
)
func ethereumKeys() {
// Generate private key with the go-ethereum
priv, err := crypto.GenerateKey()
if err != nil {
panic(err)
}
encPriv := make([]byte, len(priv.D.Bytes())*2)
hex.Encode(encPriv, priv.D.Bytes())
fmt.Println(fmt.Sprintf("PrivKey: %v", string(encPriv)))
// Get go-ethereum public key
ethPub, ok := priv.Public().(*ecdsa.PublicKey)
if !ok {
panic(err)
}
ethPublicKeyBytes := crypto.FromECDSAPub(ethPub)
// Format byte depending on the oddness of the Y coordinate.
format := 0x02
if ethPub.Y.Bit(0) != 0 {
format = 0x03
}
// Public key in the 33-byte compressed format.
pub := ethPublicKeyBytes[:33]
encPub := make([]byte, len(pub)*2)
pub[0] = byte(format)
hex.Encode(encPub, pub)
fmt.Println(fmt.Sprintf("PubKey: %v", string(encPub)))
// Bitcoin style addresses
sha := sha256.Sum256(pub)
hasherRIPEMD160 := ripemd160.New()
hasherRIPEMD160.Write(sha[:])
addr := hasherRIPEMD160.Sum(nil)
fmt.Println(fmt.Sprintf("Address: %v", base58.CheckEncode(addr[:], 0)))
} |
Since we can rely on go-Ethereum as a dep we should comment out the test. But seems sufficient |
|
@tac0turtle did you have a chance to look at the last commit? |
yes, but we cant update the pr in order to merge. Need you to update for us to merge |
Description
Closes:
#11343
Author Checklist
All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.
I have...
!
to the type prefix if API or client breaking changeCHANGELOG.md
Reviewers Checklist
All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.
I have...
!
in the type prefix if API or client breaking change