简体   繁体   English

中继智能合约设计

[英]Relay smart contract design

Im trying to make a relay smart contract which can pass msg.value and msg.sender in a function call from another deployed smart contract.我试图制作一个中继智能合约,它可以在另一个部署的智能合约的 function 调用中传递msg.valuemsg.sender

Context: The goal is to mint/borrow with multiples DeFi protocol (deployed and not owned by me contracts) with ONE main smart contract to have only ONE wallet to handle.背景:目标是使用多个 DeFi 协议(部署且不属于我的合约)与一个主智能合约进行铸造/借用,以便只有一个钱包可以处理。 That implies that funds ( msg.value ?) and owner ( msg.sender ?) are transfered within the functions calling transaction to the DeFi smart contracts.这意味着资金( msg.value ?)和所有者( msg.sender ?)在调用交易的函数内转移到 DeFi 智能合约。

EOA = A wallet with a bit of ETH to pay fees EOA = 一个带有一点 ETH 来支付费用的钱包

Relay = The relay smart contract, which must receive funds from the DeFi smart contracts (= as being the msg.sender ?) Relay = 中继智能合约,必须从 DeFi 智能合约接收资金(= 作为msg.sender ?)

proxyDeFi = The proxy smart contract which allow to send multiple requests to one or multiple DeFi smart contracts within one transaction proxyDeFi = 代理智能合约,允许在一笔交易中向一个或多个 DeFi 智能合约发送多个请求

It seems to me that delegatecall allows to pass the msg.sender and the msg.value in the execution of a function of another smart contract, so what I did so far:在我看来, delegatecall允许在执行另一个智能合约的 function 时传递msg.sendermsg.value ,所以到目前为止我做了什么:

The proxyDeFi is working as intended when called by the EOA, but proxyDeFi is the msg.sender for the queried DeFi smart contracts, not EOA.当 EOA 调用 proxyDeFi 时,它按预期工作,但 proxyDeFi 是查询的msg.sender智能合约的 msg.sender,而不是 EOA。 We will need several proxy contracts which could be updated often, so I tried to make a simple relay:我们需要几个可以经常更新的代理合约,所以我尝试做一个简单的中继:

contract Relay {
    address public proxyDeFi;
    address owner = msg.sender;
    
    modifier isOwner() {
        require(msg.sender == owner, "Forbidden");
        _;
    }

    function update(address newAddress) isOwner public {
        proxyDeFi = newAddress;
    }

    fallback() isOwner external payable {
        proxyDeFi.delegatecall(msg.data);
    }
}

I tried to call proxyDeFi's functions to Relay (with EOA), but the transaction is systematically reverted on the deletegateCall .我试图将 proxyDeFi 的函数调用到 Relay(使用 EOA),但在deletegateCall上系统地恢复了事务。 I tried to add a debug on the proxyDeFi side but nothing is output, I am new to Solidity so there is certainly something that I did not understand.我尝试在 proxyDeFi 端添加调试,但没有任何东西是 output,我是 Solidity 的新手,所以肯定有一些我不明白的东西。

Roughly, I would like proxyDeFi to only be considered as if it was a library for the relay, except that proxyDeFi would be another smart contract deployed so that we can modify it without having to redeploy the Relay.粗略地说,我希望 proxyDeFi 仅被视为中继的库,除了 proxyDeFi 将是另一个部署的智能合约,因此我们可以修改它而无需重新部署中继。 I have the feeling that what I want to achieve is actually more complex than that, or maybe my method is not the correct/best one.我有一种感觉,我想要实现的实际上比这更复杂,或者我的方法可能不是正确/最好的方法。 I would greatly appreciate your advice.非常感谢您的建议。

When your calling contract to contract interactions the msg.sender is the calling contract, you could use tx.origin if you want it to get the address of person who initialized the transaction.当您的调用合约与合约交互时, msg.sender是调用合约,如果您希望它获取初始化交易的人的地址,您可以使用tx.origin

Careful, using delegate call, there are some exploit vulnerabilities if its improperly used, because it calls the function and updates the data stored on the calling contract.小心,使用委托调用,如果使用不当会有一些利用漏洞,因为它调用 function 并更新存储在调用合约上的数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM