native/policy: disallow blocking native contracts

Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
Evgeniy Stratonikov 2021-09-03 11:08:30 +03:00
parent 64f9ed826f
commit 7371593bdc
2 changed files with 16 additions and 4 deletions

View file

@ -319,6 +319,11 @@ func (p *Policy) blockAccount(ic *interop.Context, args []stackitem.Item) stacki
panic("invalid committee signature") panic("invalid committee signature")
} }
hash := toUint160(args[0]) 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) { if p.IsBlockedInternal(ic.DAO, hash) {
return stackitem.NewBool(false) return stackitem.NewBool(false)
} }

View file

@ -201,18 +201,25 @@ func TestBlockedAccounts(t *testing.T) {
neoHash := chain.contracts.NEO.Metadata().Hash neoHash := chain.contracts.NEO.Metadata().Hash
res, err := invokeContractMethodGeneric(chain, 100000000, policyHash, "blockAccount", true, neoHash.BytesBE()) res, err := invokeContractMethodGeneric(chain, 100000000, policyHash, "blockAccount", true, neoHash.BytesBE())
require.NoError(t, err) 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)) 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) require.NoError(t, err)
checkFAULTState(t, res) 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) require.NoError(t, err)
checkResult(t, res, stackitem.NewBool(true)) 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) require.NoError(t, err)
checkResult(t, res, stackitem.Make(0)) checkResult(t, res, stackitem.Null{})
}) })
} }