Ethereum: Creation of a nested function call with createreproxywithnonce
If you work with the secure proxy system in Ethereum, the use of a new Gnosis safe can be a complex process. A common problem occurs when you try to create a proxy for a single contract or a function with the Createreproxywithnonce method.
In this article, we will deal with nested functions and nonces with the details of the use of the “Creeproxywithnonce” method.
The problem: Nested function calls
Let us see an example of the use of a simple Gnosis safe that uses two contracts:
- “Safecontract”: This contract contains basic security functions such as the users of the white list.
- “MyContract”: This is the main contract for which we want to have a proxy that implements personalized logic.
In order to provide the two contracts on the safe proxy factory with createreproxywithnonce ', we would have to create nested functional calls:
Solidity
Contract Mysafe {
MyFunction function () internal return () {
// personalized logic here ...
}
}
Safecontract contract is Safeproxyfactory {
Public Safunction () Nonces (0] {
Return myfunction ();
}
Createreproxywithnonce function (
_Gingleton,
Initializer,
Salt
) Return of the internal replacement (MySafe) {
MySAFE PROXY = New Mysafe (address (_singleton));
// initializes proxy with certain data ...
Proxy return;
}
}
"" ""
As you can see, we create nested functional calls:CreateProxywithnonce” is called recursive in a different function. This approach has several problems:
* The nested functional calls are not permitted : Recursive functional calls are not supported in the case of solidity.
* Nonces only applies to the first call
: Since “Createreproxywithnonce” creates a new instance of “MySafe”, we don’t lose anything about the previous call. To solve this problem, we have to explicitly hand over the Nuncio.
The solution: handed over from nonces
from explicitly **
In order to solve the above problems, we can change our approach as follows:
`Solidity
Contract Mysafe {
MyFunction function () internal return () {
// personalized logic here ...
}
}
Safecontract contract is Safeproxyfactory {
Createreproxywithnonce function (
_Gingleton,
Initializer,
Salt
) Public nunci [0] {
Return new MySAFE (address (_singleton));
}
GetProxy function () internal view (MySAFE) {
// returns the proxy instance
}
}
"" ""
In this revised approach:
- We hand overNonce [0] ‘to the’ Creatatereproxywithnonce ‘method, which receives a nonce value for the first call.
- We also define our own function
getProxy ()
that returns the proxy instance. In this way we can return the proxy instance without having to count on the nuncups.
Diploma
In order to create nested functional views with “Creatatereproxywithnonce”, you must explicitly transmit nonces, either as a parameter or an internal viewing property. In this way, you can avoid recursive functional calls and ensure that your contract is properly initialized.
If the use of Gnosis is secured via the safe proxy system, follow these guidelines if you create nested functional calls:
- Pass on the Nonces explicitly in the “Createreproxywithnonce” methods.
- Use the properties of the internal view to restore proxy instances.