Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ linters:
- prealloc
- protogetter
- reassign
- recvcheck
- rowserrcheck
- spancheck
- sqlclosecheck
Expand All @@ -40,7 +41,6 @@ linters:
disable:
- depguard
- noctx
- recvcheck
exclusions:
generated: lax
presets:
Expand Down
2 changes: 1 addition & 1 deletion cbor/cbor.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,6 @@ func (d *DecodeStoreCbor) SetCbor(cborData []byte) {
}

// Cbor returns the original CBOR for the object
func (d DecodeStoreCbor) Cbor() []byte {
func (d *DecodeStoreCbor) Cbor() []byte {
return d.cborData
}
16 changes: 8 additions & 8 deletions cbor/value.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,15 @@ func (v *Value) UnmarshalCBOR(data []byte) error {
return nil
}

func (v Value) Cbor() []byte {
func (v *Value) Cbor() []byte {
return []byte(v.cborData)
}

func (v Value) Value() any {
func (v *Value) Value() any {
return v.value
}

func (v Value) MarshalJSON() ([]byte, error) {
func (v *Value) MarshalJSON() ([]byte, error) {
var tmpJson string
if v.value != nil {
astJson, err := generateAstJson(v.value)
Expand Down Expand Up @@ -282,15 +282,15 @@ func NewConstructor(constructor uint, value any) Constructor {
return c
}

func (v Constructor) Constructor() uint {
func (v *Constructor) Constructor() uint {
return v.constructor
}

func (v Constructor) Fields() []any {
func (v *Constructor) Fields() []any {
return v.value.Value().([]any)
}

func (c Constructor) FieldsCbor() []byte {
func (c *Constructor) FieldsCbor() []byte {
return c.value.Cbor()
}

Expand Down Expand Up @@ -330,7 +330,7 @@ func (c *Constructor) UnmarshalCBOR(data []byte) error {
return nil
}

func (c Constructor) MarshalCBOR() ([]byte, error) {
func (c *Constructor) MarshalCBOR() ([]byte, error) {
var tmpTag Tag
if c.constructor <= 6 {
// Alternatives 0-6
Expand All @@ -350,7 +350,7 @@ func (c Constructor) MarshalCBOR() ([]byte, error) {
return Encode(&tmpTag)
}

func (v Constructor) MarshalJSON() ([]byte, error) {
func (v *Constructor) MarshalJSON() ([]byte, error) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1: Constructor.MarshalJSON moved to pointer receiver but generateAstJson marshals a value, so MarshalJSON is skipped and constructors serialize as {}.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At cbor/value.go, line 353:

<comment>Constructor.MarshalJSON moved to pointer receiver but generateAstJson marshals a value, so MarshalJSON is skipped and constructors serialize as `{}`.</comment>

<file context>
@@ -350,7 +350,7 @@ func (c Constructor) MarshalCBOR() ([]byte, error) {
 }
 
-func (v Constructor) MarshalJSON() ([]byte, error) {
+func (v *Constructor) MarshalJSON() ([]byte, error) {
 	var sb strings.Builder
 	sb.WriteString(fmt.Sprintf(`{"constructor":%d,"fields":[`, v.constructor))
</file context>
Suggested change
func (v *Constructor) MarshalJSON() ([]byte, error) {
func (v Constructor) MarshalJSON() ([]byte, error) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1: Constructor MarshalJSON changed to pointer receiver but callers still marshal Constructor values, so custom JSON output is bypassed

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At cbor/value.go, line 353:

<comment>Constructor MarshalJSON changed to pointer receiver but callers still marshal Constructor values, so custom JSON output is bypassed</comment>

<file context>
@@ -350,7 +350,7 @@ func (c Constructor) MarshalCBOR() ([]byte, error) {
 }
 
-func (v Constructor) MarshalJSON() ([]byte, error) {
+func (v *Constructor) MarshalJSON() ([]byte, error) {
 	var sb strings.Builder
 	sb.WriteString(fmt.Sprintf(`{"constructor":%d,"fields":[`, v.constructor))
</file context>

var sb strings.Builder
sb.WriteString(fmt.Sprintf(`{"constructor":%d,"fields":[`, v.constructor))
tmpList := [][]byte{}
Expand Down
12 changes: 6 additions & 6 deletions internal/test/conformance/conformance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1073,7 +1073,7 @@ func (s *initialStateUtxos) UnmarshalCBOR(data []byte) error {
TxId: utxoId.Hash,
OutputIndex: uint32(utxoId.Idx),
},
Output: output,
Output: &output,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1: Taking the address of the reused range variable makes all UTxOs share the same output pointer, corrupting decoded UTxOs.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At internal/test/conformance/conformance_test.go, line 1076:

<comment>Taking the address of the reused range variable makes all UTxOs share the same output pointer, corrupting decoded UTxOs.</comment>

<file context>
@@ -1073,7 +1073,7 @@ func (s *initialStateUtxos) UnmarshalCBOR(data []byte) error {
 						OutputIndex: uint32(utxoId.Idx),
 					},
-					Output: output,
+					Output: &output,
 				})
 			}
</file context>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1: All UTxOs take the address of the reused range variable output, so every Output pointer aliases the same value (last iteration) instead of the per-UTxO output.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At internal/test/conformance/conformance_test.go, line 1076:

<comment>All UTxOs take the address of the reused range variable `output`, so every `Output` pointer aliases the same value (last iteration) instead of the per-UTxO output.</comment>

<file context>
@@ -1073,7 +1073,7 @@ func (s *initialStateUtxos) UnmarshalCBOR(data []byte) error {
 						OutputIndex: uint32(utxoId.Idx),
 					},
-					Output: output,
+					Output: &output,
 				})
 			}
</file context>

})
}
continue
Expand Down Expand Up @@ -1103,7 +1103,7 @@ func (s *initialStateUtxos) UnmarshalCBOR(data []byte) error {
TxId: utxoId.Hash,
OutputIndex: uint32(utxoId.Idx),
},
Output: output,
Output: &output,
})
}
continue
Expand All @@ -1130,7 +1130,7 @@ func (s *initialStateUtxos) UnmarshalCBOR(data []byte) error {
TxId: hash,
OutputIndex: uint32(idx),
},
Output: output,
Output: &output,
})
}
}
Expand All @@ -1150,7 +1150,7 @@ func (s *initialStateUtxos) UnmarshalCBOR(data []byte) error {
TxId: utxoId.Hash,
OutputIndex: uint32(utxoId.Idx),
},
Output: output,
Output: &output,
})
}
continue
Expand All @@ -1167,7 +1167,7 @@ func (s *initialStateUtxos) UnmarshalCBOR(data []byte) error {
TxId: utxoId.Hash,
OutputIndex: uint32(utxoId.Idx),
},
Output: output,
Output: &output,
})
}
}
Expand Down Expand Up @@ -1222,7 +1222,7 @@ func (s *initialStateUtxos) UnmarshalCBOR(data []byte) error {
TxId: hash,
OutputIndex: index,
},
Output: output,
Output: &output,
})
}
}
Expand Down
64 changes: 32 additions & 32 deletions ledger/allegra/allegra.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func (b *AllegraBlock) UnmarshalCBOR(cborData []byte) error {
return nil
}

func (AllegraBlock) Type() int {
func (*AllegraBlock) Type() int {
return BlockTypeAllegra
}

Expand Down Expand Up @@ -237,7 +237,7 @@ func (b *AllegraTransactionBody) ProtocolParameterUpdates() (uint64, map[common.
}
updateMap := make(map[common.Blake2b224]common.ProtocolParameterUpdate)
for k, v := range b.Update.ProtocolParamUpdates {
updateMap[k] = v
updateMap[k] = &v
}
return b.Update.Epoch, updateMap
}
Expand Down Expand Up @@ -326,99 +326,99 @@ func (t *AllegraTransaction) UnmarshalCBOR(cborData []byte) error {
return nil
}

func (AllegraTransaction) Type() int {
func (*AllegraTransaction) Type() int {
return TxTypeAllegra
}

func (t AllegraTransaction) Hash() common.Blake2b256 {
func (t *AllegraTransaction) Hash() common.Blake2b256 {
return t.Id()
}

func (t AllegraTransaction) Id() common.Blake2b256 {
func (t *AllegraTransaction) Id() common.Blake2b256 {
return t.Body.Id()
}

func (t AllegraTransaction) LeiosHash() common.Blake2b256 {
func (t *AllegraTransaction) LeiosHash() common.Blake2b256 {
if t.hash == nil {
tmpHash := common.Blake2b256Hash(t.Cbor())
t.hash = &tmpHash
}
return *t.hash
}

func (t AllegraTransaction) Inputs() []common.TransactionInput {
func (t *AllegraTransaction) Inputs() []common.TransactionInput {
return t.Body.Inputs()
}

func (t AllegraTransaction) Outputs() []common.TransactionOutput {
func (t *AllegraTransaction) Outputs() []common.TransactionOutput {
return t.Body.Outputs()
}

func (t AllegraTransaction) Fee() *big.Int {
func (t *AllegraTransaction) Fee() *big.Int {
return t.Body.Fee()
}

func (t AllegraTransaction) TTL() uint64 {
func (t *AllegraTransaction) TTL() uint64 {
return t.Body.TTL()
}

func (t AllegraTransaction) ValidityIntervalStart() uint64 {
func (t *AllegraTransaction) ValidityIntervalStart() uint64 {
return t.Body.ValidityIntervalStart()
}

func (t AllegraTransaction) ReferenceInputs() []common.TransactionInput {
func (t *AllegraTransaction) ReferenceInputs() []common.TransactionInput {
return t.Body.ReferenceInputs()
}

func (t AllegraTransaction) Collateral() []common.TransactionInput {
func (t *AllegraTransaction) Collateral() []common.TransactionInput {
return t.Body.Collateral()
}

func (t AllegraTransaction) CollateralReturn() common.TransactionOutput {
func (t *AllegraTransaction) CollateralReturn() common.TransactionOutput {
return t.Body.CollateralReturn()
}

func (t AllegraTransaction) TotalCollateral() *big.Int {
func (t *AllegraTransaction) TotalCollateral() *big.Int {
return t.Body.TotalCollateral()
}

func (t AllegraTransaction) Certificates() []common.Certificate {
func (t *AllegraTransaction) Certificates() []common.Certificate {
return t.Body.Certificates()
}

func (t AllegraTransaction) Withdrawals() map[*common.Address]*big.Int {
func (t *AllegraTransaction) Withdrawals() map[*common.Address]*big.Int {
return t.Body.Withdrawals()
}

func (t AllegraTransaction) AuxDataHash() *common.Blake2b256 {
func (t *AllegraTransaction) AuxDataHash() *common.Blake2b256 {
return t.Body.AuxDataHash()
}

func (t AllegraTransaction) RequiredSigners() []common.Blake2b224 {
func (t *AllegraTransaction) RequiredSigners() []common.Blake2b224 {
return t.Body.RequiredSigners()
}

func (t AllegraTransaction) AssetMint() *common.MultiAsset[common.MultiAssetTypeMint] {
func (t *AllegraTransaction) AssetMint() *common.MultiAsset[common.MultiAssetTypeMint] {
return t.Body.AssetMint()
}

func (t AllegraTransaction) ScriptDataHash() *common.Blake2b256 {
func (t *AllegraTransaction) ScriptDataHash() *common.Blake2b256 {
return t.Body.ScriptDataHash()
}

func (t AllegraTransaction) VotingProcedures() common.VotingProcedures {
func (t *AllegraTransaction) VotingProcedures() common.VotingProcedures {
return t.Body.VotingProcedures()
}

func (t AllegraTransaction) ProposalProcedures() []common.ProposalProcedure {
func (t *AllegraTransaction) ProposalProcedures() []common.ProposalProcedure {
return t.Body.ProposalProcedures()
}

func (t AllegraTransaction) CurrentTreasuryValue() *big.Int {
func (t *AllegraTransaction) CurrentTreasuryValue() *big.Int {
return t.Body.CurrentTreasuryValue()
}

func (t AllegraTransaction) Donation() *big.Int {
func (t *AllegraTransaction) Donation() *big.Int {
return t.Body.Donation()
}

Expand All @@ -430,15 +430,15 @@ func (t *AllegraTransaction) AuxiliaryData() common.AuxiliaryData {
return t.auxData
}

func (t AllegraTransaction) IsValid() bool {
func (t *AllegraTransaction) IsValid() bool {
return true
}

func (t AllegraTransaction) Consumed() []common.TransactionInput {
func (t *AllegraTransaction) Consumed() []common.TransactionInput {
return t.Inputs()
}

func (t AllegraTransaction) Produced() []common.Utxo {
func (t *AllegraTransaction) Produced() []common.Utxo {
outputs := t.Outputs()
ret := make([]common.Utxo, 0, len(outputs))
for idx, output := range outputs {
Expand All @@ -456,15 +456,15 @@ func (t AllegraTransaction) Produced() []common.Utxo {
return ret
}

func (t AllegraTransaction) ProtocolParameterUpdates() (uint64, map[common.Blake2b224]common.ProtocolParameterUpdate) {
func (t *AllegraTransaction) ProtocolParameterUpdates() (uint64, map[common.Blake2b224]common.ProtocolParameterUpdate) {
return t.Body.ProtocolParameterUpdates()
}

func (t AllegraTransaction) Witnesses() common.TransactionWitnessSet {
return t.WitnessSet
func (t *AllegraTransaction) Witnesses() common.TransactionWitnessSet {
return &t.WitnessSet
}

func (t AllegraTransaction) Utxorpc() (*utxorpc.Tx, error) {
func (t *AllegraTransaction) Utxorpc() (*utxorpc.Tx, error) {
tx, err := t.Body.Utxorpc()
if err != nil {
return nil, fmt.Errorf("failed to convert Allegra transaction: %w", err)
Expand Down
2 changes: 1 addition & 1 deletion ledger/allegra/rules_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ func TestUtxoValidateValueNotConservedUtxo(t *testing.T) {
utxos := []common.Utxo{
{
Id: shelley.NewShelleyTransactionInput(testInputTxId, 0),
Output: shelley.ShelleyTransactionOutput{
Output: &shelley.ShelleyTransactionOutput{
OutputAmount: testInputAmount,
},
},
Expand Down
Loading