core/vm: reuse pooled bigints for ADDRESS, ORIGIN and CALLER

This commit is contained in:
Martin Holst Swende 2019-03-04 09:45:56 +01:00
parent bda409a02a
commit e5945d58f0
No known key found for this signature in database
GPG key ID: 683B438C05A5DDF0
2 changed files with 6 additions and 3 deletions

View file

@ -205,6 +205,9 @@ func (a Address) Bytes() []byte { return a[:] }
// Big converts an address to a big integer. // Big converts an address to a big integer.
func (a Address) Big() *big.Int { return new(big.Int).SetBytes(a[:]) } func (a Address) Big() *big.Int { return new(big.Int).SetBytes(a[:]) }
// SetBig converts an address to a given big integer.
func (a Address) SetBig(int *big.Int) *big.Int { return int.SetBytes(a[:]) }
// Hash converts an address to a hash by left-padding it with zeros. // Hash converts an address to a hash by left-padding it with zeros.
func (a Address) Hash() Hash { return BytesToHash(a[:]) } func (a Address) Hash() Hash { return BytesToHash(a[:]) }

View file

@ -405,7 +405,7 @@ func opSha3(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory
} }
func opAddress(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { func opAddress(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) {
stack.push(contract.Address().Big()) stack.push(contract.Address().SetBig(interpreter.intPool.get()))
return nil, nil return nil, nil
} }
@ -416,12 +416,12 @@ func opBalance(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memo
} }
func opOrigin(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { func opOrigin(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) {
stack.push(interpreter.evm.Origin.Big()) stack.push(interpreter.evm.Origin.SetBig(interpreter.intPool.get()))
return nil, nil return nil, nil
} }
func opCaller(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { func opCaller(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) {
stack.push(contract.Caller().Big()) stack.push(contract.Caller().SetBig(interpreter.intPool.get()))
return nil, nil return nil, nil
} }