Skip to content

Commit

Permalink
Merge pull request #1531 from dusk-network/fix-txdecode
Browse files Browse the repository at this point in the history
  • Loading branch information
herr-seppia authored Jun 7, 2023
2 parents f6e64ee + 21227dd commit 5b32220
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 19 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ 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]

### Removed
- Remove `step` from block header certificate [#1500]
Expand Down Expand Up @@ -101,6 +102,7 @@ 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
[#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
15 changes: 15 additions & 0 deletions pkg/core/data/ipc/transactions/call.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package transactions

import (
"bytes"
"io"
"io/ioutil"

"github.com/dusk-network/dusk-blockchain/pkg/p2p/wire/encoding"
Expand All @@ -17,6 +18,9 @@ import (
type Call struct {
// ContractID are 32 bytes representing the address of a contract. It is a valid BlsScalar.
ContractID []byte

// FnName is the name the name of the function to call (as bytes)
FnName []byte
// The data to call the contract with.
CallData []byte
}
Expand All @@ -25,6 +29,7 @@ type Call struct {
func NewCall() *Call {
return &Call{
ContractID: make([]byte, 32),
FnName: make([]byte, 0),
CallData: make([]byte, 0),
}
}
Expand All @@ -35,6 +40,16 @@ func UnmarshalCall(r *bytes.Buffer, c *Call) error {
return err
}

var lenFnName uint64
if err := encoding.ReadUint64LE(r, &lenFnName); err != nil {
return err
}

c.FnName = make([]byte, lenFnName)
if _, err := io.ReadFull(r, c.FnName); err != nil {
return err
}

data, err := ioutil.ReadAll(r)
if err != nil {
return err
Expand Down
3 changes: 2 additions & 1 deletion pkg/core/data/ipc/transactions/fixtures.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,12 @@ func RandContractCalls(amount, invalid int, includeCoinbase bool) []ContractCall

// RandTx mocks a transaction.
func RandTx() *Transaction {
anchor := hex.EncodeToString(Rand32Bytes())
nullifiersLength := "0100000000000000"

// Generate a random blinding factor
nullifiers := hex.EncodeToString(Rand32Bytes())
hexPayload := nullifiersLength + nullifiers + "0200000000000000010c8088b9e8c9d06915673d4d94fc76348fb7ce7503e8587f30caea67ab8379b815ce6aba274054f337bdd92d9411d8be3f282b05e3c6d42e8eea9f3215b8de33b96a3c7c1dbcb4d8cdd8ef13e50e84cf6480116311677676269d3e662cea608c5a3479e042102a78621252a37f2d99e6824e17a2b11597147d1adf4624e7d436ffffffffffffffff997ebe7877346dc48137c1d115176c60c5dbf0ea77dd8cdca0cfbc0f3d90304ecb5b2b3d60a2b9d4df4a999ef3a768f8bd75c75aac343bff35bed7cfb2e3513315e8ece73c24ca0c97bda403149dcf9fea1c8827b682c1bbe089c8d10355c45e01e549d068cb470cbefe6fddd3b2d8aacfa5a76805e725d5394e882a79d157695ec48dcb7e531ccc3b334ae122d4fd40e242e7d8a85fdb82bd4c9e9621a9a60d042dbbaec8a2acb879b48d311f1264b1aafe6bf26ccc0bb250af7a2e19e8dcdc3851f382c509fb449a701a93c9489ae97bae88feaebe38fc6c128dc4b286724c10ffffffffffffffff14b611da24f94e89dd03121410f05b53c52cfc785da3c8d59bb65d07b78ab0241c6a8f3ffadc251790b9f78a31b82246c883cbfa1330337bd094045c01dcca2a7de1eadf6f1f7116169ed9dd10541a407035bb8fe834a973d8176f51f07a8435fee6a01aa94b675366ed1b054b8091542329dd1538bcec8a7503906281f0b61200ca9a3b000000000200000000000000d85dbd596fc0476c779f3e2e7b5e58b732cb71f9ca056a8828cf845885a22f17848a28b1224942eb4222b7c43fc01e60529c7ee5fab115f3802c91179d0edfa19851d4394c5da06a86f955b2bd1305672e61a9569b5e024f03c957d4160d3d23fad4651d0897d60d89845c58baee90dbb291366e711628910673b9f3eedaaec355d87e2b2619a6809157bf01d3579145794a2b10e5e0f23d053e48a699ad318d80d2e737ca67e32f0848724907f3a847befe125d83031fc249cc24d489bee3cca6dfba0129d5578102c594b72631a13797cc0413391a5a1886c7536e6fdc0c489dfdbc00baba13e05157a7ab7273523dbb98d34c06e3a058424f361aad4a8fbda04b3327dbf973a2fc07d54445ebe6651b2e35a3f5c983dad6f05599505d20e8049ab8b6a8f099304dbc4badb806e2e8b02f90619eacef17710c48c316cddd0889badea8613806d13450208797859e6271335cda185bbfc5844358e701c0ca03ad84e86019661d4b29336d10be7f2d1510cb65478f0ea3e0baea5d49ff962bcccdcf4396a0b3cfed0f1b8c5537b148f88f31e782f30be64807cad8900706b18a31cce9a743694b0abf94d6ff32789e870b3b70970bc2a01b69faea5a6dfc3514b4d6cf831dd715429cb3c9c3c9011422260233eab35f30dec5415fe06f9a22e5e4847cde93f61e896ebeec082ced1e65b7bf5dfe6f6dd064d2649580ae5ec6b09934167cdd0efc24150dee406c18dc4d6def110c74049a3f14c7d2b019606518ab91cba648915908d032c33cd3a6c07bfb908902c5a8bd55ed5fb25582659a9f4fb82aedba03c6946823b020ff8fad039772696c1b58a3434a5c53f5b6670943e90ccf49fb24d88929f467341cd68978082969dfc75ccdf161e1340bb3d66633b52703b2efd6cf769395fa892f5738cf5dee96afe27fe085bed54dd607bc0f0b3fe5fd5e83f1a18ed9e3457ac28bc6a49224c20f17d63fbc38f2d3e49af4f108407a9523e55fc1e89a2c221b0d15a993a3856a9f9618655555f7828734da3193ad2353c81a6f0720e90dbc62a8dcdd1e117b8f6addd574a6c483a5bebb06255e9614ff22ce4ac848de8ee8df47bd133fbd5f46bf9bf9a56e80d6e411cf2803186dad1a7cd9176ba85dff17e29471fb1c6f3a9304630e190406857e511c93711eca6a472f89005ddef430f0df953dcf5a3751bddaf39da32e25a87b1f41cc23f14b25ea9e0289785520696b0a82d6a23a19eb11ca32021c414ba83f0d4012933a4a962826e7185f21f440c8b08c1adf58aec9daee1c8e15e607239e819fc5dea80c697e800a1a18acd235789fb9dfee43f3e8a51ba190656ca8ee9dc7ed1cbfce26a0deb7563f52292f3f6bef6360095b1fa416afa01640ddbabbd3b8fc15223d50c0cdc80cb846947b80408764fab356051d2783e2a9e54917cfaab223c75dd8d5187841fbe93fc79bbc1d63ffffce68ae16c3b4ef3bd92d87bec21f2f958ab4f91535f10c50ef186e3a4d2a43b8060ac15b9ef21256e52123862563540c14d9d0904c20c70d2c5915e352b582f7ee0dfe3338658c1e7245b651428799705d9b76847e9fc8a872ef3aae9c978ca64e3f5f11dd7d49decaad5c299680e7478ddc9651d8578774431b46cc701601af616f9c7323ce76fcd1c6055f7d02652c9a2354ad21ebfd1df37d5254609e3d38666940a2a6dd21c59400bf444f8b297203243de4099b1c8640fb43849f160cdab42a52e0a107df5db400819f7587957f07d72cb498ae97aa6d1e67ae2900ff56f7378f742e04fcdedd2a72ef20aea340f9f65cff2bedc1362733170906a443a1964bdc59c245808014604e2fc9c9f23ecc590da6bedcb81c69ef8f369d69a0c9c663e0faccefde8bf848224166c59b49eb9a58f8fb38bdb42f6b33b5470378bfe21a980b1d78a8da4c32b4f380127bdd6a9c0c96f1b3ee4c0bbc69fa312e7a77560ad2eafdc97017ff9e51da30ee8e2acfaef091236c4c6cf66e2f43129d70744812d2eafdc97017ff9e51da30ee8e2acfaef091236c4c6cf66e2f43129d707448126981ddc905c11356d461b7ccc828dc1ac8e3c92cc9ba3619ee76f9150095a75304d64fd0d2d436f18e6881aae6b7d99bed17078b8f508f0cf4bb2dbd3e7f7871170c739f9d9ea4404bff4066c3ed34d6a52245965b485b766344a380f65e5d2800000000000000000000000000000000"
hexPayload := anchor + nullifiersLength + nullifiers + "01000000000000000122ac26240b04b9d8697a7a6d772d41c6af4a9f2a0bc6448c7e6114e8804ac80cc48dcb7e531ccc3b334ae122d4fd40e242e7d8a85fdb82bd4c9e9621a9a60d04a7360f31dc0426451e57b526451a5c3749c131cd38c80f84b235005cef4d1b02b3badf1200e8f833c22807fb59db2aa2ec69b33477ff68a6c5efbd050da26bd0ffffffffffffffff80382f73d39cf357b17072a65d2c17be9f9880324b97101a75c2bfa8b55cb500a74664a6634a404d8fe7c237c0ac343120b7c2a08c07dcb5bfb478b81639c60c33f1f2ac9d3a88bc9502259709df1ec33841644ef18b5bc79a06c95d1d76240f00e40b540200000001000000000000008fcfc11603cb86871527b0ea685928cb15f2328de0a7f078b23ab5da376059060ed3d05d422e85952935b66044045643cc70f423a86064c58e9b6823c902364d01f0f78a0f69e99f97e76dbf3f89f46509d2d1958461585f2086d13f327603bec0a88460350fd1f8771a4d491fba5a47d44febe54727ef8474247d2dfff8c3bd2d87d999c587c5015c02a914c71256bb95bebe01f5d3281330dd1dc3e41583c8007b4c4cc3f5e948e7c18c4473f16c1bff076eb456382ccc0a62cdb76f617d6319992584556a1ae9b82f57984168deedf5479b0656c80a1c996087c82195748b491004000000000000ad59c1241ac7f7044ce29ad2ec83d6427b62cc8e89b109378adaa24ec7d0180aa7f08aceab4ce0256c152c504f9523bcb1d6281a2177f0a16ebad07e514d8307008174fa7bd588318826a4f53fabde76ff2d401cbd696a6ccbefa1d8fc913540888317cb3cf6808de698ed3e8df725357829e6396becfd1f4ca342990bb155a27cbfa65f03dea62af40d4c9935f6a4878adfe01bb5319a685a83e839c71d2b768860fee5262f6f23a358d25ee9cc4f3ab4bc86196b8e9b6451380b7187c7ff098889cf1bceb3e34816748a74e0d929f53b2744aa2aaa5b2160664024eba71335ec4fa8c070ac0eb0160b54b6a65adf05ad18f6f0dddbe0a86bb0917c6c84dee0f68e17403d52b8b8a20587af513716095d3fe3988f809d3b28bd30d14b79e70fa3b78a377ba8776ac990fabfbb04eff96005607a6c001b5babd88ce7c346e96ca8601059549548115b857a949a504e66b5a174281568812de5d979717d681b5d203517d5ddb3278880dade92e3e209b0deefc386d3926a9ffbd9887edcecd2f59513c71d5a403af10281a1f06c99cd48960532bb9c34a22feecb9ae2db84516ac688b70efd8fa0157f58e89c4d404453b834cb55c4412f5578dc361cd5e0b5b5aa26d31ead0beeb02c815691b827809f6496cdc569689da5c1134aee517d8fd8998422a2b16558781f4cec9fd396bdd42ee29d39be4b4e4056df2622d80f1b300f38b49be928a1f28a5c8a074ca73e51bcd601a4a783211eaea28691cc42192008b2926fa0c375161bb18cfa23ade1109971ef2e0ac312960773debdc5fc6b0dd786061d9e04ec63cb91d70cc0056b3cf68f442624f69b434c87a1e8acf7d885c4ab4878d7a9849b9395ed2031a6e7737026f107cdc94ba0d0defdf19a87324d68a81402411475e5d1b115687ae70772c14adf42bbd3a5c680d52896ee3faeb8ebc7218e0b9805116aa2434384ec4d4e96d216859cfb2942a31e16fd703920b1f93fbe69039f2e1bc98757b589cc634e0fc921113f4f3c9d65c126c0b3c105a7139106b9b809b75c9f68393b6a7c4721b692536d95a875c2147f4a8555535ab3dcf00247107ce4d18656c3e79aa534235ccbc969b9b61c5d217230c0c1a60f0f2d179acc9fe1a022f8c2b1858bd4370e646b6077737a0eecceeb2f550f2b6498e90d4cc3d1510f511346ef542bf7a76578fde1dadd5b9d8165faab5046c7f767ca2077dc52b569e71ebfb1ff3351ca61a59aa643e73f720664837fbac1225255b8170285d0966f7ec911d6f92f906e336ede3434575c71aeb2b21dd3224e6855c202a3ae8891b312a48451c6406681272c15bb887b6bd75509bc7098b22a8f2c81b25123ef7d9513e13e9eedf0888e39c761d08732e307f87cb709fb2e91282fe0e68c265bb8aa4d39faa1dbd354f512eb175ff4f9a5a989c1f524c52b417ec4621bf28b1513d901c412de5ec495214301020000000000000000000000000000000000000000000000000000000000000005000000000000007374616b6584c0db848cf67c6beedd8ac09146f0cc8b25b7e6419059bd09cc58917ca38589736275080dc8e52a4fc4e0df2b54f2e383e75c9004d586a64d06a23408a68c54fa47ece43fba6d45002c3b940972191d887a0c1ad8c576cb73d5f3feb0188b049626321a8779ae66bcd9d29c98f72b71c5b020b208a1df7d0575cf08dc06f5087274567a828976379b3ecfe8e32fe088b8f85afe1a3a62f64a703acb21fcd392b36099b91db25f671f20d619795b2d78727ebe0fb50ecc56e3b56bce592cb578a7169403b0ef9d595069c3e98e03b6236bad9afa4647329956590ed6abd04d0013e18f914937ffd9152dc0e300b90176a73c313af138ff6dea2c291bed4d0abefbbc2bfcb37d4ad56a4241135b318bdb3e73c7184358b4982df204be1747a56a99abbf5a021ddfab7930ef50ff728f76847111512132058ac3fa3aab997a9a18d7b52cebaa9b1dcd8bcc1dc3d9e605e9a20d758a39334fde5bb096f2d1084146bf13119a215e25e29eb786d0c711c8b22c45d4041f76fc9cca8ef6fdb1261be89639883a91c2346ab70264c2cd7330efb27efa44278afd6b7bd576f09b95807a8ee9646485f5d92d1a34c2337a290655b47027bdbfe9589b7ca5c0d27dcf70a087d7e102d345fb12211669565dd663c5900265cc1f6bce4b5deefb324f62fc008c71f5ddb59a26f611aa9bad4de1f225ccfe605c1382295af787e867988eb8b0e53d9467612d52a5e76a9c9d338f6cce995b042b4607b3364ee32922a60052912b16be823ddc769e7f14fabf1a6f72426df03725ffce3a4659a74d850bd51400f169e0a4ca4327acde8555cd571ed23ea7b94b9ab115511912185f04d18a0f3b6bc0df06fc06d7b1215d79f8bb40bf441293cd13ec5aaabb656a83de719e9f9da884c0930a3e8f6b4583a20ee196502608373ccb46f412ec71fdcfbfdec8ea6236610dadd40737c13789d083bdf48e126bfe4c109c3307a7d477262f6da0d7067b9988ec53f818e7db6c463f2c7e2b63d8a1d28f0272ffc3afc25420cb0907815b7c0c1bfa315d833a6b5b7d1b723533ecb0c2b5ef43e6e1276fb76716441be7bacca07a556113fd5fbbe7bec6e8ac34ed9a08c707a89f4740e1b0db92fa0307a799faf0dcfedb6c247cb92aaeb43f1841cef365c5f736700ef456271567cd3320c8a6c93018f8ef7f45af7e3aaeb95a61a1e6e95a2e07b04e1fe617c24a3babf9e4db6e06a3ec71335d96529af30e0103912d8d4e6bc7cc0d2e3c615d1b61e37f1b9fdb1fe70c371633a4c18f0f5a372bb0405d6ad38061b2ed2d71d276778a8f6ca370f01a6ef500353229dfc7007191dbda251253d675f312feb993dbb137f2b0637095c5fcbd6776ce2357d3461fc448926656ba3cd1ffd9ee64bca9096572feb4a1ca05ff366f65c99b4bbc7c2245ec7ac2bbe63f58174203efd2db856ffa26a3b0ae5b774b5ff34593e07be75b8cb1c21a0f45bdf5b695b05d7806878ef71fca3cf08b7b29d323aea961cec065a19cb90a33b99880e371c5a6e3f979143bb750b5de539e42e204f62f9ab4b96462c8e44ab4798b183ddd323642590895258767628619d202f89e07a05cd74216857c73031dc8e61544c74d0ce51a7f7f032ce5d85c0e0d938a569e5739724b74dda9eaa411ebec226dc2f99222d2a910567aca1fb4a2ebd7d1357605ef11b62da57f21aca20ff0c878cdb3e45177b7f2a6667bf52df9c4fb1c86bf65fb80e3040000000000000000b3134a0603dbc3be4cd8bcb4925424b88138f561d87a4acc466b93bc0f783e18d05495f0b00c77b1e477f3b625e9ef0e155f4ef89fc1007f8b106b67c6af1dcfeb9404b450aef328a775666518eac1a2156832a16d86712dd261d594270c3d1000000000000000000010a5d4e8000000b8faffff10040000"

payloadBytes, err := hex.DecodeString(hexPayload)
if err != nil {
Expand Down
35 changes: 23 additions & 12 deletions pkg/core/data/ipc/transactions/payload_decoded.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ package transactions
import (
"bytes"
"encoding/binary"
"io"

"golang.org/x/crypto/blake2b"

Expand Down Expand Up @@ -116,6 +117,10 @@ func (p *TransactionPayloadDecoded) Hash(txType TxType) ([]byte, error) {
return nil, err
}

if _, err := hash.Write(p.Call.FnName); err != nil {
return nil, err
}

if _, err := hash.Write(p.Call.CallData); err != nil {
return nil, err
}
Expand All @@ -129,6 +134,10 @@ func (p *TransactionPayloadDecoded) Hash(txType TxType) ([]byte, error) {

// UnmarshalTransactionPayloadDecoded reads a TransactionPayloadDecoded struct from a bytes.Buffer.
func UnmarshalTransactionPayloadDecoded(r *bytes.Buffer, f *TransactionPayloadDecoded, txType TxType) error {
if err := encoding.Read256(r, f.Anchor); err != nil {
return err
}

var lenInputs uint64
if err := encoding.ReadUint64LE(r, &lenInputs); err != nil {
return err
Expand All @@ -155,20 +164,12 @@ func UnmarshalTransactionPayloadDecoded(r *bytes.Buffer, f *TransactionPayloadDe
}
}

if err := encoding.Read256(r, f.Anchor); err != nil {
return err
}

if err := UnmarshalFee(r, f.Fee); err != nil {
return err
}

if _, err := r.Read(f.SpendProof); err != nil {
return err
}

var crossoverFlag uint64
if err := encoding.ReadUint64LE(r, &crossoverFlag); err != nil {
var crossoverFlag uint8
if err := encoding.ReadUint8(r, &crossoverFlag); err != nil {
return err
}

Expand All @@ -179,8 +180,18 @@ func UnmarshalTransactionPayloadDecoded(r *bytes.Buffer, f *TransactionPayloadDe
}
}

var callFlag uint64
if err := encoding.ReadUint64LE(r, &callFlag); err != nil {
var lenProof uint64
if err := encoding.ReadUint64LE(r, &lenProof); err != nil {
return err
}

f.SpendProof = make([]byte, lenProof)
if _, err := io.ReadFull(r, f.SpendProof); err != nil {
return err
}

var callFlag uint8
if err := encoding.ReadUint8(r, &callFlag); err != nil {
return err
}

Expand Down
Loading

0 comments on commit 5b32220

Please sign in to comment.