diff --git a/vm/core/sign.go b/vm/core/sign.go index 780c4283a5..917725028a 100644 --- a/vm/core/sign.go +++ b/vm/core/sign.go @@ -28,10 +28,6 @@ func SignedTx(tx *Tx, genesisID types.Hash20, pk signing.PrivateKey) ([]byte, er return nil, fmt.Errorf("encoding deploy TX: %w", err) } - sig := SignRawTx(encodedTx.Bytes(), genesisID, pk) - if _, err := scale.EncodeByteSlice(enc, sig); err != nil { - return nil, fmt.Errorf("encoding TX signature: %w", err) - } - + encodedTx.Write(SignRawTx(encodedTx.Bytes(), genesisID, pk)) return encodedTx.Bytes(), nil } diff --git a/vm/sdk/multisig/tx.go b/vm/sdk/multisig/tx.go index d3636c9e31..6e549733f8 100644 --- a/vm/sdk/multisig/tx.go +++ b/vm/sdk/multisig/tx.go @@ -45,20 +45,15 @@ func (a *SignatureAggregator) Add(ref uint8, sig core.Signature) { // Raw returns full raw transaction including payload and signatures. func (a *SignatureAggregator) Raw() []byte { - var buf bytes.Buffer - enc := scale.NewEncoder(&buf) + buf := bytes.NewBuffer(a.unsigned) + enc := scale.NewEncoder(buf) keys := slices.Sorted(maps.Keys(a.parts)) for _, ref := range keys { if err := enc.Encode(a.parts[ref]); err != nil { panic(err) } } - rawTxBuf := bytes.NewBuffer(a.unsigned) - enc = scale.NewEncoder(rawTxBuf) - if err := enc.Encode(buf.Bytes()); err != nil { - panic(err) - } - return rawTxBuf.Bytes() + return buf.Bytes() } func EncodeSpawnArgs(required uint8, pubkeys []core.PublicKey) []byte { diff --git a/vm/vm.go b/vm/vm.go index 74dc5a84b9..ca705439a5 100644 --- a/vm/vm.go +++ b/vm/vm.go @@ -5,7 +5,6 @@ import ( "context" "errors" "fmt" - "io" "time" gossamerScale "github.com/ChainSafe/gossamer/pkg/scale" @@ -537,14 +536,6 @@ func parse( if tx.Version != 1 { return nil, nil, fmt.Errorf("%w: %d", errWrongVersion, tx.Version) } - // Decode witness data - witnessData, _, err := scale.DecodeByteSlice(decoder) - switch { - case errors.Is(err, io.EOF): - logger.Debug("witness data is empty") - case err != nil: - return nil, nil, fmt.Errorf("decoding witness data: %w", err) - } ctx, err := core.New(cfg.GenesisID, lid, tx.Principal, loader, logger) if err != nil { @@ -602,7 +593,7 @@ func parse( } ctx.TxPayload = tx.Payload ctx.TxData = raw[:n] - ctx.WitnessData = witnessData + ctx.WitnessData = raw[n:] // At this point we've established that the transaction is correctly formed, but we haven't // yet attempted to validate the signature. That happens later in Verify(). @@ -616,10 +607,10 @@ func parse( logger.Debug( "calculating max gas", zap.Int("payload len", len(tx.Payload)), - zap.Int("witness data len", len(witnessData)), + zap.Int("witness data len", len(ctx.WitnessData)), ) ctx.Header.MaxGas = core.MaxGas( - estimatedStateSize + max(len(tx.Payload), 6) - 6 + len(witnessData), + estimatedStateSize + max(len(tx.Payload), 6) - 6 + len(ctx.WitnessData), ) // skip bytes for method selector ctx.Header.Principal = tx.Principal ctx.Header.GasPrice = tx.Metadata.GasPrice