可以在视图功能中欺骗味精吗?
从我可以看到的情况下,通过“连接”函数通过ethers.js将视图功能中的消息发送到您想要的任何地址似乎很容易将消息发送者设置为。
例如,如果您有这样的合同:
contract Test {
address public owner;
string private secret;
modifier onlyOwner() {
require(msg.sender==owner,"onlyOwner");
_;
}
constructor() {
owner = msg.sender;
secret="Abracadabra";
}
function setSecret(string memory newSecret) public onlyOwner {
secret = newSecret;
}
function getSecret() public view onlyOwner returns(string memory) {
return secret;
}
}
即使您不是所有者帐户,也可以运行
let owner = await con.owner();
let secret = con.connect(owner).getSecret()
,也不会收到以太货币的投诉。我知道,如果您尝试运行setSecret
,但是当没有涉及的交易时,似乎您不需要真正的签名人,只是合同地址。
还有其他需要检查味精是否实际上是一个帐户,而不仅仅是帐户地址的字符串?
From what I can see, it seems trivially easy to set message sender in a view function to whatever address you want for external calls through ethers.js via the 'connect' function.
For example, if you have a contract like this:
contract Test {
address public owner;
string private secret;
modifier onlyOwner() {
require(msg.sender==owner,"onlyOwner");
_;
}
constructor() {
owner = msg.sender;
secret="Abracadabra";
}
function setSecret(string memory newSecret) public onlyOwner {
secret = newSecret;
}
function getSecret() public view onlyOwner returns(string memory) {
return secret;
}
}
Even if you aren't the owner account, you could run
let owner = await con.owner();
let secret = con.connect(owner).getSecret()
And get no complaints from ethers. I know this would fail if you tried to run setSecret
but when there no transaction involved it looks like you don't need a real signer, just a contract address.
Is there some other to check if the msg.sender is actually an account, not just a string of the account address?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当然可以,它不是“黑客
”有关区块链的数据(即使您不提供读取功能),使变量私有的安全措施也不是安全措施。
Sure it can be, it is not a 'hack', when you call view function you can overwrite msg.sender
And anyway 'secret' variable (even private) can be read by some tools, as any data on blockchain (even if you will not provide read function), it is not a security measure to make variable private..
将其与代表呼叫连接,然后您会看到您的欺骗地址在链中我从未尝试过的是如何发生的,如果有人呼叫查看,则可以实现它,然后代表在链上呼叫ocuurs ocuurs on Chain上
connect it with delegate call then you see how that your spoofed address occurs in on chain tx i have never tried you can do it make it live if someone call view then the delegate call ocuurs on on chain