Skip to content

Commit

Permalink
fix commitment filter bug
Browse files Browse the repository at this point in the history
  • Loading branch information
cyberphysic4l committed Sep 15, 2023
1 parent 64f5d33 commit b612ea0
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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(
Expand All @@ -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) {
Expand Down

0 comments on commit b612ea0

Please sign in to comment.