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

Fix proxy assertion #394

Merged
merged 2 commits into from
Jul 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/openzeppelin/upgrades/Proxy.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# OpenZeppelin Contracts for Cairo v0.2.0 (upgrades/Proxy.cairo)

%lang starknet
#%builtins pedersen range_check bitwise

from starkware.cairo.common.cairo_builtins import HashBuiltin
from starkware.starknet.common.syscalls import (
Expand Down
4 changes: 3 additions & 1 deletion src/openzeppelin/upgrades/library.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,10 @@ namespace Proxy:
range_check_ptr
}(new_implementation: felt):
with_attr error_message("Proxy: implementation hash cannot be zero"):
Proxy_implementation_hash.write(new_implementation)
assert_not_zero(new_implementation)
end

Proxy_implementation_hash.write(new_implementation)
Upgraded.emit(new_implementation)
return ()
end
Expand Down
20 changes: 20 additions & 0 deletions tests/upgrades/test_upgrades.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,26 @@ async def test_upgrade_from_non_admin(proxy_factory):
)


@pytest.mark.asyncio
async def test__set_implementation_as_zero(proxy_factory):
admin, _, proxy, _, _ = proxy_factory

# initialize implementation
await signer.send_transaction(
admin, proxy.contract_address, 'initializer', [
admin.contract_address
]
)

# upgrade should revert
await assert_revert(
signer.send_transaction(
admin, proxy.contract_address, 'upgrade', [0]
),
reverted_with="Proxy: implementation hash cannot be zero"
)


@pytest.mark.asyncio
async def test_implementation_v2(after_upgrade):
admin, _, proxy, _, v2_decl = after_upgrade
Expand Down