This commit is contained in:
Jae Kwon
2015-06-25 20:28:34 -07:00
parent a55950e1d0
commit 9965dd5de6
75 changed files with 556 additions and 522 deletions

View File

@@ -11,17 +11,17 @@ import (
var nativeContracts = make(map[Word256]NativeContract)
func init() {
nativeContracts[Uint64ToWord256(1)] = ecrecoverFunc
nativeContracts[Uint64ToWord256(2)] = sha256Func
nativeContracts[Uint64ToWord256(3)] = ripemd160Func
nativeContracts[Uint64ToWord256(4)] = identityFunc
nativeContracts[Int64ToWord256(1)] = ecrecoverFunc
nativeContracts[Int64ToWord256(2)] = sha256Func
nativeContracts[Int64ToWord256(3)] = ripemd160Func
nativeContracts[Int64ToWord256(4)] = identityFunc
}
//-----------------------------------------------------------------------------
type NativeContract func(input []byte, gas *uint64) (output []byte, err error)
type NativeContract func(input []byte, gas *int64) (output []byte, err error)
func ecrecoverFunc(input []byte, gas *uint64) (output []byte, err error) {
func ecrecoverFunc(input []byte, gas *int64) (output []byte, err error) {
// Deduct gas
gasRequired := GasEcRecover
if *gas < gasRequired {
@@ -42,9 +42,9 @@ func ecrecoverFunc(input []byte, gas *uint64) (output []byte, err error) {
return LeftPadBytes(hashed, 32), nil
}
func sha256Func(input []byte, gas *uint64) (output []byte, err error) {
func sha256Func(input []byte, gas *int64) (output []byte, err error) {
// Deduct gas
gasRequired := uint64((len(input)+31)/32)*GasSha256Word + GasSha256Base
gasRequired := int64((len(input)+31)/32)*GasSha256Word + GasSha256Base
if *gas < gasRequired {
return nil, ErrInsufficientGas
} else {
@@ -59,9 +59,9 @@ func sha256Func(input []byte, gas *uint64) (output []byte, err error) {
return hasher.Sum(nil), nil
}
func ripemd160Func(input []byte, gas *uint64) (output []byte, err error) {
func ripemd160Func(input []byte, gas *int64) (output []byte, err error) {
// Deduct gas
gasRequired := uint64((len(input)+31)/32)*GasRipemd160Word + GasRipemd160Base
gasRequired := int64((len(input)+31)/32)*GasRipemd160Word + GasRipemd160Base
if *gas < gasRequired {
return nil, ErrInsufficientGas
} else {
@@ -76,9 +76,9 @@ func ripemd160Func(input []byte, gas *uint64) (output []byte, err error) {
return LeftPadBytes(hasher.Sum(nil), 32), nil
}
func identityFunc(input []byte, gas *uint64) (output []byte, err error) {
func identityFunc(input []byte, gas *int64) (output []byte, err error) {
// Deduct gas
gasRequired := uint64((len(input)+31)/32)*GasIdentityWord + GasIdentityBase
gasRequired := int64((len(input)+31)/32)*GasIdentityWord + GasIdentityBase
if *gas < gasRequired {
return nil, ErrInsufficientGas
} else {