Skip to content

Commit

Permalink
Fix proxy assertion (#394)
Browse files Browse the repository at this point in the history
* fix hash assertion

* remove comment
  • Loading branch information
andrew-fleming authored Jul 12, 2022
1 parent 9b76a3b commit e8a7d2b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
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

0 comments on commit e8a7d2b

Please sign in to comment.