I noticed while working this level that given two very similar functions, one will update the king as expected, while the other will not. I'm not sure why this is. The only difference I can see is the one that works has an if statement with a revert while the function that does not work does not have the if statement. Even though I passed the level I'd like to gain a deeper understanding of why one works and the other doesnt. Thank you.
Code to reproduce
pragma solidity ^0.6.0;
contract KingAttack {
function doesNotWork(address king) public payable {
(bool result, bytes memory data) = king.call.value(msg.value)("");
}
function becomeKing(address king) public payable {
(bool result, bytes memory data) = king.call.value(msg.value)("");
if(!result) revert();
}
}
Environment
injected web3, remix, rinkeby