diff options
author | obscuren <geffobscura@gmail.com> | 2014-10-18 19:31:20 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2014-10-18 19:31:20 +0800 |
commit | 20c742e47406c13ebc6427951f6fcf1b0056ea26 (patch) | |
tree | e8112a93626c0f20ca5aa9ac91ea2d1be07150d9 /vm/address.go | |
parent | a02dc4ccc321bdee2a670eecdf5c3bac01fc290b (diff) | |
download | dexon-20c742e47406c13ebc6427951f6fcf1b0056ea26.tar dexon-20c742e47406c13ebc6427951f6fcf1b0056ea26.tar.gz dexon-20c742e47406c13ebc6427951f6fcf1b0056ea26.tar.bz2 dexon-20c742e47406c13ebc6427951f6fcf1b0056ea26.tar.lz dexon-20c742e47406c13ebc6427951f6fcf1b0056ea26.tar.xz dexon-20c742e47406c13ebc6427951f6fcf1b0056ea26.tar.zst dexon-20c742e47406c13ebc6427951f6fcf1b0056ea26.zip |
Moved ethvm => vm
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..cfb7f36d9 --- /dev/null +++ b/vm/address.go @@ -0,0 +1,42 @@ +package vm + +import ( + "math/big" + + "github.com/ethereum/eth-go/ethcrypto" + "github.com/ethereum/eth-go/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) +} |