aboutsummaryrefslogtreecommitdiffstats
path: root/vm/address.go
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2014-10-18 19:31:20 +0800
committerobscuren <geffobscura@gmail.com>2014-10-18 19:31:20 +0800
commit20c742e47406c13ebc6427951f6fcf1b0056ea26 (patch)
treee8112a93626c0f20ca5aa9ac91ea2d1be07150d9 /vm/address.go
parenta02dc4ccc321bdee2a670eecdf5c3bac01fc290b (diff)
downloadgo-tangerine-20c742e47406c13ebc6427951f6fcf1b0056ea26.tar
go-tangerine-20c742e47406c13ebc6427951f6fcf1b0056ea26.tar.gz
go-tangerine-20c742e47406c13ebc6427951f6fcf1b0056ea26.tar.bz2
go-tangerine-20c742e47406c13ebc6427951f6fcf1b0056ea26.tar.lz
go-tangerine-20c742e47406c13ebc6427951f6fcf1b0056ea26.tar.xz
go-tangerine-20c742e47406c13ebc6427951f6fcf1b0056ea26.tar.zst
go-tangerine-20c742e47406c13ebc6427951f6fcf1b0056ea26.zip
Moved ethvm => vm
Diffstat (limited to 'vm/address.go')
-rw-r--r--vm/address.go42
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)
+}