Skip to content

Commit

Permalink
https://github.com/neo-project/neo/pull/2292
Browse files Browse the repository at this point in the history
  • Loading branch information
ixje committed Apr 7, 2021
1 parent 0ab0e47 commit 74cd92c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
17 changes: 8 additions & 9 deletions neo3/contracts/applicationengine.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,7 @@ def checkwitness(self, hash_: types.UInt160) -> bool:
return True

if payloads.WitnessScope.CUSTOM_GROUPS in signer.scope:
if contracts.CallFlags.READ_STATES not in \
contracts.CallFlags(self.current_context.call_flags):
raise ValueError("Context requires callflags ALLOW_STATES")
self._validate_callflags(contracts.CallFlags.READ_STATES)

contract = contracts.ManagementContract().get_contract(self.snapshot, self.calling_scripthash)
if contract is None:
Expand All @@ -105,9 +103,7 @@ def checkwitness(self, hash_: types.UInt160) -> bool:
return True
return False

if contracts.CallFlags.READ_STATES not in \
contracts.CallFlags(self.current_context.call_flags):
raise ValueError("Context requires callflags ALLOW_STATES")
self._validate_callflags(contracts.CallFlags.READ_STATES)

# for other IVerifiable types like Block
hashes_for_verifying = self.script_container.get_script_hashes_for_verifying(self.snapshot)
Expand Down Expand Up @@ -235,9 +231,7 @@ def on_syscall(self, method_id: int) -> Any:
if descriptor is None:
raise KeyError(f"Requested interop {method_id} is not valid")

if descriptor.required_call_flags not in contracts.CallFlags(self.current_context.call_flags):
raise ValueError(f"Cannot call {descriptor.method} with {self.current_context.call_flags}")

self._validate_callflags(descriptor.required_call_flags)
self.add_gas(descriptor.price * self.exec_fee_factor)

parameters = []
Expand Down Expand Up @@ -371,6 +365,7 @@ def load_contract(self,
return context

def load_token(self, token_id: int) -> vm.ExecutionContext:
self._validate_callflags(contracts.CallFlags.READ_STATES | contracts.CallFlags.ALLOW_CALL)
contract = self._context_state.get(self.current_context, None)
if contract is None:
raise ValueError("Current context has no contract state")
Expand Down Expand Up @@ -463,3 +458,7 @@ def _contract_call_internal2(self,
if contracts.NativeContract.is_native(target_contract.hash):
context_new.evaluation_stack.push(vm.ByteStringStackItem(method_descriptor.name.encode('utf-8')))
return context_new

def _validate_callflags(self, callflags: contracts.CallFlags):
if callflags not in contracts.CallFlags(self.current_context.call_flags):
raise ValueError(f"Context requires callflags {callflags}")
2 changes: 1 addition & 1 deletion neo3/contracts/interop/contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from neo3.contracts.interop import register


@register("System.Contract.Call", 1 << 15, contracts.CallFlags.ALLOW_CALL)
@register("System.Contract.Call", 1 << 15, contracts.CallFlags.READ_STATES | contracts.CallFlags.ALLOW_CALL)
def contract_call(engine: contracts.ApplicationEngine,
contract_hash: types.UInt160,
method: str,
Expand Down

0 comments on commit 74cd92c

Please sign in to comment.