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
98 changes: 84 additions & 14 deletions ledger/allegra/rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,12 @@ var UtxoValidationRules = []common.UtxoValidationRuleFunc{
}

// UtxoValidateOutsideValidityIntervalUtxo ensures that the current tip slot has reached the specified validity interval
func UtxoValidateOutsideValidityIntervalUtxo(tx common.Transaction, slot uint64, _ common.LedgerState, _ common.ProtocolParameters) error {
func UtxoValidateOutsideValidityIntervalUtxo(
tx common.Transaction,
slot uint64,
_ common.LedgerState,
_ common.ProtocolParameters,
) error {
validityIntervalStart := tx.ValidityIntervalStart()
if validityIntervalStart == 0 || slot >= validityIntervalStart {
return nil
Expand All @@ -46,54 +51,119 @@ func UtxoValidateOutsideValidityIntervalUtxo(tx common.Transaction, slot uint64,
}
}

func UtxoValidateInputSetEmptyUtxo(tx common.Transaction, slot uint64, ls common.LedgerState, pp common.ProtocolParameters) error {
func UtxoValidateInputSetEmptyUtxo(
tx common.Transaction,
slot uint64,
ls common.LedgerState,
pp common.ProtocolParameters,
) error {
return shelley.UtxoValidateInputSetEmptyUtxo(tx, slot, ls, pp)
}

func UtxoValidateFeeTooSmallUtxo(tx common.Transaction, slot uint64, ls common.LedgerState, pp common.ProtocolParameters) error {
func UtxoValidateFeeTooSmallUtxo(
tx common.Transaction,
slot uint64,
ls common.LedgerState,
pp common.ProtocolParameters,
) error {
tmpPparams, ok := pp.(*AllegraProtocolParameters)
if !ok {
return fmt.Errorf("pparams are not expected type")
}
return shelley.UtxoValidateFeeTooSmallUtxo(tx, slot, ls, &tmpPparams.ShelleyProtocolParameters)
return shelley.UtxoValidateFeeTooSmallUtxo(
tx,
slot,
ls,
&tmpPparams.ShelleyProtocolParameters,
)
}

func UtxoValidateBadInputsUtxo(tx common.Transaction, slot uint64, ls common.LedgerState, pp common.ProtocolParameters) error {
func UtxoValidateBadInputsUtxo(
tx common.Transaction,
slot uint64,
ls common.LedgerState,
pp common.ProtocolParameters,
) error {
return shelley.UtxoValidateBadInputsUtxo(tx, slot, ls, pp)
}

func UtxoValidateWrongNetwork(tx common.Transaction, slot uint64, ls common.LedgerState, pp common.ProtocolParameters) error {
func UtxoValidateWrongNetwork(
tx common.Transaction,
slot uint64,
ls common.LedgerState,
pp common.ProtocolParameters,
) error {
return shelley.UtxoValidateWrongNetwork(tx, slot, ls, pp)
}

func UtxoValidateWrongNetworkWithdrawal(tx common.Transaction, slot uint64, ls common.LedgerState, pp common.ProtocolParameters) error {
func UtxoValidateWrongNetworkWithdrawal(
tx common.Transaction,
slot uint64,
ls common.LedgerState,
pp common.ProtocolParameters,
) error {
return shelley.UtxoValidateWrongNetworkWithdrawal(tx, slot, ls, pp)
}

func UtxoValidateValueNotConservedUtxo(tx common.Transaction, slot uint64, ls common.LedgerState, pp common.ProtocolParameters) error {
func UtxoValidateValueNotConservedUtxo(
tx common.Transaction,
slot uint64,
ls common.LedgerState,
pp common.ProtocolParameters,
) error {
tmpPparams, ok := pp.(*AllegraProtocolParameters)
if !ok {
return fmt.Errorf("pparams are not expected type")
}
return shelley.UtxoValidateValueNotConservedUtxo(tx, slot, ls, &tmpPparams.ShelleyProtocolParameters)
return shelley.UtxoValidateValueNotConservedUtxo(
tx,
slot,
ls,
&tmpPparams.ShelleyProtocolParameters,
)
}

func UtxoValidateOutputTooSmallUtxo(tx common.Transaction, slot uint64, ls common.LedgerState, pp common.ProtocolParameters) error {
func UtxoValidateOutputTooSmallUtxo(
tx common.Transaction,
slot uint64,
ls common.LedgerState,
pp common.ProtocolParameters,
) error {
tmpPparams, ok := pp.(*AllegraProtocolParameters)
if !ok {
return fmt.Errorf("pparams are not expected type")
}
return shelley.UtxoValidateOutputTooSmallUtxo(tx, slot, ls, &tmpPparams.ShelleyProtocolParameters)
return shelley.UtxoValidateOutputTooSmallUtxo(
tx,
slot,
ls,
&tmpPparams.ShelleyProtocolParameters,
)
}

func UtxoValidateOutputBootAddrAttrsTooBig(tx common.Transaction, slot uint64, ls common.LedgerState, pp common.ProtocolParameters) error {
func UtxoValidateOutputBootAddrAttrsTooBig(
tx common.Transaction,
slot uint64,
ls common.LedgerState,
pp common.ProtocolParameters,
) error {
return shelley.UtxoValidateOutputBootAddrAttrsTooBig(tx, slot, ls, pp)
}

func UtxoValidateMaxTxSizeUtxo(tx common.Transaction, slot uint64, ls common.LedgerState, pp common.ProtocolParameters) error {
func UtxoValidateMaxTxSizeUtxo(
tx common.Transaction,
slot uint64,
ls common.LedgerState,
pp common.ProtocolParameters,
) error {
tmpPparams, ok := pp.(*AllegraProtocolParameters)
if !ok {
return fmt.Errorf("pparams are not expected type")
}
return shelley.UtxoValidateMaxTxSizeUtxo(tx, slot, ls, &tmpPparams.ShelleyProtocolParameters)
return shelley.UtxoValidateMaxTxSizeUtxo(
tx,
slot,
ls,
&tmpPparams.ShelleyProtocolParameters,
)
}
24 changes: 18 additions & 6 deletions ledger/allegra/rules_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ func (ls testLedgerState) NetworkId() uint {
return ls.networkId
}

func (ls testLedgerState) UtxoById(id common.TransactionInput) (common.Utxo, error) {
func (ls testLedgerState) UtxoById(
id common.TransactionInput,
) (common.Utxo, error) {
for _, tmpUtxo := range ls.utxos {
if id.Index() != tmpUtxo.Id.Index() {
continue
Expand Down Expand Up @@ -383,8 +385,12 @@ func TestUtxoValidateBadInputsUtxo(t *testing.T) {
}

func TestUtxoValidateWrongNetwork(t *testing.T) {
testCorrectNetworkAddr, _ := common.NewAddress("addr1qytna5k2fq9ler0fuk45j7zfwv7t2zwhp777nvdjqqfr5tz8ztpwnk8zq5ngetcz5k5mckgkajnygtsra9aej2h3ek5seupmvd")
testWrongNetworkAddr, _ := common.NewAddress("addr_test1qqx80sj9nwxdnglmzdl95v2k40d9422au0klwav8jz2dj985v0wma0mza32f8z6pv2jmkn7cen50f9vn9jmp7dd0njcqqpce07")
testCorrectNetworkAddr, _ := common.NewAddress(
"addr1qytna5k2fq9ler0fuk45j7zfwv7t2zwhp777nvdjqqfr5tz8ztpwnk8zq5ngetcz5k5mckgkajnygtsra9aej2h3ek5seupmvd",
)
testWrongNetworkAddr, _ := common.NewAddress(
"addr_test1qqx80sj9nwxdnglmzdl95v2k40d9422au0klwav8jz2dj985v0wma0mza32f8z6pv2jmkn7cen50f9vn9jmp7dd0njcqqpce07",
)
testTx := &allegra.AllegraTransaction{
Body: allegra.AllegraTransactionBody{
ShelleyTransactionBody: shelley.ShelleyTransactionBody{
Expand Down Expand Up @@ -451,8 +457,12 @@ func TestUtxoValidateWrongNetwork(t *testing.T) {
}

func TestUtxoValidateWrongNetworkWithdrawal(t *testing.T) {
testCorrectNetworkAddr, _ := common.NewAddress("addr1qytna5k2fq9ler0fuk45j7zfwv7t2zwhp777nvdjqqfr5tz8ztpwnk8zq5ngetcz5k5mckgkajnygtsra9aej2h3ek5seupmvd")
testWrongNetworkAddr, _ := common.NewAddress("addr_test1qqx80sj9nwxdnglmzdl95v2k40d9422au0klwav8jz2dj985v0wma0mza32f8z6pv2jmkn7cen50f9vn9jmp7dd0njcqqpce07")
testCorrectNetworkAddr, _ := common.NewAddress(
"addr1qytna5k2fq9ler0fuk45j7zfwv7t2zwhp777nvdjqqfr5tz8ztpwnk8zq5ngetcz5k5mckgkajnygtsra9aej2h3ek5seupmvd",
)
testWrongNetworkAddr, _ := common.NewAddress(
"addr_test1qqx80sj9nwxdnglmzdl95v2k40d9422au0klwav8jz2dj985v0wma0mza32f8z6pv2jmkn7cen50f9vn9jmp7dd0njcqqpce07",
)
testTx := &allegra.AllegraTransaction{
Body: allegra.AllegraTransactionBody{
ShelleyTransactionBody: shelley.ShelleyTransactionBody{
Expand Down Expand Up @@ -696,7 +706,9 @@ func TestUtxoValidateOutputTooSmallUtxo(t *testing.T) {
}

func TestUtxoValidateOutputBootAddrAttrsTooBig(t *testing.T) {
testGoodAddr, _ := common.NewAddress("addr1qytna5k2fq9ler0fuk45j7zfwv7t2zwhp777nvdjqqfr5tz8ztpwnk8zq5ngetcz5k5mckgkajnygtsra9aej2h3ek5seupmvd")
testGoodAddr, _ := common.NewAddress(
"addr1qytna5k2fq9ler0fuk45j7zfwv7t2zwhp777nvdjqqfr5tz8ztpwnk8zq5ngetcz5k5mckgkajnygtsra9aej2h3ek5seupmvd",
)
// Generate random pubkey
testBadAddrPubkey := make([]byte, 28)
if _, err := rand.Read(testBadAddrPubkey); err != nil {
Expand Down
5 changes: 4 additions & 1 deletion ledger/alonzo/alonzo.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,10 @@ func (r AlonzoRedeemers) Indexes(tag common.RedeemerTag) []uint {
return ret
}

func (r AlonzoRedeemers) Value(index uint, tag common.RedeemerTag) (cbor.LazyValue, common.RedeemerExUnits) {
func (r AlonzoRedeemers) Value(
index uint,
tag common.RedeemerTag,
) (cbor.LazyValue, common.RedeemerExUnits) {
for _, redeemer := range r {
if redeemer.Tag == tag && uint(redeemer.Index) == index {
return redeemer.Data, redeemer.ExUnits
Expand Down
10 changes: 5 additions & 5 deletions ledger/alonzo/pparams.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,27 +122,27 @@ func (p *AlonzoProtocolParameters) Utxorpc() *cardano.PParams {
if p.A0.Num().Int64() > math.MaxInt32 ||
p.A0.Denom().Int64() < 0 ||
p.A0.Denom().Int64() > math.MaxUint32 {
return nil
return nil
}
if p.Rho.Num().Int64() > math.MaxInt32 ||
p.Rho.Denom().Int64() < 0 ||
p.Rho.Denom().Int64() > math.MaxUint32 {
return nil
return nil
}
if p.Tau.Num().Int64() > math.MaxInt32 ||
p.Tau.Denom().Int64() < 0 ||
p.Tau.Denom().Int64() > math.MaxUint32 {
return nil
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
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
return nil
}
// #nosec G115
return &cardano.PParams{
Expand Down
10 changes: 5 additions & 5 deletions ledger/babbage/pparams.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,27 +161,27 @@ func (p *BabbageProtocolParameters) Utxorpc() *cardano.PParams {
if p.A0.Num().Int64() > math.MaxInt32 ||
p.A0.Denom().Int64() < 0 ||
p.A0.Denom().Int64() > math.MaxUint32 {
return nil
return nil
}
if p.Rho.Num().Int64() > math.MaxInt32 ||
p.Rho.Denom().Int64() < 0 ||
p.Rho.Denom().Int64() > math.MaxUint32 {
return nil
return nil
}
if p.Tau.Num().Int64() > math.MaxInt32 ||
p.Tau.Denom().Int64() < 0 ||
p.Tau.Denom().Int64() > math.MaxUint32 {
return nil
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
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
return nil
}
// #nosec G115
return &cardano.PParams{
Expand Down
5 changes: 4 additions & 1 deletion ledger/conway/conway.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,10 @@ func (r ConwayRedeemers) Indexes(tag common.RedeemerTag) []uint {
return ret
}

func (r ConwayRedeemers) Value(index uint, tag common.RedeemerTag) (cbor.LazyValue, common.RedeemerExUnits) {
func (r ConwayRedeemers) Value(
index uint,
tag common.RedeemerTag,
) (cbor.LazyValue, common.RedeemerExUnits) {
redeemer, ok := r.Redeemers[ConwayRedeemerKey{
Tag: tag,
Index: uint32(index), // #nosec G115
Expand Down
10 changes: 5 additions & 5 deletions ledger/conway/pparams.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,27 +64,27 @@ func (p *ConwayProtocolParameters) Utxorpc() *cardano.PParams {
if p.A0.Num().Int64() > math.MaxInt32 ||
p.A0.Denom().Int64() < 0 ||
p.A0.Denom().Int64() > math.MaxUint32 {
return nil
return nil
}
if p.Rho.Num().Int64() > math.MaxInt32 ||
p.Rho.Denom().Int64() < 0 ||
p.Rho.Denom().Int64() > math.MaxUint32 {
return nil
return nil
}
if p.Tau.Num().Int64() > math.MaxInt32 ||
p.Tau.Denom().Int64() < 0 ||
p.Tau.Denom().Int64() > math.MaxUint32 {
return nil
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
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
return nil
}
// #nosec G115
return &cardano.PParams{
Expand Down
Loading
Loading