|
1 |
| -// Copyright 2024 Blink Labs Software |
| 1 | +// Copyright 2025 Blink Labs Software |
2 | 2 | //
|
3 | 3 | // Licensed under the Apache License, Version 2.0 (the "License");
|
4 | 4 | // you may not use this file except in compliance with the License.
|
|
15 | 15 | package babbage
|
16 | 16 |
|
17 | 17 | import (
|
| 18 | + "math" |
| 19 | + |
| 20 | + cardano "github.com/utxorpc/go-codegen/utxorpc/v1alpha/cardano" |
| 21 | + |
18 | 22 | "github.com/blinklabs-io/gouroboros/cbor"
|
19 | 23 | "github.com/blinklabs-io/gouroboros/ledger/alonzo"
|
20 | 24 | "github.com/blinklabs-io/gouroboros/ledger/common"
|
21 |
| - "github.com/utxorpc/go-codegen/utxorpc/v1alpha/cardano" |
22 | 25 | )
|
23 | 26 |
|
24 | 27 | // BabbageProtocolParameters represents the current Babbage protocol parameters as seen in local-state-query
|
@@ -154,6 +157,33 @@ func (u *BabbageProtocolParameterUpdate) UnmarshalCBOR(data []byte) error {
|
154 | 157 | }
|
155 | 158 |
|
156 | 159 | func (p *BabbageProtocolParameters) Utxorpc() *cardano.PParams {
|
| 160 | + // sanity check |
| 161 | + if p.A0.Num().Int64() > math.MaxInt32 || |
| 162 | + p.A0.Denom().Int64() < 0 || |
| 163 | + p.A0.Denom().Int64() > math.MaxUint32 { |
| 164 | + return nil |
| 165 | + } |
| 166 | + if p.Rho.Num().Int64() > math.MaxInt32 || |
| 167 | + p.Rho.Denom().Int64() < 0 || |
| 168 | + p.Rho.Denom().Int64() > math.MaxUint32 { |
| 169 | + return nil |
| 170 | + } |
| 171 | + if p.Tau.Num().Int64() > math.MaxInt32 || |
| 172 | + p.Tau.Denom().Int64() < 0 || |
| 173 | + p.Tau.Denom().Int64() > math.MaxUint32 { |
| 174 | + return nil |
| 175 | + } |
| 176 | + if p.ExecutionCosts.MemPrice.Num().Int64() > math.MaxInt32 || |
| 177 | + p.ExecutionCosts.MemPrice.Denom().Int64() < 0 || |
| 178 | + p.ExecutionCosts.MemPrice.Denom().Int64() > math.MaxUint32 { |
| 179 | + return nil |
| 180 | + } |
| 181 | + if p.ExecutionCosts.StepPrice.Num().Int64() > math.MaxInt32 || |
| 182 | + p.ExecutionCosts.StepPrice.Denom().Int64() < 0 || |
| 183 | + p.ExecutionCosts.StepPrice.Denom().Int64() > math.MaxUint32 { |
| 184 | + return nil |
| 185 | + } |
| 186 | + // #nosec G115 |
157 | 187 | return &cardano.PParams{
|
158 | 188 | CoinsPerUtxoByte: p.AdaPerUtxoByte,
|
159 | 189 | MaxTxSize: uint64(p.MaxTxSize),
|
|
0 commit comments