question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add support for constructor in logic holding contracts.

See original GitHub issue

When deploying the logic contract for a proxy, you are expected to replace the constructor with an initialize function, for the part that is instance-specific (let’s say the name and symbol of an ERC20). This is verified by the plugin, which will refuse to work with implementations that have non-trivial constructors

However, it can still make sense to have a constructor that sets an immutable variable (such as the address of a forwarder for the ERC2771Context). That way the logic contract can “hardcode” the forwarder in an immutable variable, and then all instances use the same forwarder out of the box, without having to initialize it.

Therefore, I think it would be useful to have a way to bypass this check and provide constructor arguments for the logic contract.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:5
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
lbedercommented, Jul 1, 2021

You can find it here: https://github.com/OpenZeppelin/openzeppelin-upgrades/compare/master...lbeder:ctor-args?expand=1 and other than the issue with the caching of the logic contract (which causes the tests to fail) - it’s good for review.

1reaction
frangiocommented, Apr 9, 2021

Bypassing the check is now implemented, and basic immutable variables should work with the appropriate overrides:

/// @custom:oz-upgrades-unsafe-allow state-variable-immutable
address immutable self = address(this);

Empty constructors should also be possible:

/// @custom:oz-upgrades-unsafe-allow constructor
constructor() {
    // set immutable vars here?
}

But it’s still not possible to provide arguments to the constructor.

Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - Design by contracts and constructors - Stack Overflow
The class invariant must hold after the constructor (any of them) finishes, and before and after any public method of the class is...
Read more >
Writing Upgradeable Contracts - OpenZeppelin Docs
When working with upgradeable contracts using OpenZeppelin Upgrades, there are a few minor caveats ... no constructors can be used in upgradeable contracts....
Read more >
Nested smart contracts guide - LogRocket Blog
Calling a nested contract from an external contract: Contracts can also be called externally; for example, you could use a constructor function ...
Read more >
Solidity - Constructors - GeeksforGeeks
If the child contract is not passing any parameter to the parent's constructor the child contract will become an abstract contract. There are ......
Read more >
Dependency Injection anti-pattern: multiple constructors
Injectables are the types that contain the logic of our application. ... This holds for both the person reading the code and the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found