如果合约B中的方法只能由合约A调用,合约A是否可以伪装?
代码如下:
pragma solidity ^0.4.23;
contract A {
address public owner;
B public b;
function A(address _owner) {
owner = _owner;
b = B(msg.sender);
}
function callB() public view returns(string _greeting) {
require(msg.sender == owner);
return b.onlyForA();
}
}
contract B {
A public a;
function B() {
a = new A(msg.sender);
}
// only contract A can call this function
function onlyForA() public view returns(string _greeting) {
require(msg.sender == address(a));
return "Hello A!";
}
}
如果攻击者知道合同a的地址,他可以假装合同A然后调用合同B的“onlyForA”方法吗?