aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWei-Ning Huang <w@dexon.org>2019-01-25 12:52:26 +0800
committerJimmy Hu <jimmy.hu@dexon.org>2019-01-25 12:52:26 +0800
commit67aecb871a0ca9ffeefdfd8561bf44b3d047fcd6 (patch)
treefe0a8b6e5bf1644ac150c75750807e21c82b8a2e
parentd817f80e9e874ec2c3190ed443bfdc5a9b29d74e (diff)
downloaddexon-67aecb871a0ca9ffeefdfd8561bf44b3d047fcd6.tar
dexon-67aecb871a0ca9ffeefdfd8561bf44b3d047fcd6.tar.gz
dexon-67aecb871a0ca9ffeefdfd8561bf44b3d047fcd6.tar.bz2
dexon-67aecb871a0ca9ffeefdfd8561bf44b3d047fcd6.tar.lz
dexon-67aecb871a0ca9ffeefdfd8561bf44b3d047fcd6.tar.xz
dexon-67aecb871a0ca9ffeefdfd8561bf44b3d047fcd6.tar.zst
dexon-67aecb871a0ca9ffeefdfd8561bf44b3d047fcd6.zip
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.
-rw-r--r--core/vm/instructions.go10
1 files changed, 5 insertions, 5 deletions
diff --git a/core/vm/instructions.go b/core/vm/instructions.go
index 84e3dfd78..678502a93 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))