Skip to content

Add OpenZeppelin upgradeable support#15

Open
loothero wants to merge 1 commit into
mainfrom
add-oz-upgradeable
Open

Add OpenZeppelin upgradeable support#15
loothero wants to merge 1 commit into
mainfrom
add-oz-upgradeable

Conversation

@loothero

Copy link
Copy Markdown
Member

Summary

  • Added OpenZeppelin openzeppelin_upgrades v3.0.0 dependency and lockfile entry.
  • Wired UpgradeableComponent into the Beasts NFT contract with owner-gated IUpgradeable::upgrade.
  • Added focused upgrade authorization/validation tests in src/mint_tests.cairo.

Changed files

  • Scarb.toml
  • Scarb.lock
  • src/lib.cairo
  • src/mint_tests.cairo

Verification

  • scarb fmt passed
  • scarb fmt --check --workspace passed
  • scarb build passed
  • snforge test --max-n-steps 4294967295 passed: 37 passed, 0 failed, 306 ignored

Copilot AI review requested due to automatic review settings May 25, 2026 00:51

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request adds upgradeability to the beasts_nft contract by integrating OpenZeppelin's UpgradeableComponent. The changes involve updating Scarb.toml and Scarb.lock for the new dependency, implementing the IUpgradeable interface in src/lib.cairo, and expanding the test suite in src/mint_tests.cairo. Feedback suggests that the upgrade function should include a check against the contract's terminal_timestamp to ensure that the upgrade path is disabled once the contract is intended to become immutable.

Comment thread src/lib.cairo
Comment on lines +258 to +261
fn upgrade(ref self: ContractState, new_class_hash: ClassHash) {
self.ownable.assert_only_owner();
self.upgradeable.upgrade(new_class_hash);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The upgrade function does not account for the terminal_timestamp logic implemented in other parts of the contract (e.g., build_metadata_uri). If the contract is intended to become "terminal" (immutable or final) after a specific timestamp, allowing upgrades after that point would allow the owner to bypass this restriction by replacing the contract logic entirely. Consider adding a check to ensure the contract is not past its terminal timestamp before allowing an upgrade.

        fn upgrade(ref self: ContractState, new_class_hash: ClassHash) {
            self.ownable.assert_only_owner();

            let terminal_ts = self.terminal_timestamp.read();
            if terminal_ts != 0_u64 {
                assert(starknet::get_block_timestamp() <= terminal_ts, 'Terminal: upgrade disabled');
            }

            self.upgradeable.upgrade(new_class_hash);
        }

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Adds OpenZeppelin upgradeable support to the Beasts NFT contract, gating upgrades behind the owner check and adding tests for both unauthorized callers and validation paths.

Changes:

  • Add openzeppelin_upgrades v3.0.0 dependency in Scarb.toml / Scarb.lock.
  • Wire UpgradeableComponent into beasts_nft with an owner-gated IUpgradeable::upgrade impl.
  • Extend deploy_contract helper and add two upgrade authorization/validation tests in src/mint_tests.cairo.

Reviewed changes

Copilot reviewed 3 out of 4 changed files in this pull request and generated no comments.

File Description
Scarb.toml Adds openzeppelin_upgrades v3.0.0 dependency.
Scarb.lock Lockfile entry for the new dependency.
src/lib.cairo Imports/wires UpgradeableComponent, adds substorage, event, and owner-gated upgrade ABI.
src/mint_tests.cairo Adds IUpgradeableDispatcher to deploy helper tuple and two new upgrade tests; updates existing destructurings.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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