From 57925b464967cd45aedcd8876e2eba5d8ba3abbc Mon Sep 17 00:00:00 2001 From: Herr Seppia Date: Tue, 13 Jun 2023 10:29:58 +0200 Subject: [PATCH] Fix acceptance of txs with empty payload Resolves #1532 --- CHANGELOG.md | 8 ++++++- pkg/core/data/ipc/transactions/provider.go | 28 +++++++++++++++------- pkg/p2p/wire/message/transactions_test.go | 3 +++ 3 files changed, 30 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6f7dd2952..70f3fe229 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,10 +13,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - Change rusk-version compatibility to `0.6.0` [#1514] - Change TX decode to support new phoenix structure [#1529] +- Use constant Committee Size [#1520] ### Removed - Remove `step` from block header certificate [#1500] +### Fixed +- Fix acceptance of txs with empty payload [#1532] + ## [0.6.1] - 2022-12-21 ### Added @@ -102,7 +106,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 -[#1529]: https://github.com/dusk-network/dusk-blockchain/issues/1520 +[#1532]: https://github.com/dusk-network/dusk-blockchain/issues/1532 +[#1529]: https://github.com/dusk-network/dusk-blockchain/issues/1529 +[#1520]: https://github.com/dusk-network/dusk-blockchain/issues/1520 [#1514]: https://github.com/dusk-network/dusk-blockchain/issues/1514 [#1500]: https://github.com/dusk-network/dusk-blockchain/issues/1500 [#1499]: https://github.com/dusk-network/dusk-blockchain/issues/1499 diff --git a/pkg/core/data/ipc/transactions/provider.go b/pkg/core/data/ipc/transactions/provider.go index 72d078726..7cb81b363 100644 --- a/pkg/core/data/ipc/transactions/provider.go +++ b/pkg/core/data/ipc/transactions/provider.go @@ -7,6 +7,7 @@ package transactions import ( + "bytes" "context" "encoding/hex" "errors" @@ -220,25 +221,36 @@ func (e *executor) Finalize(ctx context.Context, calls []ContractCall, stateRoot return resCalls, *provisioners, res.StateRoot, nil } +// STAKE_CONTRACT_ID is the byte representation of the ModuleID of the StakeContract. +var STAKE_CONTRACT_ID = []byte{0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} + +// TX_STAKE is the byte representation of the string `stake`. +var TX_STAKE = []byte("stake") + +// TX_UNSTAKE is the byte representation of the string "unstake". +var TX_UNSTAKE = []byte("unstake") + func shouldUpdateProvisioners(blockHeight uint64, txs []ContractCall) bool { if blockHeight%config.EPOCH == 0 { return true } - const TX_STAKE = byte(0x00) - const TX_UNSTAKE = byte(0x01) - for _, tx := range txs { if tx.TxError() != nil { continue } if payload, err := tx.Decode(); err == nil && payload.Call != nil { - switch payload.Call.CallData[0] { - case TX_STAKE, TX_UNSTAKE: - { - return true - } + if !bytes.Equal(payload.Call.ContractID, STAKE_CONTRACT_ID) { + continue + } + + if !bytes.Equal(payload.Call.FnName, TX_STAKE) { + return true + } + + if !bytes.Equal(payload.Call.FnName, TX_UNSTAKE) { + return true } } } diff --git a/pkg/p2p/wire/message/transactions_test.go b/pkg/p2p/wire/message/transactions_test.go index da04c8ac1..ea8fc2c54 100644 --- a/pkg/p2p/wire/message/transactions_test.go +++ b/pkg/p2p/wire/message/transactions_test.go @@ -148,6 +148,9 @@ func TestStakeTransaction(t *testing.T) { assert.NotZero(decoded.Fee.GasPrice, "GasPrice should not be 0") assert.NotEmpty(decoded.Nullifiers, "Nullifiers should be present") + assert.EqualValues(transactions.STAKE_CONTRACT_ID, decoded.Call.ContractID, "Contract id invalid") + assert.EqualValues(transactions.TX_STAKE, decoded.Call.FnName, "FnName id invalid") + hash, err := decoded.Hash(txdummy.TxType) if err != nil { t.Fatalf("Unable to calculate hash for staking: %v", err)