aboutsummaryrefslogtreecommitdiffstats
path: root/core/vm/instructions.go
diff options
context:
space:
mode:
authorGustav Simonsson <gustav.simonsson@gmail.com>2015-11-27 22:40:29 +0800
committerJeffrey Wilcke <geffobscura@gmail.com>2016-02-18 17:08:11 +0800
commit371871d685d54b916aef28de689d6f0af7822083 (patch)
treee704b02ba2ffd2d1164001885fba15106b0f7d94 /core/vm/instructions.go
parentaa36a6ae4f24f07e2c470a21c93ff37ad5861982 (diff)
downloadgo-tangerine-371871d685d54b916aef28de689d6f0af7822083.tar.gz
go-tangerine-371871d685d54b916aef28de689d6f0af7822083.tar.zst
go-tangerine-371871d685d54b916aef28de689d6f0af7822083.zip
parmas, crypto, core, core/vm: homestead consensus protocol changes
* change gas cost for contract creating txs * invalidate signature with s value greater than secp256k1 N / 2 * OOG contract creation if not enough gas to store code * new difficulty adjustment algorithm * new DELEGATECALL op code
Diffstat (limited to 'core/vm/instructions.go')
-rw-r--r--core/vm/instructions.go49
1 files changed, 22 insertions, 27 deletions
diff --git a/core/vm/instructions.go b/core/vm/instructions.go
index 2e868521e..9d3d4e6fe 100644
--- a/core/vm/instructions.go
+++ b/core/vm/instructions.go
@@ -337,7 +337,13 @@ func opOrigin(instr instruction, pc *uint64, env Environment, contract *Contract
}
func opCaller(instr instruction, pc *uint64, env Environment, contract *Contract, memory *Memory, stack *stack) {
- stack.push(common.Bytes2Big(contract.caller.Address().Bytes()))
+ var bigAddr *big.Int
+ if contract.DelegateCall {
+ bigAddr = env.Origin().Big()
+ } else {
+ bigAddr = contract.caller.Address().Big()
+ }
+ stack.push(bigAddr)
}
func opCallValue(instr instruction, pc *uint64, env Environment, contract *Contract, memory *Memory, stack *stack) {
@@ -485,7 +491,6 @@ func opSload(instr instruction, pc *uint64, env Environment, contract *Contract,
func opSstore(instr instruction, pc *uint64, env Environment, contract *Contract, memory *Memory, stack *stack) {
loc := common.BigToHash(stack.pop())
val := stack.pop()
-
env.Db().SetState(contract.Address(), loc, common.BigToHash(val))
}
@@ -509,31 +514,6 @@ func opGas(instr instruction, pc *uint64, env Environment, contract *Contract, m
}
func opCreate(instr instruction, pc *uint64, env Environment, contract *Contract, memory *Memory, stack *stack) {
- var (
- value = stack.pop()
- offset, size = stack.pop(), stack.pop()
- input = memory.Get(offset.Int64(), size.Int64())
- gas = new(big.Int).Set(contract.Gas)
- addr common.Address
- ret []byte
- suberr error
- )
-
- contract.UseGas(contract.Gas)
- ret, addr, suberr = env.Create(contract, input, gas, contract.Price, value)
- if suberr != nil {
- stack.push(new(big.Int))
- } else {
- // gas < len(ret) * Createinstr.dataGas == NO_CODE
- dataGas := big.NewInt(int64(len(ret)))
- dataGas.Mul(dataGas, params.CreateDataGas)
- if contract.UseGas(dataGas) {
- env.Db().SetCode(addr, ret)
- }
-
- stack.push(addr.Big())
-
- }
}
func opCall(instr instruction, pc *uint64, env Environment, contract *Contract, memory *Memory, stack *stack) {
@@ -598,6 +578,21 @@ func opCallCode(instr instruction, pc *uint64, env Environment, contract *Contra
}
}
+func opDelegateCall(instr instruction, pc *uint64, env Environment, contract *Contract, memory *Memory, stack *stack) {
+ gas, to, inOffset, inSize, outOffset, outSize := stack.pop(), stack.pop(), stack.pop(), stack.pop(), stack.pop(), stack.pop()
+
+ toAddr := common.BigToAddress(to)
+ args := memory.Get(inOffset.Int64(), inSize.Int64())
+ ret, err := env.DelegateCall(contract, toAddr, args, gas, contract.Price)
+
+ if err != nil {
+ stack.push(new(big.Int))
+ } else {
+ stack.push(big.NewInt(1))
+ memory.Set(outOffset.Uint64(), outSize.Uint64(), ret)
+ }
+}
+
func opReturn(instr instruction, pc *uint64, env Environment, contract *Contract, memory *Memory, stack *stack) {
}
func opStop(instr instruction, pc *uint64, env Environment, contract *Contract, memory *Memory, stack *stack) {