可以在视图功能中欺骗味精吗?

发布于 2025-02-14 00:01:38 字数 829 浏览 2 评论 0原文

从我可以看到的情况下,通过“连接”函数通过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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

亣腦蒛氧 2025-02-21 00:01:38

当然可以,它不是“黑客

”有关区块链的数据(即使您不提供读取功能),使变量私有的安全措施也不是安全措施。

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..

末骤雨初歇 2025-02-21 00:01:38

将其与代表呼叫连接,然后您会看到您的欺骗地址在链中我从未尝试过的是如何发生的,如果有人呼叫查看,则可以实现它,然后代表在链上呼叫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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文