Skip to content

Commit

Permalink
native/policy: disallow blocking native contracts
Browse files Browse the repository at this point in the history
Signed-off-by: Evgeniy Stratonikov <[email protected]>
  • Loading branch information
fyrchik committed Sep 3, 2021
1 parent 64f9ed8 commit 7371593
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
5 changes: 5 additions & 0 deletions pkg/core/native/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,11 @@ func (p *Policy) blockAccount(ic *interop.Context, args []stackitem.Item) stacki
panic("invalid committee signature")
}
hash := toUint160(args[0])
for i := range ic.Natives {
if ic.Natives[i].Metadata().Hash == hash {
panic("cannot block native contract")
}
}
if p.IsBlockedInternal(ic.DAO, hash) {
return stackitem.NewBool(false)
}
Expand Down
15 changes: 11 additions & 4 deletions pkg/core/native_policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,18 +201,25 @@ func TestBlockedAccounts(t *testing.T) {
neoHash := chain.contracts.NEO.Metadata().Hash
res, err := invokeContractMethodGeneric(chain, 100000000, policyHash, "blockAccount", true, neoHash.BytesBE())
require.NoError(t, err)
checkFAULTState(t, res)

cs, _ := getTestContractState(chain)
require.NoError(t, chain.contracts.Management.PutContractState(chain.dao, cs))

res, err = invokeContractMethodGeneric(chain, 100000000, policyHash, "blockAccount", true, cs.Hash.BytesBE())
require.NoError(t, err)
checkResult(t, res, stackitem.NewBool(true))

res, err = invokeContractMethodGeneric(chain, 100000000, neoHash, "balanceOf", true, account.BytesBE())
res, err = invokeContractMethod(chain, 100000000, cs.Hash, "justReturn")
require.NoError(t, err)
checkFAULTState(t, res)

res, err = invokeContractMethodGeneric(chain, 100000000, policyHash, "unblockAccount", true, neoHash.BytesBE())
res, err = invokeContractMethodGeneric(chain, 100000000, policyHash, "unblockAccount", true, cs.Hash.BytesBE())
require.NoError(t, err)
checkResult(t, res, stackitem.NewBool(true))

res, err = invokeContractMethodGeneric(chain, 100000000, neoHash, "balanceOf", true, account.BytesBE())
res, err = invokeContractMethod(chain, 100000000, cs.Hash, "justReturn")
require.NoError(t, err)
checkResult(t, res, stackitem.Make(0))
checkResult(t, res, stackitem.Null{})
})
}

0 comments on commit 7371593

Please sign in to comment.