diff options
author | Jeffrey Wilcke <obscuren@users.noreply.github.com> | 2014-10-23 22:46:18 +0800 |
---|---|---|
committer | Jeffrey Wilcke <obscuren@users.noreply.github.com> | 2014-10-23 22:46:18 +0800 |
commit | 119c5b40a7ed1aea1c871c0cb56956b8ef9303d9 (patch) | |
tree | b021423da04c9ff319a77549b473b6bad4930dd4 /vm/address.go | |
parent | 50fd46924900869e7210217c6a07979b544991c8 (diff) | |
parent | 184055b3e2995894ccaba364484223e488730627 (diff) | |
download | dexon-119c5b40a7ed1aea1c871c0cb56956b8ef9303d9.tar dexon-119c5b40a7ed1aea1c871c0cb56956b8ef9303d9.tar.gz dexon-119c5b40a7ed1aea1c871c0cb56956b8ef9303d9.tar.bz2 dexon-119c5b40a7ed1aea1c871c0cb56956b8ef9303d9.tar.lz dexon-119c5b40a7ed1aea1c871c0cb56956b8ef9303d9.tar.xz dexon-119c5b40a7ed1aea1c871c0cb56956b8ef9303d9.tar.zst dexon-119c5b40a7ed1aea1c871c0cb56956b8ef9303d9.zip |
Merge pull request #150 from fjl/develop
Merge eth-go repo into go-ethereum
Diffstat (limited to 'vm/address.go')
-rw-r--r-- | vm/address.go | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/vm/address.go b/vm/address.go new file mode 100644 index 000000000..c4aa1eb7c --- /dev/null +++ b/vm/address.go @@ -0,0 +1,42 @@ +package vm + +import ( + "math/big" + + "github.com/ethereum/go-ethereum/ethcrypto" + "github.com/ethereum/go-ethereum/ethutil" +) + +type Address interface { + Call(in []byte) []byte +} + +type PrecompiledAddress struct { + Gas *big.Int + fn func(in []byte) []byte +} + +func (self PrecompiledAddress) Call(in []byte) []byte { + return self.fn(in) +} + +var Precompiled = map[uint64]*PrecompiledAddress{ + 1: &PrecompiledAddress{big.NewInt(500), ecrecoverFunc}, + 2: &PrecompiledAddress{big.NewInt(100), sha256Func}, + 3: &PrecompiledAddress{big.NewInt(100), ripemd160Func}, +} + +func sha256Func(in []byte) []byte { + return ethcrypto.Sha256(in) +} + +func ripemd160Func(in []byte) []byte { + return ethutil.RightPadBytes(ethcrypto.Ripemd160(in), 32) +} + +func ecrecoverFunc(in []byte) []byte { + // In case of an invalid sig. Defaults to return nil + defer func() { recover() }() + + return ethcrypto.Ecrecover(in) +} |