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 contract update counter https://github.com/neo-project/neo/pull/2697 #162

Merged
merged 1 commit into from
Jun 27, 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
8 changes: 8 additions & 0 deletions neo3/contracts/native/management.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ def contract_create_with_data(self,
sb.emit_push(parsed_manifest.name)
hash_ = to_script_hash(sb.to_array())

if contracts.PolicyContract().is_blocked(engine.snapshot, hash_):
raise ValueError(f"Contract {hash_} is blocked by the policy contract")

existing_contract = engine.snapshot.contracts.try_get(hash_)
if existing_contract is not None:
raise ValueError("Contract already exists")
Expand Down Expand Up @@ -132,6 +135,9 @@ def contract_update_with_data(self,
if contract is None:
raise ValueError("Can't find contract to update")

if contract.update_counter == 0xFFFF:
raise ValueError("Maximum contract updates reached")

if nef_file is not None:
if nef_len == 0:
raise ValueError(f"Invalid NEF length: {nef_len}")
Expand Down Expand Up @@ -179,6 +185,8 @@ def contract_destroy(self, engine: contracts.ApplicationEngine) -> None:
for key, _ in engine.snapshot.storages.find(contract.id.to_bytes(4, 'little', signed=True)):
engine.snapshot.storages.delete(key)

contracts.PolicyContract()._block_account_internal(engine.snapshot, hash_)

msgrouter.interop_notify(self.hash,
"Destroy",
vm.ArrayStackItem(vm.ByteStringStackItem(contract.hash.to_array()))
Expand Down
7 changes: 5 additions & 2 deletions neo3/contracts/native/policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,16 @@ def _block_account(self, engine: contracts.ApplicationEngine, account: types.UIn
"""
if not self._check_committee(engine):
return False
return self._block_account_internal(engine.snapshot, account)

def _block_account_internal(self, snapshot: storage.Snapshot, account: types.UInt160) -> bool:
if self.is_native(account):
raise ValueError("Cannot block native contracts")
storage_key = self.key_blocked_account + account.to_array()
storage_item = engine.snapshot.storages.try_get(storage_key, read_only=False)
storage_item = snapshot.storages.try_get(storage_key, read_only=False)
if storage_item is None:
storage_item = storage.StorageItem(b'\x00')
engine.snapshot.storages.update(storage_key, storage_item)
snapshot.storages.update(storage_key, storage_item)
else:
return False

Expand Down