From e1db48e289045741bc6a403850b8cd69210df2cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Szil=C3=A1gyi?= Date: Tue, 20 Dec 2016 11:25:49 +0200 Subject: [PATCH] accounts, core, crypto: fun with docs to make things explicit --- accounts/account_manager.go | 4 ++-- core/types/transaction_signing.go | 12 ++++++------ crypto/crypto.go | 7 ++----- 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/accounts/account_manager.go b/accounts/account_manager.go index bd7175aa918a2..12ff30bcaf564 100644 --- a/accounts/account_manager.go +++ b/accounts/account_manager.go @@ -137,7 +137,7 @@ func (am *Manager) DeleteAccount(a Account, passphrase string) error { } // Sign calculates a ECDSA signature for the given hash. The produced signature -// is in the canonical secp256k1 format (V = 0 or 1). +// is in the [R || S || V] format where V is 0 or 1. func (am *Manager) Sign(addr common.Address, hash []byte) ([]byte, error) { am.mu.RLock() defer am.mu.RUnlock() @@ -151,7 +151,7 @@ func (am *Manager) Sign(addr common.Address, hash []byte) ([]byte, error) { // SignWithPassphrase signs hash if the private key matching the given address // can be decrypted with the given passphrase. The produced signature is in the -// canonical secp256k1 format (V = 0 or 1). +// [R || S || V] format where V is 0 or 1. func (am *Manager) SignWithPassphrase(addr common.Address, passphrase string, hash []byte) (signature []byte, err error) { _, key, err := am.getDecryptedKey(Account{Address: addr}, passphrase) if err != nil { diff --git a/core/types/transaction_signing.go b/core/types/transaction_signing.go index f991667576b88..8952bd57470bd 100644 --- a/core/types/transaction_signing.go +++ b/core/types/transaction_signing.go @@ -161,8 +161,8 @@ func (s EIP155Signer) PublicKey(tx *Transaction) ([]byte, error) { return pub, nil } -// WithSignature returns a new transaction with the given signature. -// This signature needs to be in the canonical secp256k1 form (v = 0 or 1). +// WithSignature returns a new transaction with the given signature. This signature +// needs to be in the [R || S || V] format where V is 0 or 1. func (s EIP155Signer) WithSignature(tx *Transaction, sig []byte) (*Transaction, error) { if len(sig) != 65 { panic(fmt.Sprintf("wrong size for snature: got %d, want 65", len(sig))) @@ -211,8 +211,8 @@ func (s HomesteadSigner) Equal(s2 Signer) bool { return ok } -// WithSignature returns a new transaction with the given snature. -// This signature needs to be in the canonical secp256k1 form (v = 0 or 1). +// WithSignature returns a new transaction with the given signature. This signature +// needs to be in the [R || S || V] format where V is 0 or 1. func (hs HomesteadSigner) WithSignature(tx *Transaction, sig []byte) (*Transaction, error) { if len(sig) != 65 { panic(fmt.Sprintf("wrong size for snature: got %d, want 65", len(sig))) @@ -267,8 +267,8 @@ func (s FrontierSigner) Equal(s2 Signer) bool { return ok } -// WithSignature returns a new transaction with the given snature. -// This signature needs to be in the canonical secp256k1 form (v = 0 or 1). +// WithSignature returns a new transaction with the given signature. This signature +// needs to be in the [R || S || V] format where V is 0 or 1. func (fs FrontierSigner) WithSignature(tx *Transaction, sig []byte) (*Transaction, error) { if len(sig) != 65 { panic(fmt.Sprintf("wrong size for snature: got %d, want 65", len(sig))) diff --git a/crypto/crypto.go b/crypto/crypto.go index 25aec0836f2e2..f1a4b774c0bc2 100644 --- a/crypto/crypto.go +++ b/crypto/crypto.go @@ -168,8 +168,7 @@ func GenerateKey() (*ecdsa.PrivateKey, error) { } // ValidateSignatureValues verifies whether the signature values are valid with -// the given chain rules. The v value is assumed to be the canonical secp256k1 -// value of either 0 or 1. +// the given chain rules. The v value is assumed to be either 0 or 1. func ValidateSignatureValues(v byte, r, s *big.Int, homestead bool) bool { if r.Cmp(common.Big1) < 0 || s.Cmp(common.Big1) < 0 { return false @@ -200,9 +199,7 @@ func SigToPub(hash, sig []byte) (*ecdsa.PublicKey, error) { // be aware that the given hash cannot be choosen by an adversery. Common // solution is to hash any input before calculating the signature. // -// The produced signature is in the canonical secp256k1 format (V = 0 or 1), -// which can be transformed into the proper Ethereum signature accoring to -// the yellow paper within the transaction signer. +// The produced signature is in the [R || S || V] format where V is 0 or 1. func Sign(data []byte, prv *ecdsa.PrivateKey) (sig []byte, err error) { if len(data) != 32 { return nil, fmt.Errorf("hash is required to be exactly 32 bytes (%d)", len(data))