0

Let's say I have a Dispatcher contract that delegates all function calls to an Implementation contract using delegatecall (see for example https://gist.github.com/Arachnid/4ca9da48d51e23e5cfe0f0e14dd6318f).

To initialise the Dispatcher with some value uint value1 I want to (delegate)call, from the constructor of Dispatcher, an init() method of the Implementation and pass it value1. For security reasons I would like to mark the init() method of Implementation as internal... but it does not seem to work.

I know I can make the init() method of Implementation public with some custom modifier but I would like to understand why the delegatecall to the internal method is not working.

0

if you are trying to call the init() method in Implementation from Dispatcher using delegatecall , internal will not work. As the internal function visibility specifier only refers to that function being called from inside the contract. So if the delegatecall is in the constructor of the contract, then you will not need to specify anything as the constructor is only run once and that is when the contract is deployed. You cannot call the constructor after it has been deployed.

  • Thanks for responding, but I'm not sure I understand your answer. Dispatcher makes the delegatecall to init() (of Implementation) in its constructor so in that sense the method is called from inside the contract. My understanding of delegatecall is that the entire code of Implementation is executed in the context of Dispatcher. If init() was in Dispatcher it would obviously be seen when called in the constructor... so why is it different when using delegatecall. – juniz Dec 7 '17 at 14:53
  • Ok maybe I will explain further, if you do mark init() in implementation as internal , then init() can only be accessed from the implementation contract not the Dispatcher contract. The internal function visibility specifier will only make the init() function accessible in the implementation contract not outside of it. If you do use delegatecall ,call or callcode from the dispatcher contract it will not be able to access init(). If you want to initialise dispatcher with a value from the implementation contract then init() will have to be public. – jold20 Dec 7 '17 at 15:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.