From 7371593bdcfdc3d2798bfd03b66a9a1502c2f9f5 Mon Sep 17 00:00:00 2001 From: Evgeniy Stratonikov Date: Fri, 3 Sep 2021 11:08:30 +0300 Subject: [PATCH] native/policy: disallow blocking native contracts Signed-off-by: Evgeniy Stratonikov --- pkg/core/native/policy.go | 5 +++++ pkg/core/native_policy_test.go | 15 +++++++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/pkg/core/native/policy.go b/pkg/core/native/policy.go index 48b1db4ad..e377f0447 100644 --- a/pkg/core/native/policy.go +++ b/pkg/core/native/policy.go @@ -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) } diff --git a/pkg/core/native_policy_test.go b/pkg/core/native_policy_test.go index d29f3f3c0..5a041121c 100644 --- a/pkg/core/native_policy_test.go +++ b/pkg/core/native_policy_test.go @@ -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{}) }) }