Skip to content

Commit

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

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

contract = self.snapshot.contracts.get(self.calling_scripthash)
group_keys = set(map(lambda g: g.public_key, contract.manifest.groups))
if any(group_keys.intersection(signer.allowed_groups)):
return True
return False

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

# for other IVerifiable types like Block
hashes_for_verifying = self.script_container.get_script_hashes_for_verifying(self.snapshot)
return hash_ in hashes_for_verifying
Expand Down
2 changes: 1 addition & 1 deletion neo3/contracts/interop/runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def get_entryscripthash(engine: contracts.ApplicationEngine) -> types.UInt160:
return engine.entry_scripthash


@register("System.Runtime.CheckWitness", 30000, contracts.native.CallFlags.ALLOW_STATES, True, [bytes])
@register("System.Runtime.CheckWitness", 30000, contracts.native.CallFlags.NONE, True, [bytes])
def do_checkwitness(engine: contracts.ApplicationEngine, data: bytes) -> bool:
if len(data) == 20:
hash_ = types.UInt160(data)
Expand Down
2 changes: 1 addition & 1 deletion tests/contracts/interop/test_runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ def test_checkwitness_called_by_entry(self):
self.assertTrue(item.to_boolean())

def test_checkwitness_helper_other_verifiable(self):
engine = test_engine(has_snapshot=True, has_container=False, default_script=False)
engine = test_engine(has_snapshot=True, has_container=False, default_script=True)
engine.script_container = TestIVerifiable()
self.assertFalse(engine.checkwitness(types.UInt160(b'\x01' * 20)))

Expand Down

0 comments on commit 8da2d45

Please sign in to comment.