From 0fa30af8a7aaab5e110e3430f2cb8f69cb17af70 Mon Sep 17 00:00:00 2001 From: Wei-Ning Huang Date: Fri, 25 Jan 2019 12:52:26 +0800 Subject: core: vm: more change to the randomness calculation (#175) To prevent attacker from sending TX through a intermediate contract. Always use the original tx sender's adddress and nonce. --- core/vm/instructions.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'core') diff --git a/core/vm/instructions.go b/core/vm/instructions.go index 3d17287ed..cb1f1bbaa 100644 --- a/core/vm/instructions.go +++ b/core/vm/instructions.go @@ -413,9 +413,9 @@ func opSha3(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory func opRand(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { evm := interpreter.evm - nonce := evm.StateDB.GetNonce(contract.Caller()) - binaryNonce := make([]byte, binary.MaxVarintLen64) - binary.PutUvarint(binaryNonce, nonce) + nonce := evm.StateDB.GetNonce(evm.Origin) + binaryOriginNonce := make([]byte, binary.MaxVarintLen64) + binary.PutUvarint(binaryOriginNonce, nonce) binaryUsedIndex := make([]byte, binary.MaxVarintLen64) binary.PutUvarint(binaryUsedIndex, evm.RandCallIndex) @@ -424,8 +424,8 @@ func opRand(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory hash := crypto.Keccak256( evm.Randomness, - contract.Caller().Bytes(), - binaryNonce, + evm.Origin.Bytes(), + binaryOriginNonce, binaryUsedIndex) stack.push(interpreter.intPool.get().SetBytes(hash)) -- cgit v1.2.3