diff --git a/pkg/protocol/engine/commitmentfilter/accountsfilter/commitmentfilter.go b/pkg/protocol/engine/commitmentfilter/accountsfilter/commitmentfilter.go index 7f0bf2cd0..2c0d0a216 100644 --- a/pkg/protocol/engine/commitmentfilter/accountsfilter/commitmentfilter.go +++ b/pkg/protocol/engine/commitmentfilter/accountsfilter/commitmentfilter.go @@ -1,8 +1,6 @@ package accountsfilter import ( - "crypto/ed25519" - "github.com/iotaledger/hive.go/core/safemath" hiveEd25519 "github.com/iotaledger/hive.go/crypto/ed25519" "github.com/iotaledger/hive.go/ierrors" @@ -158,7 +156,15 @@ func (c *CommitmentFilter) evaluateBlock(block *blocks.Block) { case *iotago.Ed25519Signature: if !accountData.BlockIssuerKeys.Has(iotago.BlockIssuerKeyEd25519FromPublicKey(signature.PublicKey)) { // if the block issuer does not have the public key in the slot commitment, check if it has an implicit account with the corresponding address - if !accountData.BlockIssuerKeys.Has(iotago.BlockIssuerKeyEd25519AddressFromAddress(iotago.Ed25519AddressFromPubKey(ed25519.PublicKey(signature.PublicKey[:])))) { + var hasAddress = false + accountData.BlockIssuerKeys.Range(func(element iotago.BlockIssuerKey) { + if keyAddress, isAddress := element.(iotago.BlockIssuerKeyEd25519Address); isAddress { + if keyAddress.Address.Equal(iotago.Ed25519AddressFromPubKey(signature.PublicKey[:])) { + hasAddress = true + } + } + }) + if !hasAddress { c.events.BlockFiltered.Trigger(&commitmentfilter.BlockFilteredEvent{ Block: block, Reason: ierrors.Wrapf(ErrInvalidSignature, "block issuer account %s does not have block issuer key corresponding to public key %s in slot %d", block.ProtocolBlock().IssuerID, signature.PublicKey, block.ProtocolBlock().SlotCommitmentID.Index()), diff --git a/pkg/protocol/engine/commitmentfilter/accountsfilter/commitmentfilter_test.go b/pkg/protocol/engine/commitmentfilter/accountsfilter/commitmentfilter_test.go index 6f2df5ec7..19207185d 100644 --- a/pkg/protocol/engine/commitmentfilter/accountsfilter/commitmentfilter_test.go +++ b/pkg/protocol/engine/commitmentfilter/accountsfilter/commitmentfilter_test.go @@ -149,6 +149,7 @@ func TestCommitmentFilter_NoAccount(t *testing.T) { tf.CommitmentFilter.events.BlockFiltered.Hook(func(event *commitmentfilter.BlockFilteredEvent) { require.NotEqual(t, "withAccount", event.Block.ID().Alias()) + require.NotEqual(t, "withImplicitAccount", event.Block.ID().Alias()) }) keyPair := ed25519.GenerateKeyPair() @@ -165,7 +166,7 @@ func TestCommitmentFilter_NoAccount(t *testing.T) { addr := iotago.Ed25519AddressFromPubKey(keyPair.PublicKey[:]) accountID := iotago.AccountID(addr[:]) - // register the account in the proxy account manager + // register the accounts in the proxy account manager tf.AddAccountData( accountID, accounts.NewAccountData( @@ -174,13 +175,26 @@ func TestCommitmentFilter_NoAccount(t *testing.T) { accounts.WithBlockIssuerKeys(iotago.BlockIssuerKeyEd25519FromPublicKey(keyPair.PublicKey)), ), ) + keyPairImplicitAccount := ed25519.GenerateKeyPair() + implicitAddress := iotago.Ed25519AddressFromPubKey(keyPairImplicitAccount.PublicKey[:]) + implicitAccountID := iotago.AccountID(implicitAddress[:]) + tf.AddAccountData( + implicitAccountID, + accounts.NewAccountData( + implicitAccountID, + accounts.WithExpirySlot(math.MaxUint64), + accounts.WithBlockIssuerKeys(iotago.BlockIssuerKeyEd25519AddressFromAddress(implicitAddress)), + ), + ) tf.AddRMCData(currentSlot-currentAPI.ProtocolParameters().MaxCommittableAge(), iotago.Mana(0)) tf.IssueSignedBlockAtSlot("withAccount", currentSlot, commitmentID, keyPair) - otherKeyPair := ed25519.GenerateKeyPair() - tf.IssueSignedBlockAtSlot("noAccount", currentSlot, commitmentID, otherKeyPair) + keyPairNoAccount := ed25519.GenerateKeyPair() + tf.IssueSignedBlockAtSlot("noAccount", currentSlot, commitmentID, keyPairNoAccount) + + tf.IssueSignedBlockAtSlot("withImplicitAccount", currentSlot, commitmentID, keyPairImplicitAccount) } func TestCommitmentFilter_BurnedMana(t *testing.T) {