diff --git a/gen/unlock_ref.tmpl b/gen/unlock_ref.tmpl index 7d5cc5fb4..e0962e9fb 100644 --- a/gen/unlock_ref.tmpl +++ b/gen/unlock_ref.tmpl @@ -4,9 +4,9 @@ import ( "github.com/iotaledger/hive.go/serializer/v2" ) -// {{.Name}} is an Unlock which references a previous unlock. +// {{.Name}} is an Unlock which references a previous input/unlock. type {{.Name}} struct { - // The other unlock this {{.Name}} references to. + // The other input/unlock this {{.Name}} references to. Reference uint16 `serix:""` } @@ -26,7 +26,7 @@ func ({{.Receiver}} *{{.Name}}) Chainable() bool { {{if index .Features "chainable"}} return true {{else}} return false {{end}} } -func ({{.Receiver}} *{{.Name}}) Ref() uint16 { +func ({{.Receiver}} *{{.Name}}) ReferencedInputIndex() uint16 { return {{.Receiver}}.Reference } diff --git a/input.go b/input.go index 6c0032eb9..1cefc66d1 100644 --- a/input.go +++ b/input.go @@ -80,17 +80,17 @@ type Input interface { Type() InputType } -// InputsSyntacticalUnique returns an ElementValidationFunc which checks that every input has a unique UTXO ref. +// InputsSyntacticalUnique returns an ElementValidationFunc which checks that every input has a unique reference UTXO index. func InputsSyntacticalUnique() ElementValidationFunc[Input] { utxoSet := map[string]int{} return func(index int, input Input) error { switch castInput := input.(type) { case *UTXOInput: - utxoRef := castInput.OutputID() - k := string(utxoRef[:]) + referencedOutputID := castInput.OutputID() + k := string(referencedOutputID[:]) if j, has := utxoSet[k]; has { - return ierrors.Wrapf(ErrInputUTXORefsNotUnique, "input %d and %d share the same UTXO ref", j, index) + return ierrors.Wrapf(ErrInputUTXORefsNotUnique, "input %d and %d share the same referenced UTXO index", j, index) } utxoSet[k] = index default: @@ -106,6 +106,7 @@ func InputsSyntacticalIndicesWithinBounds() ElementValidationFunc[Input] { return func(index int, input Input) error { switch castInput := input.(type) { case *UTXOInput: + // TODO: do we really want to check the max value on the input side? if castInput.Index() < RefUTXOIndexMin || castInput.Index() > RefUTXOIndexMax { return ierrors.Wrapf(ErrRefUTXOIndexInvalid, "input %d", index) } diff --git a/input_test.go b/input_test.go index 45e29ac43..c9548ad1d 100644 --- a/input_test.go +++ b/input_test.go @@ -131,7 +131,7 @@ func TestInputsSyntacticalIndicesWithinBounds(t *testing.T) { wantErr: nil, }, { - name: "fail - invalid UTXO ref index", + name: "fail - invalid reference UTXO index", inputs: iotago.Inputs[iotago.Input]{ &iotago.UTXOInput{ TransactionID: [36]byte{}, diff --git a/signed_transaction.go b/signed_transaction.go index 75ef7d794..c93efa97f 100644 --- a/signed_transaction.go +++ b/signed_transaction.go @@ -106,7 +106,7 @@ func (t *SignedTransaction) syntacticallyValidate() error { } if err := ValidateUnlocks(t.Unlocks, - UnlocksSigUniqueAndRefValidator(t.API), + SignatureUniqueAndReferenceUnlocksValidator(t.API), ); err != nil { return ierrors.Errorf("invalid unlocks: %w", err) } diff --git a/unlock.go b/unlock.go index d3f4946ba..a90b41e5a 100644 --- a/unlock.go +++ b/unlock.go @@ -50,8 +50,8 @@ var ( ) var ( - // ErrSigUnlockNotUnique gets returned if sig unlocks making part of a transaction aren't unique. - ErrSigUnlockNotUnique = ierrors.New("signature unlock must be unique") + // ErrSignatureUnlockNotUnique gets returned if sig unlocks making part of a transaction aren't unique. + ErrSignatureUnlockNotUnique = ierrors.New("signature unlock must be unique") // ErrUnlockSignatureInvalid gets returned when a signature in an unlock is invalid. ErrUnlockSignatureInvalid = ierrors.New("signature in unlock is invalid") // ErrMultiUnlockNotUnique gets returned if multi unlocks making part of a transaction aren't unique. @@ -62,8 +62,8 @@ var ( ErrMultiAddressLengthUnlockLengthMismatch = ierrors.New("multi address length and multi unlock length do not match") // ErrReferentialUnlockInvalid gets returned when a ReferentialUnlock is invalid. ErrReferentialUnlockInvalid = ierrors.New("invalid referential unlock") - // ErrSigUnlockHasNilSig gets returned if a signature unlock contains a nil signature. - ErrSigUnlockHasNilSig = ierrors.New("signature is nil") + // ErrSignatureUnlockHasNilSignature gets returned if a signature unlock contains a nil signature. + ErrSignatureUnlockHasNilSignature = ierrors.New("signature is nil") // ErrUnknownUnlockType gets returned for unknown unlock. ErrUnknownUnlockType = ierrors.New("unknown unlock type") // ErrNestedMultiUnlock gets returned when a MultiUnlock is nested inside a MultiUnlock. @@ -124,8 +124,8 @@ type Unlock interface { type ReferentialUnlock interface { Unlock - // Ref returns the index of the Unlock this ReferentialUnlock references. - Ref() uint16 + // ReferencedInputIndex returns the index of the Input/Unlock this ReferentialUnlock references. + ReferencedInputIndex() uint16 // Chainable indicates whether this ReferentialUnlock can reference another ReferentialUnlock. Chainable() bool // SourceAllowed tells whether the given Address is allowed to be the source of this ReferentialUnlock. @@ -145,7 +145,7 @@ func publicKeyBytesFromSignatureBlock(signature Signature) ([]byte, error) { // UnlockValidatorFunc which given the index and the Unlock itself, runs validations and returns an error if any should fail. type UnlockValidatorFunc func(index int, unlock Unlock) error -// UnlocksSigUniqueAndRefValidator returns a validator which checks that: +// SignatureUniqueAndReferenceUnlocksValidator returns a validator which checks that: // 1. SignatureUnlock(s) are unique (compared by public key) // - SignatureUnlock(s) inside different MultiUnlock(s) don't need to be unique, // as long as there is no equal SignatureUnlock(s) outside of a MultiUnlock(s). @@ -155,11 +155,11 @@ type UnlockValidatorFunc func(index int, unlock Unlock) error // 5. MultiUnlock(s) are not nested // 6. MultiUnlock(s) are unique // 7. ReferenceUnlock(s) to MultiUnlock(s) are not nested in MultiUnlock(s) -func UnlocksSigUniqueAndRefValidator(api API) UnlockValidatorFunc { - seenSigUnlocks := map[uint16]struct{}{} +func SignatureUniqueAndReferenceUnlocksValidator(api API) UnlockValidatorFunc { + seenSignatureUnlocks := map[uint16]struct{}{} seenSigBlockPubkeyBytes := map[string]int{} seenSigBlockPubkeyBytesInMultiUnlocks := map[string]int{} - seenRefUnlocks := map[uint16]ReferentialUnlock{} + seenReferentialUnlocks := map[uint16]ReferentialUnlock{} seenMultiUnlocks := map[uint16]struct{}{} seenMultiUnlockBytes := map[string]int{} @@ -167,7 +167,7 @@ func UnlocksSigUniqueAndRefValidator(api API) UnlockValidatorFunc { switch unlock := u.(type) { case *SignatureUnlock: if unlock.Signature == nil { - return ierrors.Wrapf(ErrSigUnlockHasNilSig, "at index %d is nil", index) + return ierrors.Wrapf(ErrSignatureUnlockHasNilSignature, "at index %d is nil", index) } sigBlockPubKeyBytes, err := publicKeyBytesFromSignatureBlock(unlock.Signature) @@ -177,34 +177,34 @@ func UnlocksSigUniqueAndRefValidator(api API) UnlockValidatorFunc { // we check for duplicated pubkeys in SignatureUnlock(s) if existingIndex, exists := seenSigBlockPubkeyBytes[string(sigBlockPubKeyBytes)]; exists { - return ierrors.Wrapf(ErrSigUnlockNotUnique, "signature unlock block at index %d is the same as %d", index, existingIndex) + return ierrors.Wrapf(ErrSignatureUnlockNotUnique, "signature unlock block at index %d is the same as %d", index, existingIndex) } // we also need to check for duplicated pubkeys in MultiUnlock(s) if existingIndex, exists := seenSigBlockPubkeyBytesInMultiUnlocks[string(sigBlockPubKeyBytes)]; exists { - return ierrors.Wrapf(ErrSigUnlockNotUnique, "signature unlock block at index %d is the same as in multi unlock at index %d", index, existingIndex) + return ierrors.Wrapf(ErrSignatureUnlockNotUnique, "signature unlock block at index %d is the same as in multi unlock at index %d", index, existingIndex) } - seenSigUnlocks[uint16(index)] = struct{}{} + seenSignatureUnlocks[uint16(index)] = struct{}{} seenSigBlockPubkeyBytes[string(sigBlockPubKeyBytes)] = index case ReferentialUnlock: - if prevRef := seenRefUnlocks[unlock.Ref()]; prevRef != nil { + if prevReferentialUnlock := seenReferentialUnlocks[unlock.ReferencedInputIndex()]; prevReferentialUnlock != nil { if !unlock.Chainable() { - return ierrors.Wrapf(ErrReferentialUnlockInvalid, "%d references existing referential unlock %d but it does not support chaining", index, unlock.Ref()) + return ierrors.Wrapf(ErrReferentialUnlockInvalid, "%d references existing referential unlock %d but it does not support chaining", index, unlock.ReferencedInputIndex()) } - seenRefUnlocks[uint16(index)] = unlock + seenReferentialUnlocks[uint16(index)] = unlock break } // must reference a sig or multi unlock here - _, hasSigUnlock := seenSigUnlocks[unlock.Ref()] - _, hasMultiUnlock := seenMultiUnlocks[unlock.Ref()] - if !hasSigUnlock && !hasMultiUnlock { - return ierrors.Wrapf(ErrReferentialUnlockInvalid, "%d references non existent unlock %d", index, unlock.Ref()) + _, hasSignatureUnlock := seenSignatureUnlocks[unlock.ReferencedInputIndex()] + _, hasMultiUnlock := seenMultiUnlocks[unlock.ReferencedInputIndex()] + if !hasSignatureUnlock && !hasMultiUnlock { + return ierrors.Wrapf(ErrReferentialUnlockInvalid, "%d references non existent unlock %d", index, unlock.ReferencedInputIndex()) } - seenRefUnlocks[uint16(index)] = unlock + seenReferentialUnlocks[uint16(index)] = unlock case *MultiUnlock: multiUnlockBytes, err := api.Encode(unlock) @@ -220,7 +220,7 @@ func UnlocksSigUniqueAndRefValidator(api API) UnlockValidatorFunc { switch subUnlock := subU.(type) { case *SignatureUnlock: if subUnlock.Signature == nil { - return ierrors.Wrapf(ErrSigUnlockHasNilSig, "at index %d.%d is nil", index, subIndex) + return ierrors.Wrapf(ErrSignatureUnlockHasNilSignature, "at index %d.%d is nil", index, subIndex) } sigBlockPubKeyBytes, err := publicKeyBytesFromSignatureBlock(subUnlock.Signature) @@ -230,29 +230,29 @@ func UnlocksSigUniqueAndRefValidator(api API) UnlockValidatorFunc { // we check for duplicated pubkeys in SignatureUnlock(s) if existingIndex, exists := seenSigBlockPubkeyBytes[string(sigBlockPubKeyBytes)]; exists { - return ierrors.Wrapf(ErrSigUnlockNotUnique, "signature unlock block at index %d.%d is the same as %d", index, subIndex, existingIndex) + return ierrors.Wrapf(ErrSignatureUnlockNotUnique, "signature unlock block at index %d.%d is the same as %d", index, subIndex, existingIndex) } - // we don't set the index here in "seenSigUnlocks" because there is no concept of reference unlocks inside of multi unlocks + // we don't set the index here in "seenSignatureUnlocks" because there is no concept of reference unlocks inside of multi unlocks // add the pubkey to "seenSigBlockPubkeyBytesInMultiUnlocks", so we can check that pubkeys from a multi unlock are not reused in a normal SignatureUnlock seenSigBlockPubkeyBytesInMultiUnlocks[string(sigBlockPubKeyBytes)] = index case ReferentialUnlock: - if prevRef := seenRefUnlocks[subUnlock.Ref()]; prevRef != nil { + if prevRef := seenReferentialUnlocks[subUnlock.ReferencedInputIndex()]; prevRef != nil { if !subUnlock.Chainable() { - return ierrors.Wrapf(ErrReferentialUnlockInvalid, "%d.%d references existing referential unlock %d but it does not support chaining", index, subIndex, subUnlock.Ref()) + return ierrors.Wrapf(ErrReferentialUnlockInvalid, "%d.%d references existing referential unlock %d but it does not support chaining", index, subIndex, subUnlock.ReferencedInputIndex()) } - // we don't set the index here in "seenRefUnlocks" because it's not allowed to reference an unlock within a multi unlock + // we don't set the index here in "seenReferentialUnlocks" because it's not allowed to reference an unlock within a multi unlock continue } // must reference a sig unlock here // we don't check for "seenMultiUnlocks" here because we don't want to nest "reference unlocks to multi unlocks" in multi unlocks - if _, has := seenSigUnlocks[subUnlock.Ref()]; !has { - return ierrors.Wrapf(ErrReferentialUnlockInvalid, "%d.%d references non existent unlock %d", index, subIndex, subUnlock.Ref()) + if _, has := seenSignatureUnlocks[subUnlock.ReferencedInputIndex()]; !has { + return ierrors.Wrapf(ErrReferentialUnlockInvalid, "%d.%d references non existent unlock %d", index, subIndex, subUnlock.ReferencedInputIndex()) } - // we don't set the index here in "seenRefUnlocks" because it's not allowed to reference an unlock within a multi unlock + // we don't set the index here in "seenReferentialUnlocks" because it's not allowed to reference an unlock within a multi unlock case *MultiUnlock: return ierrors.Wrapf(ErrNestedMultiUnlock, "unlock at index %d.%d is invalid", index, subIndex) diff --git a/unlock_account.gen.go b/unlock_account.gen.go index 4b96e2faf..070d2045b 100644 --- a/unlock_account.gen.go +++ b/unlock_account.gen.go @@ -4,9 +4,9 @@ import ( "github.com/iotaledger/hive.go/serializer/v2" ) -// AccountUnlock is an Unlock which references a previous unlock. +// AccountUnlock is an Unlock which references a previous input/unlock. type AccountUnlock struct { - // The other unlock this AccountUnlock references to. + // The other input/unlock this AccountUnlock references to. Reference uint16 `serix:""` } @@ -26,7 +26,7 @@ func (r *AccountUnlock) Chainable() bool { return true } -func (r *AccountUnlock) Ref() uint16 { +func (r *AccountUnlock) ReferencedInputIndex() uint16 { return r.Reference } diff --git a/unlock_anchor.gen.go b/unlock_anchor.gen.go index 02f799c3a..9017b0946 100644 --- a/unlock_anchor.gen.go +++ b/unlock_anchor.gen.go @@ -4,9 +4,9 @@ import ( "github.com/iotaledger/hive.go/serializer/v2" ) -// AnchorUnlock is an Unlock which references a previous unlock. +// AnchorUnlock is an Unlock which references a previous input/unlock. type AnchorUnlock struct { - // The other unlock this AnchorUnlock references to. + // The other input/unlock this AnchorUnlock references to. Reference uint16 `serix:""` } @@ -26,7 +26,7 @@ func (r *AnchorUnlock) Chainable() bool { return true } -func (r *AnchorUnlock) Ref() uint16 { +func (r *AnchorUnlock) ReferencedInputIndex() uint16 { return r.Reference } diff --git a/unlock_nft.gen.go b/unlock_nft.gen.go index 4b3e6a1a0..38f979727 100644 --- a/unlock_nft.gen.go +++ b/unlock_nft.gen.go @@ -4,9 +4,9 @@ import ( "github.com/iotaledger/hive.go/serializer/v2" ) -// NFTUnlock is an Unlock which references a previous unlock. +// NFTUnlock is an Unlock which references a previous input/unlock. type NFTUnlock struct { - // The other unlock this NFTUnlock references to. + // The other input/unlock this NFTUnlock references to. Reference uint16 `serix:""` } @@ -26,7 +26,7 @@ func (r *NFTUnlock) Chainable() bool { return true } -func (r *NFTUnlock) Ref() uint16 { +func (r *NFTUnlock) ReferencedInputIndex() uint16 { return r.Reference } diff --git a/unlock_reference.gen.go b/unlock_reference.gen.go index 250c74642..fe57122a0 100644 --- a/unlock_reference.gen.go +++ b/unlock_reference.gen.go @@ -4,9 +4,9 @@ import ( "github.com/iotaledger/hive.go/serializer/v2" ) -// ReferenceUnlock is an Unlock which references a previous unlock. +// ReferenceUnlock is an Unlock which references a previous input/unlock. type ReferenceUnlock struct { - // The other unlock this ReferenceUnlock references to. + // The other input/unlock this ReferenceUnlock references to. Reference uint16 `serix:""` } @@ -26,7 +26,7 @@ func (r *ReferenceUnlock) Chainable() bool { return false } -func (r *ReferenceUnlock) Ref() uint16 { +func (r *ReferenceUnlock) ReferencedInputIndex() uint16 { return r.Reference } diff --git a/unlock_test.go b/unlock_test.go index 4aa18aaac..83637f143 100644 --- a/unlock_test.go +++ b/unlock_test.go @@ -50,7 +50,7 @@ func TestUnlock_DeSerialize(t *testing.T) { } } -func TestUnlocksSigUniqueAndRefValidator(t *testing.T) { +func TestSignatureUniqueAndReferenceUnlocksValidator(t *testing.T) { tests := []struct { name string unlocks iotago.Unlocks @@ -119,7 +119,7 @@ func TestUnlocksSigUniqueAndRefValidator(t *testing.T) { Signature: [64]byte{}, }}, }, - wantErr: iotago.ErrSigUnlockNotUnique, + wantErr: iotago.ErrSignatureUnlockNotUnique, }, { name: "fail - signature reuse outside and inside the multi unlocks - 1", @@ -137,7 +137,7 @@ func TestUnlocksSigUniqueAndRefValidator(t *testing.T) { }, }, }, - wantErr: iotago.ErrSigUnlockNotUnique, + wantErr: iotago.ErrSignatureUnlockNotUnique, }, { name: "fail - signature reuse outside and inside the multi unlocks - 2", @@ -159,7 +159,7 @@ func TestUnlocksSigUniqueAndRefValidator(t *testing.T) { Signature: [64]byte{}, }}, }, - wantErr: iotago.ErrSigUnlockNotUnique, + wantErr: iotago.ErrSignatureUnlockNotUnique, }, { name: "ok - duplicate ed25519 sig block in different multi unlocks", @@ -210,7 +210,7 @@ func TestUnlocksSigUniqueAndRefValidator(t *testing.T) { wantErr: iotago.ErrMultiUnlockNotUnique, }, { - name: "fail - reference unlock invalid ref", + name: "fail - reference unlock invalid reference", unlocks: iotago.Unlocks{ tpkg.RandEd25519SignatureUnlock(), tpkg.RandEd25519SignatureUnlock(), @@ -219,7 +219,7 @@ func TestUnlocksSigUniqueAndRefValidator(t *testing.T) { wantErr: iotago.ErrReferentialUnlockInvalid, }, { - name: "fail - reference unlock invalid ref in multi unlock", + name: "fail - reference unlock invalid reference in multi unlock", unlocks: iotago.Unlocks{ tpkg.RandEd25519SignatureUnlock(), tpkg.RandEd25519SignatureUnlock(), @@ -232,7 +232,7 @@ func TestUnlocksSigUniqueAndRefValidator(t *testing.T) { wantErr: iotago.ErrReferentialUnlockInvalid, }, { - name: "fail - reference unlock refs non sig unlock", + name: "fail - reference unlock references non sig unlock", unlocks: iotago.Unlocks{ tpkg.RandEd25519SignatureUnlock(), &iotago.ReferenceUnlock{Reference: 0}, @@ -241,7 +241,7 @@ func TestUnlocksSigUniqueAndRefValidator(t *testing.T) { wantErr: iotago.ErrReferentialUnlockInvalid, }, { - name: "fail - reference unlock refs non sig unlock in multi unlock", + name: "fail - reference unlock references non sig unlock in multi unlock", unlocks: iotago.Unlocks{ tpkg.RandEd25519SignatureUnlock(), &iotago.ReferenceUnlock{Reference: 0}, @@ -318,7 +318,7 @@ func TestUnlocksSigUniqueAndRefValidator(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - valFunc := iotago.UnlocksSigUniqueAndRefValidator(tpkg.ZeroCostTestAPI) + valFunc := iotago.SignatureUniqueAndReferenceUnlocksValidator(tpkg.ZeroCostTestAPI) var runErr error for index, unlock := range tt.unlocks { if err := valFunc(index, unlock); err != nil { diff --git a/vm/nova/stvf_test.go b/vm/nova/stvf_test.go index a531f433a..f16b4ac34 100644 --- a/vm/nova/stvf_test.go +++ b/vm/nova/stvf_test.go @@ -96,7 +96,7 @@ func TestAccountOutput_ValidateStateTransition(t *testing.T) { API: tpkg.ZeroCostTestAPI, WorkingSet: &vm.WorkingSet{ UnlockedAddrs: vm.UnlockedAddresses{ - exampleIssuer.Key(): {UnlockedAt: 0}, + exampleIssuer.Key(): {UnlockedAtInputIndex: 0}, }, Tx: &iotago.Transaction{ TransactionEssence: &iotago.TransactionEssence{ @@ -134,7 +134,7 @@ func TestAccountOutput_ValidateStateTransition(t *testing.T) { Slot: 900, }, UnlockedAddrs: vm.UnlockedAddresses{ - exampleIssuer.Key(): {UnlockedAt: 0}, + exampleIssuer.Key(): {UnlockedAtInputIndex: 0}, }, Tx: &iotago.Transaction{ API: tpkg.ZeroCostTestAPI, @@ -174,7 +174,7 @@ func TestAccountOutput_ValidateStateTransition(t *testing.T) { Slot: 10001, }, UnlockedAddrs: vm.UnlockedAddresses{ - exampleIssuer.Key(): {UnlockedAt: 0}, + exampleIssuer.Key(): {UnlockedAtInputIndex: 0}, }, Tx: &iotago.Transaction{ API: tpkg.ZeroCostTestAPI, @@ -214,7 +214,7 @@ func TestAccountOutput_ValidateStateTransition(t *testing.T) { Slot: 991, }, UnlockedAddrs: vm.UnlockedAddresses{ - exampleIssuer.Key(): {UnlockedAt: 0}, + exampleIssuer.Key(): {UnlockedAtInputIndex: 0}, }, Tx: &iotago.Transaction{ API: tpkg.ZeroCostTestAPI, @@ -254,7 +254,7 @@ func TestAccountOutput_ValidateStateTransition(t *testing.T) { Slot: currentSlot, }, UnlockedAddrs: vm.UnlockedAddresses{ - exampleIssuer.Key(): {UnlockedAt: 0}, + exampleIssuer.Key(): {UnlockedAtInputIndex: 0}, }, Tx: &iotago.Transaction{ API: tpkg.ZeroCostTestAPI, @@ -295,7 +295,7 @@ func TestAccountOutput_ValidateStateTransition(t *testing.T) { Slot: currentSlot, }, UnlockedAddrs: vm.UnlockedAddresses{ - exampleIssuer.Key(): {UnlockedAt: 0}, + exampleIssuer.Key(): {UnlockedAtInputIndex: 0}, }, Tx: &iotago.Transaction{ API: tpkg.ZeroCostTestAPI, @@ -336,7 +336,7 @@ func TestAccountOutput_ValidateStateTransition(t *testing.T) { Slot: currentSlot, }, UnlockedAddrs: vm.UnlockedAddresses{ - exampleIssuer.Key(): {UnlockedAt: 0}, + exampleIssuer.Key(): {UnlockedAtInputIndex: 0}, }, Tx: &iotago.Transaction{ API: tpkg.ZeroCostTestAPI, @@ -376,7 +376,7 @@ func TestAccountOutput_ValidateStateTransition(t *testing.T) { Slot: currentSlot, }, UnlockedAddrs: vm.UnlockedAddresses{ - exampleIssuer.Key(): {UnlockedAt: 0}, + exampleIssuer.Key(): {UnlockedAtInputIndex: 0}, }, Tx: &iotago.Transaction{ API: tpkg.ZeroCostTestAPI, @@ -436,7 +436,7 @@ func TestAccountOutput_ValidateStateTransition(t *testing.T) { Slot: currentSlot, }, UnlockedAddrs: vm.UnlockedAddresses{ - exampleIssuer.Key(): {UnlockedAt: 0}, + exampleIssuer.Key(): {UnlockedAtInputIndex: 0}, }, Tx: &iotago.Transaction{ API: tpkg.ZeroCostTestAPI, @@ -489,7 +489,7 @@ func TestAccountOutput_ValidateStateTransition(t *testing.T) { Slot: currentSlot, }, UnlockedAddrs: vm.UnlockedAddresses{ - exampleIssuer.Key(): {UnlockedAt: 0}, + exampleIssuer.Key(): {UnlockedAtInputIndex: 0}, }, Tx: &iotago.Transaction{ TransactionEssence: &iotago.TransactionEssence{ @@ -540,7 +540,7 @@ func TestAccountOutput_ValidateStateTransition(t *testing.T) { Slot: currentSlot, }, UnlockedAddrs: vm.UnlockedAddresses{ - exampleIssuer.Key(): {UnlockedAt: 0}, + exampleIssuer.Key(): {UnlockedAtInputIndex: 0}, }, Tx: &iotago.Transaction{ TransactionEssence: &iotago.TransactionEssence{ @@ -586,7 +586,7 @@ func TestAccountOutput_ValidateStateTransition(t *testing.T) { Slot: currentSlot, }, UnlockedAddrs: vm.UnlockedAddresses{ - exampleIssuer.Key(): {UnlockedAt: 0}, + exampleIssuer.Key(): {UnlockedAtInputIndex: 0}, }, Tx: &iotago.Transaction{ API: tpkg.ZeroCostTestAPI, @@ -642,7 +642,7 @@ func TestAccountOutput_ValidateStateTransition(t *testing.T) { Slot: currentSlot, }, UnlockedAddrs: vm.UnlockedAddresses{ - exampleIssuer.Key(): {UnlockedAt: 0}, + exampleIssuer.Key(): {UnlockedAtInputIndex: 0}, }, Tx: &iotago.Transaction{ API: tpkg.ZeroCostTestAPI, @@ -702,7 +702,7 @@ func TestAccountOutput_ValidateStateTransition(t *testing.T) { Slot: currentSlot, }, UnlockedAddrs: vm.UnlockedAddresses{ - exampleIssuer.Key(): {UnlockedAt: 0}, + exampleIssuer.Key(): {UnlockedAtInputIndex: 0}, }, Tx: &iotago.Transaction{ API: tpkg.ZeroCostTestAPI, @@ -762,7 +762,7 @@ func TestAccountOutput_ValidateStateTransition(t *testing.T) { Slot: currentSlot, }, UnlockedAddrs: vm.UnlockedAddresses{ - exampleIssuer.Key(): {UnlockedAt: 0}, + exampleIssuer.Key(): {UnlockedAtInputIndex: 0}, }, Tx: &iotago.Transaction{ API: tpkg.ZeroCostTestAPI, @@ -824,7 +824,7 @@ func TestAccountOutput_ValidateStateTransition(t *testing.T) { Slot: currentSlot, }, UnlockedAddrs: vm.UnlockedAddresses{ - exampleIssuer.Key(): {UnlockedAt: 0}, + exampleIssuer.Key(): {UnlockedAtInputIndex: 0}, }, Tx: &iotago.Transaction{ API: tpkg.ZeroCostTestAPI, @@ -878,7 +878,7 @@ func TestAccountOutput_ValidateStateTransition(t *testing.T) { Slot: currentSlot, }, UnlockedAddrs: vm.UnlockedAddresses{ - exampleIssuer.Key(): {UnlockedAt: 0}, + exampleIssuer.Key(): {UnlockedAtInputIndex: 0}, }, Tx: &iotago.Transaction{ API: tpkg.ZeroCostTestAPI, @@ -938,7 +938,7 @@ func TestAccountOutput_ValidateStateTransition(t *testing.T) { Slot: currentSlot, }, UnlockedAddrs: vm.UnlockedAddresses{ - exampleIssuer.Key(): {UnlockedAt: 0}, + exampleIssuer.Key(): {UnlockedAtInputIndex: 0}, }, Tx: &iotago.Transaction{ API: tpkg.ZeroCostTestAPI, @@ -998,7 +998,7 @@ func TestAccountOutput_ValidateStateTransition(t *testing.T) { Slot: currentSlot, }, UnlockedAddrs: vm.UnlockedAddresses{ - exampleIssuer.Key(): {UnlockedAt: 0}, + exampleIssuer.Key(): {UnlockedAtInputIndex: 0}, }, Tx: &iotago.Transaction{ API: tpkg.ZeroCostTestAPI, @@ -1061,7 +1061,7 @@ func TestAccountOutput_ValidateStateTransition(t *testing.T) { Slot: currentSlot, }, UnlockedAddrs: vm.UnlockedAddresses{ - exampleIssuer.Key(): {UnlockedAt: 0}, + exampleIssuer.Key(): {UnlockedAtInputIndex: 0}, }, Tx: &iotago.Transaction{ API: tpkg.ZeroCostTestAPI, @@ -1112,7 +1112,7 @@ func TestAccountOutput_ValidateStateTransition(t *testing.T) { Slot: currentSlot, }, UnlockedAddrs: vm.UnlockedAddresses{ - exampleIssuer.Key(): {UnlockedAt: 0}, + exampleIssuer.Key(): {UnlockedAtInputIndex: 0}, }, Tx: &iotago.Transaction{ API: tpkg.ZeroCostTestAPI, @@ -1452,7 +1452,7 @@ func TestAccountOutput_ValidateStateTransition(t *testing.T) { API: tpkg.ZeroCostTestAPI, WorkingSet: &vm.WorkingSet{ UnlockedAddrs: vm.UnlockedAddresses{ - exampleAddress.Key(): {UnlockedAt: 0}, + exampleAddress.Key(): {UnlockedAtInputIndex: 0}, }, Commitment: &iotago.Commitment{ Slot: 990, @@ -1536,7 +1536,7 @@ func TestAccountOutput_ValidateStateTransition(t *testing.T) { Slot: 990, }, UnlockedAddrs: vm.UnlockedAddresses{ - exampleAddress.Key(): {UnlockedAt: 0}, + exampleAddress.Key(): {UnlockedAtInputIndex: 0}, }, BIC: map[iotago.AccountID]iotago.BlockIssuanceCredits{ exampleAccountID: 10, @@ -1589,7 +1589,7 @@ func TestAccountOutput_ValidateStateTransition(t *testing.T) { API: tpkg.ZeroCostTestAPI, WorkingSet: &vm.WorkingSet{ UnlockedAddrs: vm.UnlockedAddresses{ - exampleAddress.Key(): {UnlockedAt: 0}, + exampleAddress.Key(): {UnlockedAtInputIndex: 0}, }, Tx: &iotago.Transaction{ TransactionEssence: &iotago.TransactionEssence{ @@ -1641,7 +1641,7 @@ func TestAccountOutput_ValidateStateTransition(t *testing.T) { Slot: 990, }, UnlockedAddrs: vm.UnlockedAddresses{ - exampleAddress.Key(): {UnlockedAt: 0}, + exampleAddress.Key(): {UnlockedAtInputIndex: 0}, }, BIC: map[iotago.AccountID]iotago.BlockIssuanceCredits{ exampleAccountID: 10, @@ -1699,7 +1699,7 @@ func TestAccountOutput_ValidateStateTransition(t *testing.T) { Slot: 990, }, UnlockedAddrs: vm.UnlockedAddresses{ - exampleAddress.Key(): {UnlockedAt: 0}, + exampleAddress.Key(): {UnlockedAtInputIndex: 0}, }, BIC: map[iotago.AccountID]iotago.BlockIssuanceCredits{ exampleAccountID: 10, @@ -1758,7 +1758,7 @@ func TestAccountOutput_ValidateStateTransition(t *testing.T) { Slot: 900, }, UnlockedAddrs: vm.UnlockedAddresses{ - exampleAddress.Key(): {UnlockedAt: 0}, + exampleAddress.Key(): {UnlockedAtInputIndex: 0}, }, BIC: map[iotago.AccountID]iotago.BlockIssuanceCredits{ exampleAccountID: -1, @@ -1816,7 +1816,7 @@ func TestAccountOutput_ValidateStateTransition(t *testing.T) { Slot: 900, }, UnlockedAddrs: vm.UnlockedAddresses{ - exampleAddress.Key(): {UnlockedAt: 0}, + exampleAddress.Key(): {UnlockedAtInputIndex: 0}, }, Tx: &iotago.Transaction{ @@ -1872,7 +1872,7 @@ func TestAccountOutput_ValidateStateTransition(t *testing.T) { Slot: 900, }, UnlockedAddrs: vm.UnlockedAddresses{ - exampleAddress.Key(): {UnlockedAt: 0}, + exampleAddress.Key(): {UnlockedAtInputIndex: 0}, }, BIC: map[iotago.AccountID]iotago.BlockIssuanceCredits{ exampleAccountID: 10, @@ -1931,7 +1931,7 @@ func TestAccountOutput_ValidateStateTransition(t *testing.T) { Slot: 0, }, UnlockedAddrs: vm.UnlockedAddresses{ - exampleAddress.Key(): {UnlockedAt: 0}, + exampleAddress.Key(): {UnlockedAtInputIndex: 0}, }, InChains: map[iotago.ChainID]*vm.ChainOutputWithIDs{ // serial number 5 @@ -2085,7 +2085,7 @@ func TestAnchorOutput_ValidateStateTransition(t *testing.T) { API: tpkg.ZeroCostTestAPI, WorkingSet: &vm.WorkingSet{ UnlockedAddrs: vm.UnlockedAddresses{ - exampleIssuer.Key(): {UnlockedAt: 0}, + exampleIssuer.Key(): {UnlockedAtInputIndex: 0}, }, Tx: &iotago.Transaction{ TransactionEssence: &iotago.TransactionEssence{ @@ -2163,7 +2163,7 @@ func TestAnchorOutput_ValidateStateTransition(t *testing.T) { API: tpkg.ZeroCostTestAPI, WorkingSet: &vm.WorkingSet{ UnlockedAddrs: vm.UnlockedAddresses{ - exampleGovCtrl.Key(): {UnlockedAt: 0}, + exampleGovCtrl.Key(): {UnlockedAtInputIndex: 0}, }, Commitment: &iotago.Commitment{ Slot: 990, @@ -2216,7 +2216,7 @@ func TestAnchorOutput_ValidateStateTransition(t *testing.T) { API: tpkg.ZeroCostTestAPI, WorkingSet: &vm.WorkingSet{ UnlockedAddrs: vm.UnlockedAddresses{ - exampleStateCtrl.Key(): {UnlockedAt: 0}, + exampleStateCtrl.Key(): {UnlockedAtInputIndex: 0}, }, Tx: &iotago.Transaction{ API: tpkg.ZeroCostTestAPI, @@ -2263,7 +2263,7 @@ func TestAnchorOutput_ValidateStateTransition(t *testing.T) { API: tpkg.ZeroCostTestAPI, WorkingSet: &vm.WorkingSet{ UnlockedAddrs: vm.UnlockedAddresses{ - exampleStateCtrl.Key(): {UnlockedAt: 0}, + exampleStateCtrl.Key(): {UnlockedAtInputIndex: 0}, }, Tx: &iotago.Transaction{ TransactionEssence: &iotago.TransactionEssence{ @@ -2308,7 +2308,7 @@ func TestAnchorOutput_ValidateStateTransition(t *testing.T) { API: tpkg.ZeroCostTestAPI, WorkingSet: &vm.WorkingSet{ UnlockedAddrs: vm.UnlockedAddresses{ - exampleStateCtrl.Key(): {UnlockedAt: 0}, + exampleStateCtrl.Key(): {UnlockedAtInputIndex: 0}, }, Tx: &iotago.Transaction{ TransactionEssence: &iotago.TransactionEssence{ @@ -3034,7 +3034,7 @@ func TestNFTOutput_ValidateStateTransition(t *testing.T) { API: tpkg.ZeroCostTestAPI, WorkingSet: &vm.WorkingSet{ UnlockedAddrs: vm.UnlockedAddresses{ - exampleIssuer.Key(): {UnlockedAt: 0}, + exampleIssuer.Key(): {UnlockedAtInputIndex: 0}, }, Tx: &iotago.Transaction{ TransactionEssence: &iotago.TransactionEssence{ @@ -3751,7 +3751,7 @@ func TestImplicitAccountOutput_ValidateStateTransition(t *testing.T) { API: tpkg.ZeroCostTestAPI, WorkingSet: &vm.WorkingSet{ UnlockedAddrs: vm.UnlockedAddresses{ - exampleIssuer.Key(): {UnlockedAt: 0}, + exampleIssuer.Key(): {UnlockedAtInputIndex: 0}, }, BIC: exampleBIC, Commitment: &iotago.Commitment{ @@ -3796,7 +3796,7 @@ func TestImplicitAccountOutput_ValidateStateTransition(t *testing.T) { API: tpkg.ZeroCostTestAPI, WorkingSet: &vm.WorkingSet{ UnlockedAddrs: vm.UnlockedAddresses{ - exampleIssuer.Key(): {UnlockedAt: 0}, + exampleIssuer.Key(): {UnlockedAtInputIndex: 0}, }, BIC: exampleBIC, Commitment: &iotago.Commitment{ diff --git a/vm/nova/vm.go b/vm/nova/vm.go index 4b704404c..7177e344f 100644 --- a/vm/nova/vm.go +++ b/vm/nova/vm.go @@ -35,12 +35,12 @@ func NewVMParamsWorkingSet(api iotago.API, t *iotago.Transaction, resolvedInputs workingSet.Tx = t workingSet.UnlockedAddrs = make(vm.UnlockedAddresses) workingSet.UTXOInputsSet = utxoInputsSet - workingSet.InputIDToIndex = make(map[iotago.OutputID]uint16) - for inputIndex, inputRef := range workingSet.Tx.TransactionEssence.Inputs { + workingSet.InputIDToInputIndex = make(map[iotago.OutputID]uint16) + for inputIndex, txInput := range workingSet.Tx.TransactionEssence.Inputs { //nolint:forcetypeassert // we can safely assume that this is an UTXOInput - ref := inputRef.(*iotago.UTXOInput).OutputID() - workingSet.InputIDToIndex[ref] = uint16(inputIndex) - input, ok := workingSet.UTXOInputsSet[ref] + txInputID := txInput.(*iotago.UTXOInput).OutputID() + workingSet.InputIDToInputIndex[txInputID] = uint16(inputIndex) + input, ok := workingSet.UTXOInputsSet[txInputID] if !ok { return nil, ierrors.Wrapf(iotago.ErrMissingUTXO, "utxo for input %d not supplied", inputIndex) } diff --git a/vm/vm.go b/vm/vm.go index ca5ef24bd..b57152d1a 100644 --- a/vm/vm.go +++ b/vm/vm.go @@ -38,7 +38,7 @@ type WorkingSet struct { // The mapping of OutputID to the actual inputs. UTXOInputsSet InputSet // The mapping of inputs' OutputID to the index. - InputIDToIndex map[iotago.OutputID]uint16 + InputIDToInputIndex map[iotago.OutputID]uint16 // The transaction for which this semantic validation happens. Tx *iotago.Transaction // The message which signatures are signing. @@ -159,9 +159,9 @@ func RunVMFuncs(vm VirtualMachine, vmParams *Params, execFuncs ...ExecFunc) erro // The value represent the index of the unlock which unlocked the address. type UnlockedAddresses map[string]*unlockedAddress -// SigUnlock performs a signature unlock check and adds the given address to the set of unlocked addresses if +// SignatureUnlock performs a signature unlock check and adds the given address to the set of unlocked addresses if // the signature is valid, otherwise returns an error. -func (unlockedAddrs UnlockedAddresses) SigUnlock(addr iotago.DirectUnlockableAddress, essence []byte, sig iotago.Signature, inputIndex uint16, checkUnlockOnly bool) error { +func (unlockedAddrs UnlockedAddresses) SignatureUnlock(addr iotago.DirectUnlockableAddress, essence []byte, sig iotago.Signature, inputIndex uint16, checkUnlockOnly bool) error { if err := addr.Unlock(essence, sig); err != nil { return ierrors.Wrapf(err, "input %d's address is not unlocked through its signature unlock", inputIndex) } @@ -171,27 +171,27 @@ func (unlockedAddrs UnlockedAddresses) SigUnlock(addr iotago.DirectUnlockableAdd } unlockedAddrs[addr.Key()] = &unlockedAddress{ - Address: addr, - UnlockedAt: inputIndex, - ReferencedBy: map[uint16]struct{}{}, + Address: addr, + UnlockedAtInputIndex: inputIndex, + ReferencedByInputIndex: map[uint16]struct{}{}, } return nil } -// RefUnlock performs a check whether the given address is unlocked at ref and if so, +// ReferentialUnlock performs a check whether the given address is unlocked at referenceInputIndex and if so, // adds the index of the input to the set of unlocked inputs by this address. -func (unlockedAddrs UnlockedAddresses) RefUnlock(addrKey string, ref uint16, inputIndex uint16, checkUnlockOnly bool) error { +func (unlockedAddrs UnlockedAddresses) ReferentialUnlock(addrKey string, referenceInputIndex uint16, inputIndex uint16, checkUnlockOnly bool) error { addr, has := unlockedAddrs[addrKey] - if !has || addr.UnlockedAt != ref { - return ierrors.Errorf("input %d is not unlocked through input %d's unlock", inputIndex, ref) + if !has || addr.UnlockedAtInputIndex != referenceInputIndex { + return ierrors.Errorf("input %d is not unlocked through input %d's unlock", inputIndex, referenceInputIndex) } if checkUnlockOnly { return nil } - addr.ReferencedBy[inputIndex] = struct{}{} + addr.ReferencedByInputIndex[inputIndex] = struct{}{} return nil } @@ -230,9 +230,9 @@ func (unlockedAddrs UnlockedAddresses) MultiUnlock(addr *iotago.MultiAddress, mu } unlockedAddrs[addr.Key()] = &unlockedAddress{ - Address: addr, - UnlockedAt: inputIndex, - ReferencedBy: map[uint16]struct{}{}, + Address: addr, + UnlockedAtInputIndex: inputIndex, + ReferencedByInputIndex: map[uint16]struct{}{}, } return nil @@ -241,9 +241,9 @@ func (unlockedAddrs UnlockedAddresses) MultiUnlock(addr *iotago.MultiAddress, mu // AddUnlockedChain allocates an unlockedAddress for the given chain. func (unlockedAddrs UnlockedAddresses) AddUnlockedChain(chainAddr iotago.ChainAddress, inputIndex uint16) { unlockedAddrs[chainAddr.Key()] = &unlockedAddress{ - Address: chainAddr, - UnlockedAt: inputIndex, - ReferencedBy: map[uint16]struct{}{}, + Address: chainAddr, + UnlockedAtInputIndex: inputIndex, + ReferencedByInputIndex: map[uint16]struct{}{}, } } @@ -254,7 +254,7 @@ func (unlockedAddrs UnlockedAddresses) String() string { addrs = append(addrs, addr) } sort.Slice(addrs, func(i, j int) bool { - x, y := addrs[i].UnlockedAt, addrs[j].UnlockedAt + x, y := addrs[i].UnlockedAtInputIndex, addrs[j].UnlockedAtInputIndex // prefer to show direct unlockable addresses first in string if x == y { if _, is := addrs[i].Address.(iotago.ChainAddress); is { @@ -281,11 +281,11 @@ func (unlockedAddrs UnlockedAddresses) UnlockedBy(inputIndex uint16, addrKey str return false } - if unlockedAddr.UnlockedAt == inputIndex { + if unlockedAddr.UnlockedAtInputIndex == inputIndex { return true } - _, refUnlocked := unlockedAddr.ReferencedBy[inputIndex] + _, refUnlocked := unlockedAddr.ReferencedByInputIndex[inputIndex] return refUnlocked } @@ -294,21 +294,21 @@ func (unlockedAddrs UnlockedAddresses) UnlockedBy(inputIndex uint16, addrKey str type unlockedAddress struct { // The source address which got unlocked. Address iotago.Address - // The index at which this address has been unlocked. - UnlockedAt uint16 - // A set of input/unlock-block indices which referenced this unlocked address. - ReferencedBy map[uint16]struct{} + // The index of the input/unlock by which this address has been unlocked. + UnlockedAtInputIndex uint16 + // A set of input/unlock indexes which referenced this address. + ReferencedByInputIndex map[uint16]struct{} } func (unlockedAddr *unlockedAddress) String() string { - refs := make([]int, 0, len(unlockedAddr.ReferencedBy)) - for ref := range unlockedAddr.ReferencedBy { - refs = append(refs, int(ref)) + inputIndexes := make([]int, 0, len(unlockedAddr.ReferencedByInputIndex)) + for inputIndex := range unlockedAddr.ReferencedByInputIndex { + inputIndexes = append(inputIndexes, int(inputIndex)) } - sort.Ints(refs) + sort.Ints(inputIndexes) - return fmt.Sprintf("address %s (%s), unlocked at %d, ref unlocks at %v", unlockedAddr.Address, unlockedAddr.Address.Type(), - unlockedAddr.UnlockedAt, refs) + return fmt.Sprintf("address %s (%s), unlocked at %d, referenced by unlocks at %v", unlockedAddr.Address, unlockedAddr.Address.Type(), + unlockedAddr.UnlockedAtInputIndex, inputIndexes) } // IsIssuerOnOutputUnlocked checks whether the issuer in an IssuerFeature of this new ChainOutput has been unlocked. @@ -451,15 +451,15 @@ func checkExpiration(output iotago.Output, commitmentInput VMCommitmentInput, pr func unlockAddress(ownerAddr iotago.Address, unlock iotago.Unlock, inputIndex uint16, unlockedAddrs UnlockedAddresses, essenceMsgToSign []byte, checkUnlockOnly bool) error { switch owner := ownerAddr.(type) { case iotago.ChainAddress: - refUnlock, isReferentialUnlock := unlock.(iotago.ReferentialUnlock) - if !isReferentialUnlock || !refUnlock.Chainable() || !refUnlock.SourceAllowed(ownerAddr) { + referentialUnlock, isReferentialUnlock := unlock.(iotago.ReferentialUnlock) + if !isReferentialUnlock || !referentialUnlock.Chainable() || !referentialUnlock.SourceAllowed(ownerAddr) { return ierrors.WithMessagef( iotago.ErrChainAddressUnlockInvalid, "input %d has a chain address of type %s but its corresponding unlock is of type %s", inputIndex, owner.Type(), unlock.Type(), ) } - if err := unlockedAddrs.RefUnlock(owner.Key(), refUnlock.Ref(), inputIndex, checkUnlockOnly); err != nil { + if err := unlockedAddrs.ReferentialUnlock(owner.Key(), referentialUnlock.ReferencedInputIndex(), inputIndex, checkUnlockOnly); err != nil { return ierrors.Errorf("%w %s (%s): %w", iotago.ErrChainAddressUnlockInvalid, owner, owner.Type(), err) } @@ -474,7 +474,7 @@ func unlockAddress(ownerAddr iotago.Address, unlock iotago.Unlock, inputIndex ui ) } - if err := unlockedAddrs.RefUnlock(owner.Key(), uBlock.Ref(), inputIndex, checkUnlockOnly); err != nil { + if err := unlockedAddrs.ReferentialUnlock(owner.Key(), uBlock.ReferencedInputIndex(), inputIndex, checkUnlockOnly); err != nil { return ierrors.Errorf("%w %s (%s): %w", iotago.ErrDirectUnlockableAddressUnlockInvalid, owner, owner.Type(), err) } @@ -483,11 +483,11 @@ func unlockAddress(ownerAddr iotago.Address, unlock iotago.Unlock, inputIndex ui if unlockedAddr, wasAlreadyUnlocked := unlockedAddrs[owner.Key()]; wasAlreadyUnlocked { return ierrors.WithMessagef( iotago.ErrDirectUnlockableAddressUnlockInvalid, - "input %d's address is already unlocked through input %d's unlock but the input uses a non referential unlock of type %s", inputIndex, unlockedAddr.UnlockedAt, unlock.Type(), + "input %d's address is already unlocked through input %d's unlock but the input uses a non referential unlock of type %s", inputIndex, unlockedAddr.UnlockedAtInputIndex, unlock.Type(), ) } - if err := unlockedAddrs.SigUnlock(owner, essenceMsgToSign, uBlock.Signature, inputIndex, checkUnlockOnly); err != nil { + if err := unlockedAddrs.SignatureUnlock(owner, essenceMsgToSign, uBlock.Signature, inputIndex, checkUnlockOnly); err != nil { return ierrors.Join(iotago.ErrDirectUnlockableAddressUnlockInvalid, iotago.ErrUnlockSignatureInvalid, err) } @@ -505,14 +505,14 @@ func unlockAddress(ownerAddr iotago.Address, unlock iotago.Unlock, inputIndex ui ) } - if err := unlockedAddrs.RefUnlock(owner.Key(), uBlock.Ref(), inputIndex, checkUnlockOnly); err != nil { + if err := unlockedAddrs.ReferentialUnlock(owner.Key(), uBlock.ReferencedInputIndex(), inputIndex, checkUnlockOnly); err != nil { return ierrors.Errorf("%w %s (%s): %w", iotago.ErrMultiAddressUnlockInvalid, owner, owner.Type(), err) } case *iotago.MultiUnlock: // owner must not be unlocked already if unlockedAddr, wasAlreadyUnlocked := unlockedAddrs[owner.Key()]; wasAlreadyUnlocked { - return ierrors.WithMessagef(iotago.ErrMultiAddressUnlockInvalid, "input %d's address is already unlocked through input %d's unlock but the input uses a non referential unlock", inputIndex, unlockedAddr.UnlockedAt) + return ierrors.WithMessagef(iotago.ErrMultiAddressUnlockInvalid, "input %d's address is already unlocked through input %d's unlock but the input uses a non referential unlock", inputIndex, unlockedAddr.UnlockedAtInputIndex) } if err := unlockedAddrs.MultiUnlock(owner, uBlock, inputIndex, essenceMsgToSign); err != nil { @@ -624,7 +624,7 @@ func ExecFuncBalancedBaseTokens() ExecFunc { // if the return address unlocked this input, then the return amount does // not have to be fulfilled (this can happen implicit through an expiration condition) - if vmParams.WorkingSet.UnlockedAddrs.UnlockedBy(vmParams.WorkingSet.InputIDToIndex[inputID], returnAddr) { + if vmParams.WorkingSet.UnlockedAddrs.UnlockedBy(vmParams.WorkingSet.InputIDToInputIndex[inputID], returnAddr) { continue } diff --git a/workscore.go b/workscore.go index 0682e3c46..e80072810 100644 --- a/workscore.go +++ b/workscore.go @@ -119,7 +119,7 @@ func (w WorkScoreParameters) MaxBlockWork() (WorkScore, error) { // allotments factor for max number of allotments addWorkScore(w.Allotment, MaxAllotmentCount) - // signature check for max number of inputs each unlocked by a maximum sized mutli unlock + // signature check for max number of inputs each unlocked by a maximum sized multi unlock addWorkScore(w.SignatureEd25519, MaxInputsCount*10) if innerErr != nil {