Skip to content

Commit

Permalink
Fix acceptance of txs with empty payload
Browse files Browse the repository at this point in the history
Resolves #1532
  • Loading branch information
herr-seppia authored and HDauven committed Sep 10, 2023
1 parent 483432e commit 57925b4
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 9 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -102,7 +106,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

<!-- Issues -->

[#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
Expand Down
28 changes: 20 additions & 8 deletions pkg/core/data/ipc/transactions/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package transactions

import (
"bytes"
"context"
"encoding/hex"
"errors"
Expand Down Expand Up @@ -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
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions pkg/p2p/wire/message/transactions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 57925b4

Please sign in to comment.