有没有办法将经过验证的参数传递到坚固的智能合约功能?

发布于 2025-02-07 01:22:03 字数 306 浏览 1 评论 0原文

我想将名为“ testfunction”的函数称为“索赔达特”作为参数。索赔数据参数来自服务器通过API。

contract TestSmartContract {

  testFunction(uint256 id, uint256 claimDate) public payable returns (uint) {
    // I need a logic to verify if claimDate is coming from a valid source which will mean it is correct.
  }

}

I want to call a function named "testFunction" which takes "claimDate" as a parameter. claimDate parameter comes from a server via api.

contract TestSmartContract {

  testFunction(uint256 id, uint256 claimDate) public payable returns (uint) {
    // I need a logic to verify if claimDate is coming from a valid source which will mean it is correct.
  }

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

凉墨 2025-02-14 01:22:03

简而言之,您可以使用签名验证来检查数据是否来自经过验证的源。

这个想法是;

  1. 让源签名索赔date从Off-Chain(Ex。BackendServer)签名。
  2. 索赔以及合同的签名一起发送。
  3. 存储源地址的合同验证签名是否正确。如果是,则表示索赔实际上来自源。

⚠️请注意,签名单独的索赔>可能还不够。因为一旦创建了签名,就可以通过利用者可见并重复使用。


阅读更多信息: https://blog.chainsafe .io/how-to-verify-a-signed-message-in-solidity-6b3100277424

In short, you can use signature verification to check if the data comes from the verified source.

The idea is that;

  1. Let the source sign the claimDate from off-chain (ex. backend server).
  2. Send the claimDate together with the signature to the contract.
  3. The contract which stores source address verifies if the signature is correct. If yes, it means the claimDate is really from the source.

⚠️ Note that signing claimDate alone might not be enough. Because once the signature is created, it can be visible and reused by exploiters.

Read more: https://blog.chainsafe.io/how-to-verify-a-signed-message-in-solidity-6b3100277424

稍尽春風 2025-02-14 01:22:03

您可以使用钱包地址来验证源是否有效。

例如:

contract TestSmartContract {

   address sourceAddress = "0x00...";
    
   function testFunction(uint256 id, uint256 claimDate) public returns(uint) {
       require(msg.sender == sourceAddress, "Not valid source");
       //code to execute
   }
}

You can use the wallet address to validate if the source is valid.

For example:

contract TestSmartContract {

   address sourceAddress = "0x00...";
    
   function testFunction(uint256 id, uint256 claimDate) public returns(uint) {
       require(msg.sender == sourceAddress, "Not valid source");
       //code to execute
   }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文