Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

eth upgradable contract #133

Merged
merged 6 commits into from
Jan 24, 2025
Merged

eth upgradable contract #133

merged 6 commits into from
Jan 24, 2025

Conversation

ailisp
Copy link
Contributor

@ailisp ailisp commented Jan 23, 2025

This version only allows contract owner to upgrade, we may figure out a better permission control such as voting to agree contract upgrade in future. I deployed this proxy contract to 0x6348104D80e1376b59789cA5b65f9a45708A16d6 on sepolia.

@ailisp ailisp marked this pull request as ready for review January 23, 2025 15:00

## Update the public key

To update the public key, you also need to update the contract. Add a `reinitialize` function to the contract that set the public key to new one, and upgrade the contract as above.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what do you mean by Add a `reinitialize` function to the contract that set the public key to new one?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll add an example in unit test

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

const deploymentPath = `deployments/${networkName}.json`;

// Check if deployment file exists
if (!fs.existsSync(deploymentPath)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This relies on the local deployment file? Does this mean we need to commit that file to git every time we do initialDeploy or updateContract?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. Local deployment is gitignored. For testnet it should be commited

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

/// @custom:oz-upgrades-unsafe-allow constructor
constructor() initializer {}

function initialize(PublicKey memory _publicKey) public initializer {
publicKey = _publicKey;
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to add storage gap or is it handled by the openzepplin already? https://blog.openzeppelin.com/validate-smart-contract-storage-gaps-with-openzeppelin-upgrades-plugins

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for point out. I didn't know this. After reading this I think we don't need it, we can append new variables as long as we keep existing variables.

npx hardhat run scripts/upgradeContract.js --network <network>
```

It will upgrade the implementation contract to the new version and keep the proxy contract address the same. Make sure you always extends the storage and never override it. For more details, please refer to [Writing Upgradeable Contracts](https://docs.openzeppelin.com/upgrades-plugins/writing-upgradeable).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I remember seeing that the order of declaring variables also can't change when we modify the contract? Does openzepplin warn against it?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, it does warn!

Upgrading implementation...
Error: New storage layout is incompatible

ChainSignatures: Deleted `threshold`
  > Keep the variable even if unused

contracts/ChainSignatures.sol:43: Inserted `threshold`
  > New variables should be placed after all existing inherited variables

contracts/ChainSignatures.sol:44: Inserted `hihi`
  > New variables should be placed after all existing inherited variables

@ailisp ailisp requested review from ppca and volovyks January 24, 2025 10:26
@ailisp ailisp merged commit 797aa4b into develop Jan 24, 2025
2 of 3 checks passed
@ailisp ailisp deleted the bo/eth-upgrade-contract branch January 24, 2025 10:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants