forked from cerc-io/plugeth
Core changes
* Code = '' if gas < len(D) * 5 * Sha3 gas 10 + 10 * len(D), rounding up 32 bytes * Sha256 gas 50 + 50 * len(D), rounding up 32 bytes * Ripmed gas 50 + 50 * len(D), rounding up 32 bytes * Accounts and value transfers no longer reverted
This commit is contained in:
parent
76842b0df8
commit
acf4b5753f
@ -34,8 +34,14 @@ func (self *Execution) Call(codeAddr []byte, caller vm.ClosureRef) ([]byte, erro
|
|||||||
|
|
||||||
func (self *Execution) exec(code, caddr []byte, caller vm.ClosureRef) (ret []byte, err error) {
|
func (self *Execution) exec(code, caddr []byte, caller vm.ClosureRef) (ret []byte, err error) {
|
||||||
env := self.vm.Env()
|
env := self.vm.Env()
|
||||||
|
|
||||||
chainlogger.Debugf("pre state %x\n", env.State().Root())
|
chainlogger.Debugf("pre state %x\n", env.State().Root())
|
||||||
|
|
||||||
|
from, to := env.State().GetStateObject(caller.Address()), env.State().GetOrNewStateObject(self.address)
|
||||||
|
// Skipping transfer is used on testing for the initial call
|
||||||
|
if !self.SkipTransfer {
|
||||||
|
err = env.Transfer(from, to, self.value)
|
||||||
|
}
|
||||||
|
|
||||||
snapshot := env.State().Copy()
|
snapshot := env.State().Copy()
|
||||||
defer func() {
|
defer func() {
|
||||||
if vm.IsDepthErr(err) || vm.IsOOGErr(err) {
|
if vm.IsDepthErr(err) || vm.IsOOGErr(err) {
|
||||||
@ -44,12 +50,6 @@ func (self *Execution) exec(code, caddr []byte, caller vm.ClosureRef) (ret []byt
|
|||||||
chainlogger.Debugf("post state %x\n", env.State().Root())
|
chainlogger.Debugf("post state %x\n", env.State().Root())
|
||||||
}()
|
}()
|
||||||
|
|
||||||
from, to := env.State().GetStateObject(caller.Address()), env.State().GetOrNewStateObject(self.address)
|
|
||||||
// Skipping transfer is used on testing for the initial call
|
|
||||||
if !self.SkipTransfer {
|
|
||||||
err = env.Transfer(from, to, self.value)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
caller.ReturnGas(self.Gas, self.price)
|
caller.ReturnGas(self.Gas, self.price)
|
||||||
|
|
||||||
@ -59,7 +59,7 @@ func (self *Execution) exec(code, caddr []byte, caller vm.ClosureRef) (ret []byt
|
|||||||
// Pre-compiled contracts (address.go) 1, 2 & 3.
|
// Pre-compiled contracts (address.go) 1, 2 & 3.
|
||||||
naddr := ethutil.BigD(caddr).Uint64()
|
naddr := ethutil.BigD(caddr).Uint64()
|
||||||
if p := vm.Precompiled[naddr]; p != nil {
|
if p := vm.Precompiled[naddr]; p != nil {
|
||||||
if self.Gas.Cmp(p.Gas) >= 0 {
|
if self.Gas.Cmp(p.Gas(len(self.input))) >= 0 {
|
||||||
ret = p.Call(self.input)
|
ret = p.Call(self.input)
|
||||||
self.vm.Printf("NATIVE_FUNC(%x) => %x", naddr, ret)
|
self.vm.Printf("NATIVE_FUNC(%x) => %x", naddr, ret)
|
||||||
self.vm.Endl()
|
self.vm.Endl()
|
||||||
|
@ -12,7 +12,7 @@ type Address interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type PrecompiledAddress struct {
|
type PrecompiledAddress struct {
|
||||||
Gas *big.Int
|
Gas func(l int) *big.Int
|
||||||
fn func(in []byte) []byte
|
fn func(in []byte) []byte
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -21,9 +21,19 @@ func (self PrecompiledAddress) Call(in []byte) []byte {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var Precompiled = map[uint64]*PrecompiledAddress{
|
var Precompiled = map[uint64]*PrecompiledAddress{
|
||||||
1: &PrecompiledAddress{big.NewInt(500), ecrecoverFunc},
|
1: &PrecompiledAddress{func(l int) *big.Int {
|
||||||
2: &PrecompiledAddress{big.NewInt(100), sha256Func},
|
return GasEcrecover
|
||||||
3: &PrecompiledAddress{big.NewInt(100), ripemd160Func},
|
}, ecrecoverFunc},
|
||||||
|
2: &PrecompiledAddress{func(l int) *big.Int {
|
||||||
|
n := big.NewInt(int64(l+31)/32 + 1)
|
||||||
|
n.Mul(n, GasSha256)
|
||||||
|
return n
|
||||||
|
}, sha256Func},
|
||||||
|
3: &PrecompiledAddress{func(l int) *big.Int {
|
||||||
|
n := big.NewInt(int64(l+31)/32 + 1)
|
||||||
|
n.Mul(n, GasRipemd)
|
||||||
|
return n
|
||||||
|
}, ripemd160Func},
|
||||||
}
|
}
|
||||||
|
|
||||||
func sha256Func(in []byte) []byte {
|
func sha256Func(in []byte) []byte {
|
||||||
|
@ -27,10 +27,17 @@ var (
|
|||||||
GasBalance = big.NewInt(20)
|
GasBalance = big.NewInt(20)
|
||||||
GasCreate = big.NewInt(100)
|
GasCreate = big.NewInt(100)
|
||||||
GasCall = big.NewInt(20)
|
GasCall = big.NewInt(20)
|
||||||
|
GasCreateByte = big.NewInt(5)
|
||||||
|
GasSha3Byte = big.NewInt(10)
|
||||||
|
GasSha256Byte = big.NewInt(50)
|
||||||
|
GasRipemdByte = big.NewInt(50)
|
||||||
GasMemory = big.NewInt(1)
|
GasMemory = big.NewInt(1)
|
||||||
GasData = big.NewInt(5)
|
GasData = big.NewInt(5)
|
||||||
GasTx = big.NewInt(500)
|
GasTx = big.NewInt(500)
|
||||||
GasLog = big.NewInt(32)
|
GasLog = big.NewInt(32)
|
||||||
|
GasSha256 = big.NewInt(50)
|
||||||
|
GasRipemd = big.NewInt(50)
|
||||||
|
GasEcrecover = big.NewInt(100)
|
||||||
|
|
||||||
Pow256 = ethutil.BigPow(2, 256)
|
Pow256 = ethutil.BigPow(2, 256)
|
||||||
|
|
||||||
|
@ -254,9 +254,12 @@ func (self *DebugVm) Run(me, caller ClosureRef, code []byte, value, gas, price *
|
|||||||
newMemSize.Mul(newMemSize, u256(32))
|
newMemSize.Mul(newMemSize, u256(32))
|
||||||
|
|
||||||
switch op {
|
switch op {
|
||||||
// Additional gas usage on *CODPY
|
|
||||||
case CALLDATACOPY, CODECOPY, EXTCODECOPY:
|
case CALLDATACOPY, CODECOPY, EXTCODECOPY:
|
||||||
addStepGasUsage(new(big.Int).Div(newMemSize, u256(32)))
|
addStepGasUsage(new(big.Int).Div(newMemSize, u256(32)))
|
||||||
|
case SHA3:
|
||||||
|
g := new(big.Int).Div(newMemSize, u256(32))
|
||||||
|
g.Mul(g, GasSha3Byte)
|
||||||
|
addStepGasUsage(g)
|
||||||
}
|
}
|
||||||
|
|
||||||
if newMemSize.Cmp(u256(int64(mem.Len()))) > 0 {
|
if newMemSize.Cmp(u256(int64(mem.Len()))) > 0 {
|
||||||
@ -833,8 +836,13 @@ func (self *DebugVm) Run(me, caller ClosureRef, code []byte, value, gas, price *
|
|||||||
|
|
||||||
self.Printf("CREATE err %v", err)
|
self.Printf("CREATE err %v", err)
|
||||||
} else {
|
} else {
|
||||||
ref.SetCode(ret)
|
// gas < len(ret) * CreateDataGas == NO_CODE
|
||||||
msg.Output = ret
|
dataGas := big.NewInt(int64(len(ret)))
|
||||||
|
dataGas.Mul(dataGas, GasCreateByte)
|
||||||
|
if closure.UseGas(dataGas) {
|
||||||
|
ref.SetCode(ret)
|
||||||
|
msg.Output = ret
|
||||||
|
}
|
||||||
|
|
||||||
stack.Push(ethutil.BigD(addr))
|
stack.Push(ethutil.BigD(addr))
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user