Skip to content
Merged
8 changes: 4 additions & 4 deletions ledger/allegra/allegra.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ type AllegraBlock struct {
BlockHeader *AllegraBlockHeader
TransactionBodies []AllegraTransactionBody
TransactionWitnessSets []shelley.ShelleyTransactionWitnessSet
TransactionMetadataSet map[uint]*cbor.LazyValue
TransactionMetadataSet common.TransactionMetadataSet
}

func (b *AllegraBlock) UnmarshalCBOR(cborData []byte) error {
Expand Down Expand Up @@ -239,7 +239,7 @@ type AllegraTransaction struct {
hash *common.Blake2b256
Body AllegraTransactionBody
WitnessSet shelley.ShelleyTransactionWitnessSet
TxMetadata *cbor.LazyValue
TxMetadata common.TransactionMetadatum
}

func (t *AllegraTransaction) UnmarshalCBOR(cborData []byte) error {
Expand Down Expand Up @@ -349,7 +349,7 @@ func (t AllegraTransaction) Donation() uint64 {
return t.Body.Donation()
}

func (t AllegraTransaction) Metadata() *cbor.LazyValue {
func (t AllegraTransaction) Metadata() common.TransactionMetadatum {
return t.TxMetadata
}

Expand Down Expand Up @@ -411,7 +411,7 @@ func (t *AllegraTransaction) Cbor() []byte {
cbor.RawMessage(t.WitnessSet.Cbor()),
}
if t.TxMetadata != nil {
tmpObj = append(tmpObj, cbor.RawMessage(t.TxMetadata.Cbor()))
tmpObj = append(tmpObj, t.TxMetadata)
Copy link

@cubic-dev-ai cubic-dev-ai bot Nov 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Metadata is appended as a raw struct, so the generated transaction CBOR will encode Go struct fields instead of the Cardano metadata representation.

Prompt for AI agents
Address the following comment on ledger/allegra/allegra.go at line 414:

<comment>Metadata is appended as a raw struct, so the generated transaction CBOR will encode Go struct fields instead of the Cardano metadata representation.</comment>

<file context>
@@ -411,7 +411,7 @@ func (t *AllegraTransaction) Cbor() []byte {
 	}
 	if t.TxMetadata != nil {
-		tmpObj = append(tmpObj, cbor.RawMessage(t.TxMetadata.Cbor()))
+		tmpObj = append(tmpObj, t.TxMetadata)
 	} else {
 		tmpObj = append(tmpObj, nil)
</file context>
Fix with Cubic

Copy link

@cubic-dev-ai cubic-dev-ai bot Nov 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TransactionMetadatum is appended to the CBOR array as a Go struct, so CBOR encoding no longer matches the metadata CDDL and produces invalid transactions whenever metadata is present.

Prompt for AI agents
Address the following comment on ledger/allegra/allegra.go at line 414:

<comment>`TransactionMetadatum` is appended to the CBOR array as a Go struct, so CBOR encoding no longer matches the metadata CDDL and produces invalid transactions whenever metadata is present.</comment>

<file context>
@@ -411,7 +411,7 @@ func (t *AllegraTransaction) Cbor() []byte {
 	}
 	if t.TxMetadata != nil {
-		tmpObj = append(tmpObj, cbor.RawMessage(t.TxMetadata.Cbor()))
+		tmpObj = append(tmpObj, t.TxMetadata)
 	} else {
 		tmpObj = append(tmpObj, nil)
</file context>
Fix with Cubic

} else {
tmpObj = append(tmpObj, nil)
}
Expand Down
10 changes: 5 additions & 5 deletions ledger/alonzo/alonzo.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ type AlonzoBlock struct {
BlockHeader *AlonzoBlockHeader
TransactionBodies []AlonzoTransactionBody
TransactionWitnessSets []AlonzoTransactionWitnessSet
TransactionMetadataSet map[uint]*cbor.LazyValue
TransactionMetadataSet common.TransactionMetadataSet
InvalidTransactions []uint
}

Expand Down Expand Up @@ -86,7 +86,7 @@ func (b *AlonzoBlock) MarshalCBOR() ([]byte, error) {
BlockHeader *AlonzoBlockHeader
TransactionBodies []AlonzoTransactionBody
TransactionWitnessSets []AlonzoTransactionWitnessSet
TransactionMetadataSet map[uint]*cbor.LazyValue
TransactionMetadataSet common.TransactionMetadataSet
InvalidTransactions cbor.IndefLengthList
}

Expand Down Expand Up @@ -633,7 +633,7 @@ type AlonzoTransaction struct {
Body AlonzoTransactionBody
WitnessSet AlonzoTransactionWitnessSet
TxIsValid bool
TxMetadata *cbor.LazyValue
TxMetadata common.TransactionMetadatum
}

func (t *AlonzoTransaction) UnmarshalCBOR(cborData []byte) error {
Expand Down Expand Up @@ -747,7 +747,7 @@ func (t AlonzoTransaction) Donation() uint64 {
return t.Body.Donation()
}

func (t AlonzoTransaction) Metadata() *cbor.LazyValue {
func (t AlonzoTransaction) Metadata() common.TransactionMetadatum {
return t.TxMetadata
}

Expand Down Expand Up @@ -807,7 +807,7 @@ func (t *AlonzoTransaction) Cbor() []byte {
t.TxIsValid,
}
if t.TxMetadata != nil {
tmpObj = append(tmpObj, cbor.RawMessage(t.TxMetadata.Cbor()))
tmpObj = append(tmpObj, t.TxMetadata)
Copy link

@cubic-dev-ai cubic-dev-ai bot Nov 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AlonzoTransaction.Cbor() now appends the typed metadatum struct directly, so the CBOR encoder serializes Go struct fields instead of canonical metadata. Convert the metadata to its CBOR form (as done in TransactionMetadataSet.MarshalCBOR) before appending to tmpObj or keep using the raw CBOR bytes.

Prompt for AI agents
Address the following comment on ledger/alonzo/alonzo.go at line 810:

<comment>`AlonzoTransaction.Cbor()` now appends the typed metadatum struct directly, so the CBOR encoder serializes Go struct fields instead of canonical metadata. Convert the metadata to its CBOR form (as done in TransactionMetadataSet.MarshalCBOR) before appending to tmpObj or keep using the raw CBOR bytes.</comment>

<file context>
@@ -807,7 +807,7 @@ func (t *AlonzoTransaction) Cbor() []byte {
 	}
 	if t.TxMetadata != nil {
-		tmpObj = append(tmpObj, cbor.RawMessage(t.TxMetadata.Cbor()))
+		tmpObj = append(tmpObj, t.TxMetadata)
 	} else {
 		tmpObj = append(tmpObj, nil)
</file context>
Fix with Cubic

} else {
tmpObj = append(tmpObj, nil)
}
Expand Down
8 changes: 4 additions & 4 deletions ledger/babbage/babbage.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ type BabbageBlock struct {
BlockHeader *BabbageBlockHeader
TransactionBodies []BabbageTransactionBody
TransactionWitnessSets []BabbageTransactionWitnessSet
TransactionMetadataSet map[uint]*cbor.LazyValue
TransactionMetadataSet common.TransactionMetadataSet
InvalidTransactions []uint
}

Expand Down Expand Up @@ -788,7 +788,7 @@ type BabbageTransaction struct {
Body BabbageTransactionBody
WitnessSet BabbageTransactionWitnessSet
TxIsValid bool
TxMetadata *cbor.LazyValue
TxMetadata common.TransactionMetadatum
}

func (t *BabbageTransaction) UnmarshalCBOR(cborData []byte) error {
Expand Down Expand Up @@ -902,7 +902,7 @@ func (t BabbageTransaction) Donation() uint64 {
return t.Body.Donation()
}

func (t BabbageTransaction) Metadata() *cbor.LazyValue {
func (t BabbageTransaction) Metadata() common.TransactionMetadatum {
return t.TxMetadata
}

Expand Down Expand Up @@ -969,7 +969,7 @@ func (t *BabbageTransaction) Cbor() []byte {
t.TxIsValid,
}
if t.TxMetadata != nil {
tmpObj = append(tmpObj, cbor.RawMessage(t.TxMetadata.Cbor()))
tmpObj = append(tmpObj, t.TxMetadata)
} else {
tmpObj = append(tmpObj, nil)
}
Expand Down
6 changes: 3 additions & 3 deletions ledger/byron/byron.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ type ByronTransaction struct {
hash *common.Blake2b256
TxInputs []ByronTransactionInput
TxOutputs []ByronTransactionOutput
Attributes *cbor.LazyValue
Attributes cbor.RawMessage
}

func (t *ByronTransaction) UnmarshalCBOR(cborData []byte) error {
Expand Down Expand Up @@ -275,8 +275,8 @@ func (t *ByronTransaction) Donation() uint64 {
return 0
}

func (t *ByronTransaction) Metadata() *cbor.LazyValue {
return t.Attributes
func (t *ByronTransaction) Metadata() common.TransactionMetadatum {
return nil
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is definitely not correct. This probably needs its own Byron-specific type, since it'll be different from things afterwards.

}

func (t *ByronTransaction) LeiosHash() common.Blake2b256 {
Expand Down
Loading
Loading