mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
scaffold
This commit is contained in:
parent
c94d582aa7
commit
b7bcfaaa1b
4 changed files with 89 additions and 0 deletions
|
|
@ -44,6 +44,7 @@ var PrecompiledContractsHomestead = map[common.Address]PrecompiledContract{
|
|||
common.BytesToAddress([]byte{2}): &sha256hash{},
|
||||
common.BytesToAddress([]byte{3}): &ripemd160hash{},
|
||||
common.BytesToAddress([]byte{4}): &dataCopy{},
|
||||
common.BytesToAddress([]byte{5}): &ecrecovered25519{},
|
||||
}
|
||||
|
||||
// PrecompiledContractsByzantium contains the default set of pre-compiled Ethereum
|
||||
|
|
@ -101,6 +102,24 @@ func (c *ecrecover) Run(input []byte) ([]byte, error) {
|
|||
return common.LeftPadBytes(crypto.Keccak256(pubKey[1:])[12:], 32), nil
|
||||
}
|
||||
|
||||
// ECRECOVER_EDDSA implemented as a native contract for Web Authentication support
|
||||
type ecrecovered25519 struct{}
|
||||
|
||||
func (c *ecrecovered25519) RequiredGas(input []byte) uint64 {
|
||||
return params.EcrecoverEd25519Gas
|
||||
}
|
||||
|
||||
func (c *ecrecovered25519) Run(input []byte) ([]byte, error) {
|
||||
/**
|
||||
TODO: Read these real good and write this code proper
|
||||
https://godoc.org/golang.org/x/crypto/ed25519
|
||||
https://ed25519.cr.yp.to/
|
||||
|
||||
**/
|
||||
var pubKey []byte
|
||||
return pubKey, nil
|
||||
}
|
||||
|
||||
// SHA256 implemented as a native contract.
|
||||
type sha256hash struct{}
|
||||
|
||||
|
|
|
|||
62
crypto/ed25519/ed25519.go
Normal file
62
crypto/ed25519/ed25519.go
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
package ed25519
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"math/big"
|
||||
)
|
||||
|
||||
func init() {
|
||||
}
|
||||
|
||||
var (
|
||||
ErrInvalidMsgLen = errors.New("invalid message length, need 32 bytes")
|
||||
ErrInvalidSignatureLen = errors.New("invalid signature length")
|
||||
ErrInvalidRecoveryID = errors.New("invalid signature recovery id")
|
||||
ErrInvalidKey = errors.New("invalid private key")
|
||||
ErrInvalidPubkey = errors.New("invalid public key")
|
||||
ErrSignFailed = errors.New("signing failed")
|
||||
ErrRecoverFailed = errors.New("recovery failed")
|
||||
)
|
||||
|
||||
// Sign creates a recoverable ed25519 signature.
|
||||
// The produced signature is in the 65-byte [R || S || V] format where V is 0 or 1.
|
||||
//
|
||||
// The caller is responsible for ensuring that msg cannot be chosen
|
||||
// directly by an attacker. It is usually preferable to use a cryptographic
|
||||
// hash function on any input before handing it to this function.
|
||||
func Sign(msg []byte, seckey []byte) ([]byte, error) {
|
||||
// Lets just use golang.org/x/crypto/ed25519 ??
|
||||
var sig []byte
|
||||
return sig, nil
|
||||
}
|
||||
|
||||
// RecoverPubkey returns the public key of the signer.
|
||||
// msg must be the 32-byte hash of the message to be signed.
|
||||
// sig must be a 65-byte compact ECDSA signature containing the
|
||||
// recovery id as the last element.
|
||||
func RecoverPubkey(msg []byte, sig []byte) ([]byte, error) {
|
||||
var pubkey []byte
|
||||
return pubkey, nil
|
||||
}
|
||||
|
||||
// VerifySignature checks that the given pubkey created signature over message.
|
||||
// The signature should be in [R || S] format.
|
||||
func VerifySignature(pubkey, msg, signature []byte) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func checkSignature(sig []byte) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// DecompressPubkey parses a public key in the 33-byte compressed format.
|
||||
// It returns non-nil coordinates if the public key is valid.
|
||||
func DecompressPubkey(pubkey []byte) (x, y *big.Int) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// CompressPubkey encodes a public key to 33-byte compressed format.
|
||||
func CompressPubkey(x, y *big.Int) []byte {
|
||||
var compressedKey []byte
|
||||
return compressedKey
|
||||
}
|
||||
7
crypto/ed25519/ed2551_test.go
Normal file
7
crypto/ed25519/ed2551_test.go
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
package ed25519
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestSignatureValidity(t *testing.T) {
|
||||
t.Error("Unimplemented")
|
||||
}
|
||||
|
|
@ -74,6 +74,7 @@ const (
|
|||
// Precompiled contract gas prices
|
||||
|
||||
EcrecoverGas uint64 = 3000 // Elliptic curve sender recovery gas price
|
||||
EcrecoverEd25519Gas uint64 = 3000 // Ed25519Gas Elliptic curve (not sender) recovery gas price - TODO: decide this value
|
||||
Sha256BaseGas uint64 = 60 // Base price for a SHA256 operation
|
||||
Sha256PerWordGas uint64 = 12 // Per-word price for a SHA256 operation
|
||||
Ripemd160BaseGas uint64 = 600 // Base price for a RIPEMD160 operation
|
||||
|
|
|
|||
Loading…
Reference in a new issue