Skip to content

Commit

Permalink
core/vm: reuse pooled bigints for ADDRESS, ORIGIN and CALLER
Browse files Browse the repository at this point in the history
  • Loading branch information
holiman committed Mar 4, 2019
1 parent bda409a commit e5945d5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
3 changes: 3 additions & 0 deletions common/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,9 @@ func (a Address) Bytes() []byte { return a[:] }
// Big converts an address to a big integer.
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.
func (a Address) Hash() Hash { return BytesToHash(a[:]) }

Expand Down
6 changes: 3 additions & 3 deletions core/vm/instructions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
stack.push(contract.Address().Big())
stack.push(contract.Address().SetBig(interpreter.intPool.get()))
return nil, nil
}

Expand All @@ -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) {
stack.push(interpreter.evm.Origin.Big())
stack.push(interpreter.evm.Origin.SetBig(interpreter.intPool.get()))
return nil, nil
}

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
}

Expand Down

0 comments on commit e5945d5

Please sign in to comment.