0

I have such following smart contract:

function a() external onlyOwner {
  _a();
}

function b() external onlyOwner {
  _b();
}

function _a() internal {
  // do smh
}

function _b() internal {
  // do smh
}

a and b should be only called by the owner of the contract. But I also need a logic for myself to execute these functions for me to pay the gas. So I have another such function:

function verifySigner(bytes memory signature) internal {
  // recover signer from the signature
  // do smh
}

There are 2 ways I see to make this work.

1_ Make 2 different external functions, one verifying the signature and redirecting to function a, and same for function b

2_ Make a single function that takes the function signature in the parameters and calls it with the low level call after verifying the signer as follows:

function delegate(bytes memory signature, bytes memory fnSignature) external onlyByMe {
  // verifySigner(signature)

  address(this).call(
    fnSignature
  );
}

Which one should I go with and why?

1

1 Answer 1

0

It seems to me according to my research and experiments with gas efficiency, first option is more suitable.

With the second option deployment is cheaper, but due to call's overhead, function calls are a bit more expensive. And since my contract requires a good amount of interaction, and deployment is going to occur only once, the first option is the better choice for me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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