Skip to content
Merged
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
3 changes: 2 additions & 1 deletion ledger/allegra/allegra.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2024 Blink Labs Software
// Copyright 2025 Blink Labs Software
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -98,6 +98,7 @@ func (b *AllegraBlock) Era() common.Era {

func (b *AllegraBlock) Transactions() []common.Transaction {
ret := make([]common.Transaction, len(b.TransactionBodies))
// #nosec G115
for idx := range b.TransactionBodies {
ret[idx] = &AllegraTransaction{
Body: b.TransactionBodies[idx],
Expand Down
3 changes: 2 additions & 1 deletion ledger/alonzo/alonzo.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2024 Blink Labs Software
// Copyright 2025 Blink Labs Software
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -106,6 +106,7 @@ func (b *AlonzoBlock) Transactions() []common.Transaction {
}

ret := make([]common.Transaction, len(b.TransactionBodies))
// #nosec G115
for idx := range b.TransactionBodies {
ret[idx] = &AlonzoTransaction{
Body: b.TransactionBodies[idx],
Expand Down
34 changes: 32 additions & 2 deletions ledger/alonzo/pparams.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2024 Blink Labs Software
// Copyright 2025 Blink Labs Software
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -15,10 +15,13 @@
package alonzo

import (
"math"

cardano "github.com/utxorpc/go-codegen/utxorpc/v1alpha/cardano"

"github.com/blinklabs-io/gouroboros/cbor"
"github.com/blinklabs-io/gouroboros/ledger/common"
"github.com/blinklabs-io/gouroboros/ledger/mary"
"github.com/utxorpc/go-codegen/utxorpc/v1alpha/cardano"
)

type AlonzoProtocolParameters struct {
Expand Down Expand Up @@ -115,6 +118,33 @@ func (u *AlonzoProtocolParameterUpdate) UnmarshalCBOR(data []byte) error {
}

func (p *AlonzoProtocolParameters) Utxorpc() *cardano.PParams {
// sanity check
if p.A0.Num().Int64() > math.MaxInt32 ||
p.A0.Denom().Int64() < 0 ||
p.A0.Denom().Int64() > math.MaxUint32 {
return nil
}
if p.Rho.Num().Int64() > math.MaxInt32 ||
p.Rho.Denom().Int64() < 0 ||
p.Rho.Denom().Int64() > math.MaxUint32 {
return nil
}
if p.Tau.Num().Int64() > math.MaxInt32 ||
p.Tau.Denom().Int64() < 0 ||
p.Tau.Denom().Int64() > math.MaxUint32 {
return nil
}
if p.ExecutionCosts.MemPrice.Num().Int64() > math.MaxInt32 ||
p.ExecutionCosts.MemPrice.Denom().Int64() < 0 ||
p.ExecutionCosts.MemPrice.Denom().Int64() > math.MaxUint32 {
return nil
}
if p.ExecutionCosts.StepPrice.Num().Int64() > math.MaxInt32 ||
p.ExecutionCosts.StepPrice.Denom().Int64() < 0 ||
p.ExecutionCosts.StepPrice.Denom().Int64() > math.MaxUint32 {
return nil
}
// #nosec G115
return &cardano.PParams{
CoinsPerUtxoByte: p.AdaPerUtxoByte,
MaxTxSize: uint64(p.MaxTxSize),
Expand Down
3 changes: 2 additions & 1 deletion ledger/babbage/babbage.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2024 Blink Labs Software
// Copyright 2025 Blink Labs Software
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -107,6 +107,7 @@ func (b *BabbageBlock) Transactions() []common.Transaction {
}

ret := make([]common.Transaction, len(b.TransactionBodies))
// #nosec G115
for idx := range b.TransactionBodies {
ret[idx] = &BabbageTransaction{
Body: b.TransactionBodies[idx],
Expand Down
34 changes: 32 additions & 2 deletions ledger/babbage/pparams.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2024 Blink Labs Software
// Copyright 2025 Blink Labs Software
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -15,10 +15,13 @@
package babbage

import (
"math"

cardano "github.com/utxorpc/go-codegen/utxorpc/v1alpha/cardano"

"github.com/blinklabs-io/gouroboros/cbor"
"github.com/blinklabs-io/gouroboros/ledger/alonzo"
"github.com/blinklabs-io/gouroboros/ledger/common"
"github.com/utxorpc/go-codegen/utxorpc/v1alpha/cardano"
)

// BabbageProtocolParameters represents the current Babbage protocol parameters as seen in local-state-query
Expand Down Expand Up @@ -154,6 +157,33 @@ func (u *BabbageProtocolParameterUpdate) UnmarshalCBOR(data []byte) error {
}

func (p *BabbageProtocolParameters) Utxorpc() *cardano.PParams {
// sanity check
if p.A0.Num().Int64() > math.MaxInt32 ||
p.A0.Denom().Int64() < 0 ||
p.A0.Denom().Int64() > math.MaxUint32 {
return nil
}
if p.Rho.Num().Int64() > math.MaxInt32 ||
p.Rho.Denom().Int64() < 0 ||
p.Rho.Denom().Int64() > math.MaxUint32 {
return nil
}
if p.Tau.Num().Int64() > math.MaxInt32 ||
p.Tau.Denom().Int64() < 0 ||
p.Tau.Denom().Int64() > math.MaxUint32 {
return nil
}
if p.ExecutionCosts.MemPrice.Num().Int64() > math.MaxInt32 ||
p.ExecutionCosts.MemPrice.Denom().Int64() < 0 ||
p.ExecutionCosts.MemPrice.Denom().Int64() > math.MaxUint32 {
return nil
}
if p.ExecutionCosts.StepPrice.Num().Int64() > math.MaxInt32 ||
p.ExecutionCosts.StepPrice.Denom().Int64() < 0 ||
p.ExecutionCosts.StepPrice.Denom().Int64() > math.MaxUint32 {
return nil
}
// #nosec G115
return &cardano.PParams{
CoinsPerUtxoByte: p.AdaPerUtxoByte,
MaxTxSize: uint64(p.MaxTxSize),
Expand Down
6 changes: 5 additions & 1 deletion ledger/byron/byron.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2024 Blink Labs Software
// Copyright 2025 Blink Labs Software
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -17,6 +17,7 @@ package byron
import (
"encoding/hex"
"fmt"
"math"

"github.com/blinklabs-io/gouroboros/cbor"
"github.com/blinklabs-io/gouroboros/ledger/common"
Expand Down Expand Up @@ -309,6 +310,9 @@ func NewByronTransactionInput(hash string, idx int) ByronTransactionInput {
if err != nil {
panic(fmt.Sprintf("failed to decode transaction hash: %s", err))
}
if idx < 0 || idx > math.MaxUint32 {
panic("index out of range")
}
return ByronTransactionInput{
TxId: common.Blake2b256(tmpHash),
OutputIndex: uint32(idx),
Expand Down
10 changes: 8 additions & 2 deletions ledger/common/certs.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ func (c *CertificateWrapper) UnmarshalCBOR(data []byte) error {
if _, err := cbor.Decode(data, tmpCert); err != nil {
return err
}
c.Type = uint(certType)
// certType is known within uint range
c.Type = uint(certType) // #nosec G115
c.Certificate = tmpCert
return nil
}
Expand Down Expand Up @@ -355,6 +356,7 @@ func (c *PoolRegistrationCertificate) Utxorpc() *utxorpc.Certificate {
VrfKeyhash: c.VrfKeyHash[:],
Pledge: c.Pledge,
Cost: c.Cost,
// #nosec G115
Margin: &utxorpc.RationalNumber{
Numerator: int32(c.Margin.Num().Int64()),
Denominator: uint32(c.Margin.Denom().Uint64()),
Expand Down Expand Up @@ -484,13 +486,17 @@ func (c *MoveInstantaneousRewardsCertificate) Utxorpc() *utxorpc.Certificate {
tmpMirTargets,
&utxorpc.MirTarget{
StakeCredential: stakeCred.Utxorpc(),
DeltaCoin: int64(deltaCoin),
// potential integer overflow
// #nosec G115
DeltaCoin: int64(deltaCoin),
},
)
}
return &utxorpc.Certificate{
Certificate: &utxorpc.Certificate_MirCert{
MirCert: &utxorpc.MirCert{
// potential integer overflow
// #nosec G115
From: utxorpc.MirSource(c.Reward.Source),
To: tmpMirTargets,
OtherPot: c.Reward.OtherPot,
Expand Down
3 changes: 2 additions & 1 deletion ledger/common/gov.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ func (g *GovActionWrapper) UnmarshalCBOR(data []byte) error {
if _, err := cbor.Decode(data, tmpAction); err != nil {
return err
}
g.Type = uint(actionType)
// action type is known within uint range
g.Type = uint(actionType) // #nosec G115
g.Action = tmpAction
return nil
}
Expand Down
5 changes: 2 additions & 3 deletions ledger/common/nonce.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,8 @@ func (n *Nonce) UnmarshalCBOR(data []byte) error {
if err != nil {
return err
}

n.Type = uint(nonceType)

// nonce type is known within uint range
n.Type = uint(nonceType) // #nosec G115
switch nonceType {
case NonceTypeNeutral:
// Value uses default value
Expand Down
3 changes: 2 additions & 1 deletion ledger/conway/conway.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2024 Blink Labs Software
// Copyright 2025 Blink Labs Software
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -106,6 +106,7 @@ func (b *ConwayBlock) Transactions() []common.Transaction {
}

ret := make([]common.Transaction, len(b.TransactionBodies))
// #nosec G115
for idx := range b.TransactionBodies {
ret[idx] = &ConwayTransaction{
Body: b.TransactionBodies[idx],
Expand Down
34 changes: 32 additions & 2 deletions ledger/conway/pparams.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2024 Blink Labs Software
// Copyright 2025 Blink Labs Software
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -15,10 +15,13 @@
package conway

import (
"math"

cardano "github.com/utxorpc/go-codegen/utxorpc/v1alpha/cardano"

"github.com/blinklabs-io/gouroboros/cbor"
"github.com/blinklabs-io/gouroboros/ledger/babbage"
"github.com/blinklabs-io/gouroboros/ledger/common"
"github.com/utxorpc/go-codegen/utxorpc/v1alpha/cardano"
)

type ConwayProtocolParameters struct {
Expand Down Expand Up @@ -57,6 +60,33 @@ type ConwayProtocolParameters struct {
}

func (p *ConwayProtocolParameters) Utxorpc() *cardano.PParams {
// sanity check
if p.A0.Num().Int64() > math.MaxInt32 ||
p.A0.Denom().Int64() < 0 ||
p.A0.Denom().Int64() > math.MaxUint32 {
return nil
}
if p.Rho.Num().Int64() > math.MaxInt32 ||
p.Rho.Denom().Int64() < 0 ||
p.Rho.Denom().Int64() > math.MaxUint32 {
return nil
}
if p.Tau.Num().Int64() > math.MaxInt32 ||
p.Tau.Denom().Int64() < 0 ||
p.Tau.Denom().Int64() > math.MaxUint32 {
return nil
}
if p.ExecutionCosts.MemPrice.Num().Int64() > math.MaxInt32 ||
p.ExecutionCosts.MemPrice.Denom().Int64() < 0 ||
p.ExecutionCosts.MemPrice.Denom().Int64() > math.MaxUint32 {
return nil
}
if p.ExecutionCosts.StepPrice.Num().Int64() > math.MaxInt32 ||
p.ExecutionCosts.StepPrice.Denom().Int64() < 0 ||
p.ExecutionCosts.StepPrice.Denom().Int64() > math.MaxUint32 {
return nil
}
// #nosec G115
return &cardano.PParams{
CoinsPerUtxoByte: p.AdaPerUtxoByte,
MaxTxSize: uint64(p.MaxTxSize),
Expand Down
3 changes: 2 additions & 1 deletion ledger/mary/mary.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2024 Blink Labs Software
// Copyright 2025 Blink Labs Software
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -100,6 +100,7 @@ func (b *MaryBlock) Era() common.Era {

func (b *MaryBlock) Transactions() []common.Transaction {
ret := make([]common.Transaction, len(b.TransactionBodies))
// #nosec G115
for idx := range b.TransactionBodies {
ret[idx] = &MaryTransaction{
Body: b.TransactionBodies[idx],
Expand Down
23 changes: 21 additions & 2 deletions ledger/shelley/pparams.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2024 Blink Labs Software
// Copyright 2025 Blink Labs Software
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -15,11 +15,13 @@
package shelley

import (
"math"
"math/big"

cardano "github.com/utxorpc/go-codegen/utxorpc/v1alpha/cardano"

"github.com/blinklabs-io/gouroboros/cbor"
"github.com/blinklabs-io/gouroboros/ledger/common"
"github.com/utxorpc/go-codegen/utxorpc/v1alpha/cardano"
)

type ShelleyProtocolParameters struct {
Expand Down Expand Up @@ -158,6 +160,23 @@ func (u *ShelleyProtocolParameterUpdate) UnmarshalCBOR(data []byte) error {
}

func (p *ShelleyProtocolParameters) Utxorpc() *cardano.PParams {
// sanity check
if p.A0.Num().Int64() > math.MaxInt32 ||
p.A0.Denom().Int64() < 0 ||
p.A0.Denom().Int64() > math.MaxUint32 {
return nil
}
if p.Rho.Num().Int64() > math.MaxInt32 ||
p.Rho.Denom().Int64() < 0 ||
p.Rho.Denom().Int64() > math.MaxUint32 {
return nil
}
if p.Tau.Num().Int64() > math.MaxInt32 ||
p.Tau.Denom().Int64() < 0 ||
p.Tau.Denom().Int64() > math.MaxUint32 {
return nil
}
// #nosec G115
return &cardano.PParams{
MaxTxSize: uint64(p.MaxTxSize),
MinFeeCoefficient: uint64(p.MinFeeA),
Expand Down
7 changes: 6 additions & 1 deletion ledger/shelley/shelley.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2024 Blink Labs Software
// Copyright 2025 Blink Labs Software
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -17,6 +17,7 @@ package shelley
import (
"encoding/hex"
"fmt"
"math"

utxorpc "github.com/utxorpc/go-codegen/utxorpc/v1alpha/cardano"

Expand Down Expand Up @@ -97,6 +98,7 @@ func (b *ShelleyBlock) Era() common.Era {

func (b *ShelleyBlock) Transactions() []common.Transaction {
ret := make([]common.Transaction, len(b.TransactionBodies))
// #nosec G115
for idx := range b.TransactionBodies {
ret[idx] = &ShelleyTransaction{
Body: b.TransactionBodies[idx],
Expand Down Expand Up @@ -403,6 +405,9 @@ func NewShelleyTransactionInput(hash string, idx int) ShelleyTransactionInput {
if err != nil {
panic(fmt.Sprintf("failed to decode transaction hash: %s", err))
}
if idx < 0 || idx > math.MaxUint32 {
panic("index out of range")
}
return ShelleyTransactionInput{
TxId: common.Blake2b256(tmpHash),
OutputIndex: uint32(idx),
Expand Down
Loading
Loading