From 3ae5046ae3a495227deb13d50291c340f000ed2d Mon Sep 17 00:00:00 2001 From: Spirin Vladimir Date: Sun, 8 Aug 2021 16:07:00 +0200 Subject: [PATCH] Accept only valid _targetDna In case _targetDna > 10**6 than we going to have new zombies with probably duplicated dna. IMHO better restrict to accept only valid dna then support invalid cases. --- lesson-2/chapter-8/zombiefeeding.sol | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lesson-2/chapter-8/zombiefeeding.sol b/lesson-2/chapter-8/zombiefeeding.sol index 5de9e21..48cf4ad 100644 --- a/lesson-2/chapter-8/zombiefeeding.sol +++ b/lesson-2/chapter-8/zombiefeeding.sol @@ -5,9 +5,9 @@ contract ZombieFeeding is ZombieFactory { function feedAndMultiply(uint _zombieId, uint _targetDna) public { require(msg.sender == zombieToOwner[_zombieId]); Zombie storage myZombie = zombies[_zombieId]; - _targetDna = _targetDna % dnaModulus; + require(_targetDna == _targetDna % dnaModulus); uint newDna = (myZombie.dna + _targetDna) / 2; _createZombie("NoName", newDna); } -} \ No newline at end of file +}