Skip to content

Commit

Permalink
Merge pull request #771 from iotaledger/fix/ref-unlocks
Browse files Browse the repository at this point in the history
Fix bug with implicit account and basic output signatures
  • Loading branch information
muXxer authored Feb 28, 2024
2 parents edc441c + fce0708 commit 24cf994
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 40 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ require (
github.com/iotaledger/inx-app v1.0.0-rc.3.0.20240216141618-d7dfe94bdc1e
github.com/iotaledger/inx/go v1.0.0-rc.2.0.20240216141023-6d5f4ef12ac5
github.com/iotaledger/iota-crypto-demo v0.0.0-20240216103559-27ca8dffd1e7
github.com/iotaledger/iota.go/v4 v4.0.0-20240220155644-70d23c10cabe
github.com/iotaledger/iota.go/v4 v4.0.0-20240228104340-25491bf70f39
github.com/labstack/echo/v4 v4.11.4
github.com/labstack/gommon v0.4.2
github.com/libp2p/go-libp2p v0.32.2
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,8 @@ github.com/iotaledger/inx/go v1.0.0-rc.2.0.20240216141023-6d5f4ef12ac5 h1:ebh2IK
github.com/iotaledger/inx/go v1.0.0-rc.2.0.20240216141023-6d5f4ef12ac5/go.mod h1:Go1Gp6s+RCwNyaTjSw/TCk1Li5xd3+926aCu61kL+ks=
github.com/iotaledger/iota-crypto-demo v0.0.0-20240216103559-27ca8dffd1e7 h1:t6k4MqiUov0FrBb2o2JhKlOVSdlPbIQWM8ivYHL0G0g=
github.com/iotaledger/iota-crypto-demo v0.0.0-20240216103559-27ca8dffd1e7/go.mod h1:do+N3LpeDEi9qselEC4XcjqGoRc7cWGiqBtIeBOKEMs=
github.com/iotaledger/iota.go/v4 v4.0.0-20240220155644-70d23c10cabe h1:c6Sa60ISQHsEsKEF+fnAKjsH/pQQwz/l66r/Y2QWHtg=
github.com/iotaledger/iota.go/v4 v4.0.0-20240220155644-70d23c10cabe/go.mod h1:IZNS0qmVdoRjIbFe4VTPG7k3bzSJQBvAHL2eC/2kFT0=
github.com/iotaledger/iota.go/v4 v4.0.0-20240228104340-25491bf70f39 h1:C6ODo+JQ04SOLC8ayo/EvBYgnO1oGOV91czUD1kTguQ=
github.com/iotaledger/iota.go/v4 v4.0.0-20240228104340-25491bf70f39/go.mod h1:IZNS0qmVdoRjIbFe4VTPG7k3bzSJQBvAHL2eC/2kFT0=
github.com/ipfs/boxo v0.17.0 h1:fVXAb12dNbraCX1Cdid5BB6Kl62gVLNVA+e0EYMqAU0=
github.com/ipfs/boxo v0.17.0/go.mod h1:pIZgTWdm3k3pLF9Uq6MB8JEcW07UDwNJjlXW1HELW80=
github.com/ipfs/go-cid v0.4.1 h1:A/T3qGvxi4kpKWWcPC/PgbvDA2bjVLO7n4UeVwnbs/s=
Expand Down
14 changes: 7 additions & 7 deletions pkg/protocol/engine/ledger/ledger/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,13 +174,13 @@ func (v *VM) ValidateSignatures(signedTransaction mempool.SignedTransaction, res
RewardsInputSet: rewardInputSet,
}

unlockedIdentities, err := nova.NewVirtualMachine().ValidateUnlocks(signedStardustTransaction, resolvedInputs)
unlockedAddresses, err := nova.NewVirtualMachine().ValidateUnlocks(signedStardustTransaction, resolvedInputs)
if err != nil {
return nil, err
}

executionContext = context.Background()
executionContext = context.WithValue(executionContext, ExecutionContextKeyUnlockedIdentities, unlockedIdentities)
executionContext = context.WithValue(executionContext, ExecutionContextKeyUnlockedAddresses, unlockedAddresses)
executionContext = context.WithValue(executionContext, ExecutionContextKeyResolvedInputs, resolvedInputs)

return executionContext, nil
Expand All @@ -197,17 +197,17 @@ func (v *VM) Execute(executionContext context.Context, transaction mempool.Trans
return nil, err
}

unlockedIdentities, ok := executionContext.Value(ExecutionContextKeyUnlockedIdentities).(iotagovm.UnlockedIdentities)
unlockedAddresses, ok := executionContext.Value(ExecutionContextKeyUnlockedAddresses).(iotagovm.UnlockedAddresses)
if !ok {
return nil, ierrors.Errorf("unlockedIdentities not found in execution context")
return nil, ierrors.Errorf("unlockedAddresses not found in execution context")
}

resolvedInputs, ok := executionContext.Value(ExecutionContextKeyResolvedInputs).(iotagovm.ResolvedInputs)
if !ok {
return nil, ierrors.Errorf("resolvedInputs not found in execution context")
}

createdOutputs, err := nova.NewVirtualMachine().Execute(stardustTransaction, resolvedInputs, unlockedIdentities)
createdOutputs, err := nova.NewVirtualMachine().Execute(stardustTransaction, resolvedInputs, unlockedAddresses)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -237,8 +237,8 @@ func (v *VM) Execute(executionContext context.Context, transaction mempool.Trans
type ExecutionContextKey uint8

const (
// ExecutionContextKeyUnlockedIdentities is the key for the unlocked identities in the execution context.
ExecutionContextKeyUnlockedIdentities ExecutionContextKey = iota
// ExecutionContextKeyUnlockedAddresses is the key for the unlocked addresses in the execution context.
ExecutionContextKeyUnlockedAddresses ExecutionContextKey = iota

// ExecutionContextKeyResolvedInputs is the key for the resolved inputs in the execution context.
ExecutionContextKeyResolvedInputs
Expand Down
26 changes: 13 additions & 13 deletions pkg/protocol/engine/utxoledger/tpkg/equal.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,29 @@ func EqualOutput(t *testing.T, expected *utxoledger.Output, actual *utxoledger.O
require.Equal(t, expected.SlotCreated(), actual.SlotCreated())
require.Equal(t, expected.OutputType(), actual.OutputType())

var expectedIdent iotago.Address
var expectedOwner iotago.Address
switch output := expected.Output().(type) {
case iotago.TransIndepIdentOutput:
expectedIdent = output.Ident()
case iotago.TransDepIdentOutput:
expectedIdent = output.ChainID().ToAddress()
case iotago.OwnerTransitionIndependentOutput:
expectedOwner = output.Owner()
case iotago.OwnerTransitionDependentOutput:
expectedOwner = output.ChainID().ToAddress()
default:
require.Fail(t, "unsupported output type")
}

var actualIdent iotago.Address
var actualOwner iotago.Address
switch output := actual.Output().(type) {
case iotago.TransIndepIdentOutput:
actualIdent = output.Ident()
case iotago.TransDepIdentOutput:
actualIdent = output.ChainID().ToAddress()
case iotago.OwnerTransitionIndependentOutput:
actualOwner = output.Owner()
case iotago.OwnerTransitionDependentOutput:
actualOwner = output.ChainID().ToAddress()
default:
require.Fail(t, "unsupported output type")
}

require.NotNil(t, expectedIdent)
require.NotNil(t, actualIdent)
require.True(t, expectedIdent.Equal(actualIdent))
require.NotNil(t, expectedOwner)
require.NotNil(t, actualOwner)
require.True(t, expectedOwner.Equal(actualOwner))
require.Equal(t, expected.BaseTokenAmount(), actual.BaseTokenAmount())
require.EqualValues(t, expected.Output(), actual.Output())
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/tests/combined_account_transition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ func createImplicitToFullAccount(ts *testsuite.TestSuite) iotago.AccountID {
block3Slot := ts.CurrentSlot()
tx4 := newUserWallet.TransitionImplicitAccountToAccountOutput(
"TX4",
[]string{"TX3:0"},
[]string{"TX3:0", "TX3:1"},
mock.WithBlockIssuerFeature(
iotago.BlockIssuerKeys{implicitBlockIssuerKey},
iotago.MaxSlotIndex,
Expand Down
7 changes: 4 additions & 3 deletions pkg/testsuite/mock/wallet_transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -1132,7 +1132,9 @@ func (w *Wallet) TransitionNFTWithTransactionOpts(transactionName string, inputN
func (w *Wallet) createSignedTransactionWithOptions(transactionName string, addressIndexes []uint32, opts ...options.Option[builder.TransactionBuilder]) *iotago.SignedTransaction {
currentAPI := w.Node.Protocol.CommittedAPI()

txBuilder := builder.NewTransactionBuilder(currentAPI)
addressSigner := w.AddressSigner(addressIndexes...)

txBuilder := builder.NewTransactionBuilder(currentAPI, addressSigner)
// Use the wallet's current slot as creation slot by default.
txBuilder.SetCreationSlot(w.currentSlot)
// Set the transaction capabilities to be able to do anything.
Expand All @@ -1141,8 +1143,7 @@ func (w *Wallet) createSignedTransactionWithOptions(transactionName string, addr
randomPayload := tpkg.Rand12ByteArray()
txBuilder.AddTaggedDataPayload(&iotago.TaggedData{Tag: randomPayload[:], Data: randomPayload[:]})

addressSigner := w.AddressSigner(addressIndexes...)
signedTransaction := lo.PanicOnErr(options.Apply(txBuilder, opts).Build(addressSigner))
signedTransaction := lo.PanicOnErr(options.Apply(txBuilder, opts).Build())

// register the outputs in the wallet
w.registerOutputs(transactionName, signedTransaction.Transaction, addressIndexes...)
Expand Down
20 changes: 10 additions & 10 deletions tools/docker-network/tests/dockerframework.go
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ func (d *DockerTestFramework) CreateAccount(opts ...options.Option[builder.Accou
require.NoError(d.Testing, err)

implicitAddrSigner := iotago.NewInMemoryAddressSigner(iotago.NewAddressKeysForImplicitAccountCreationAddress(receiverAddr.(*iotago.ImplicitAccountCreationAddress), implicitPrivateKey))
signedTx, err := builder.NewTransactionBuilder(apiForSlot).
signedTx, err := builder.NewTransactionBuilder(apiForSlot, implicitAddrSigner).
AddInput(&builder.TxInput{
UnlockTarget: receiverAddr,
InputID: implicitOutputID,
Expand All @@ -412,7 +412,7 @@ func (d *DockerTestFramework) CreateAccount(opts ...options.Option[builder.Accou
AddCommitmentInput(&iotago.CommitmentInput{CommitmentID: lo.Return1(issuerResp.LatestCommitment.ID())}).
AddBlockIssuanceCreditInput(&iotago.BlockIssuanceCreditInput{AccountID: accountID}).
AllotAllMana(currentSlot, accountID, 0).
Build(implicitAddrSigner)
Build()
require.NoError(d.Testing, err)

blkID := d.SubmitPayload(ctx, signedTx, wallet.NewEd25519Account(accountID, implicitPrivateKey), congestionResp, issuerResp)
Expand Down Expand Up @@ -458,7 +458,7 @@ func (d *DockerTestFramework) DelegateToValidator(from *Account, validator *Node
StartEpoch(getDelegationStartEpoch(apiForSlot, issuerResp.LatestCommitment.Slot)).
DelegatedAmount(fundsUTXOOutput.BaseTokenAmount()).MustBuild()

signedTx, err := builder.NewTransactionBuilder(apiForSlot).
signedTx, err := builder.NewTransactionBuilder(apiForSlot, fundsAddrSigner).
AddInput(&builder.TxInput{
UnlockTarget: fundsAddr,
InputID: fundsOutputID,
Expand All @@ -468,7 +468,7 @@ func (d *DockerTestFramework) DelegateToValidator(from *Account, validator *Node
SetCreationSlot(currentSlot).
AddCommitmentInput(&iotago.CommitmentInput{CommitmentID: lo.Return1(issuerResp.LatestCommitment.ID())}).
AllotAllMana(currentSlot, from.AccountID, 0).
Build(fundsAddrSigner)
Build()
require.NoError(d.Testing, err)

blkID := d.SubmitPayload(ctx, signedTx, wallet.NewEd25519Account(from.AccountID, from.BlockIssuerKey), congestionResp, issuerResp)
Expand Down Expand Up @@ -499,15 +499,15 @@ func (d *DockerTestFramework) IncreaseBIC(to *Account) {
basicOutput, err := builder.NewBasicOutputBuilder(fundsAddr, fundsUTXOOutput.BaseTokenAmount()).Build()
require.NoError(d.Testing, err)

signedTx, err := builder.NewTransactionBuilder(apiForSlot).
signedTx, err := builder.NewTransactionBuilder(apiForSlot, fundsAddrSigner).
AddInput(&builder.TxInput{
UnlockTarget: fundsAddr,
InputID: fundsOutputID,
Input: fundsUTXOOutput,
}).
AddOutput(basicOutput).
AllotAllMana(currentSlot, to.AccountID, 0).
Build(fundsAddrSigner)
Build()

blkID := d.SubmitPayload(ctx, signedTx, wallet.NewEd25519Account(to.AccountID, to.BlockIssuerKey), congestionResp, issuerResp)

Expand Down Expand Up @@ -550,7 +550,7 @@ func (d *DockerTestFramework) AllotManaTo(from *Account, to *Account, manaToAllo
congestionResp, err := clt.Congestion(ctx, from.AccountAddress, 0, lo.PanicOnErr(issuerResp.LatestCommitment.ID()))
require.NoError(d.Testing, err)

signedTx, err := builder.NewTransactionBuilder(apiForSlot).
signedTx, err := builder.NewTransactionBuilder(apiForSlot, fundsAddrSigner).
AddInput(&builder.TxInput{
UnlockTarget: fundsAddr,
InputID: fundsOutputID,
Expand All @@ -560,7 +560,7 @@ func (d *DockerTestFramework) AllotManaTo(from *Account, to *Account, manaToAllo
AddOutput(basicOutput).
SetCreationSlot(currentSlot).
AllotAllMana(currentSlot, from.AccountID, 0).
Build(fundsAddrSigner)
Build()
require.NoError(d.Testing, err)

blkID := d.SubmitPayload(ctx, signedTx, wallet.NewEd25519Account(from.AccountID, from.BlockIssuerKey), congestionResp, issuerResp)
Expand Down Expand Up @@ -611,7 +611,7 @@ func (d *DockerTestFramework) CreateNativeToken(from *Account, mintedAmount iota
congestionResp, err := clt.Congestion(ctx, from.AccountAddress, 0, lo.PanicOnErr(issuerResp.LatestCommitment.ID()))
require.NoError(d.Testing, err)

signedTx, err := builder.NewTransactionBuilder(apiForSlot).
signedTx, err := builder.NewTransactionBuilder(apiForSlot, signer).
AddInput(&builder.TxInput{
UnlockTarget: fundsAddr,
InputID: fundsOutputID,
Expand All @@ -628,7 +628,7 @@ func (d *DockerTestFramework) CreateNativeToken(from *Account, mintedAmount iota
AddBlockIssuanceCreditInput(&iotago.BlockIssuanceCreditInput{AccountID: from.AccountID}).
AddCommitmentInput(&iotago.CommitmentInput{CommitmentID: lo.Return1(issuerResp.LatestCommitment.ID())}).
AllotAllMana(currentSlot, from.AccountID, 0).
Build(signer)
Build()
require.NoError(d.Testing, err)

blkID := d.SubmitPayload(ctx, signedTx, wallet.NewEd25519Account(from.AccountID, from.BlockIssuerKey), congestionResp, issuerResp)
Expand Down
2 changes: 1 addition & 1 deletion tools/gendoc/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ require (
github.com/iotaledger/inx-app v1.0.0-rc.3.0.20240216141618-d7dfe94bdc1e // indirect
github.com/iotaledger/inx/go v1.0.0-rc.2.0.20240216141023-6d5f4ef12ac5 // indirect
github.com/iotaledger/iota-crypto-demo v0.0.0-20240216103559-27ca8dffd1e7 // indirect
github.com/iotaledger/iota.go/v4 v4.0.0-20240223110058-f304abf3efa0 // indirect
github.com/iotaledger/iota.go/v4 v4.0.0-20240228104340-25491bf70f39 // indirect
github.com/ipfs/boxo v0.17.0 // indirect
github.com/ipfs/go-cid v0.4.1 // indirect
github.com/ipfs/go-datastore v0.6.0 // indirect
Expand Down
4 changes: 2 additions & 2 deletions tools/gendoc/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -315,8 +315,8 @@ github.com/iotaledger/inx/go v1.0.0-rc.2.0.20240216141023-6d5f4ef12ac5 h1:ebh2IK
github.com/iotaledger/inx/go v1.0.0-rc.2.0.20240216141023-6d5f4ef12ac5/go.mod h1:Go1Gp6s+RCwNyaTjSw/TCk1Li5xd3+926aCu61kL+ks=
github.com/iotaledger/iota-crypto-demo v0.0.0-20240216103559-27ca8dffd1e7 h1:t6k4MqiUov0FrBb2o2JhKlOVSdlPbIQWM8ivYHL0G0g=
github.com/iotaledger/iota-crypto-demo v0.0.0-20240216103559-27ca8dffd1e7/go.mod h1:do+N3LpeDEi9qselEC4XcjqGoRc7cWGiqBtIeBOKEMs=
github.com/iotaledger/iota.go/v4 v4.0.0-20240223110058-f304abf3efa0 h1:gQjVmVSa8ezyzsE90oIz7HESKtLpGN8mSVkNX4mRysQ=
github.com/iotaledger/iota.go/v4 v4.0.0-20240223110058-f304abf3efa0/go.mod h1:IZNS0qmVdoRjIbFe4VTPG7k3bzSJQBvAHL2eC/2kFT0=
github.com/iotaledger/iota.go/v4 v4.0.0-20240228104340-25491bf70f39 h1:C6ODo+JQ04SOLC8ayo/EvBYgnO1oGOV91czUD1kTguQ=
github.com/iotaledger/iota.go/v4 v4.0.0-20240228104340-25491bf70f39/go.mod h1:IZNS0qmVdoRjIbFe4VTPG7k3bzSJQBvAHL2eC/2kFT0=
github.com/ipfs/boxo v0.17.0 h1:fVXAb12dNbraCX1Cdid5BB6Kl62gVLNVA+e0EYMqAU0=
github.com/ipfs/boxo v0.17.0/go.mod h1:pIZgTWdm3k3pLF9Uq6MB8JEcW07UDwNJjlXW1HELW80=
github.com/ipfs/go-cid v0.4.1 h1:A/T3qGvxi4kpKWWcPC/PgbvDA2bjVLO7n4UeVwnbs/s=
Expand Down

0 comments on commit 24cf994

Please sign in to comment.