From 60ad227aff11c66118b4ae6abcefeda8c3934b12 Mon Sep 17 00:00:00 2001 From: Jordan Ribbink Date: Fri, 20 Feb 2026 12:19:44 -0800 Subject: [PATCH] Fix transaction ID encoding for system transactions --- transaction.go | 9 ++++++--- transaction_test.go | 24 ++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/transaction.go b/transaction.go index 954cb5450..9fe1ef058 100644 --- a/transaction.go +++ b/transaction.go @@ -416,9 +416,12 @@ func (t *Transaction) payloadCanonicalForm() payloadCanonicalForm { } // note(sideninja): This is a temporary workaround until cadence defines canonical format addressing the issue https://github.com/onflow/flow-go-sdk/issues/286 - for i, arg := range t.Arguments { - if len(arg) > 0 && arg[len(arg)-1] == byte(10) { // extra new line character - t.Arguments[i] = arg[:len(arg)-1] + // system transactions (Payer == EmptyAddress) preserve trailing newlines in arguments + if t.Payer != EmptyAddress { + for i, arg := range t.Arguments { + if len(arg) > 0 && arg[len(arg)-1] == byte(10) { // extra new line character + t.Arguments[i] = arg[:len(arg)-1] + } } } diff --git a/transaction_test.go b/transaction_test.go index 3c4fe8e34..f125bbe04 100644 --- a/transaction_test.go +++ b/transaction_test.go @@ -745,6 +745,15 @@ func baseTx() *flow.Transaction { AddPayloadSignature(flow.HexToAddress("01"), 4, sig) } +func baseSystemTx() *flow.Transaction { + return flow.NewTransaction(). + SetScript([]byte(`transaction { execute { log("Hello, World!") } }`)). + SetReferenceBlockID(flow.HexToID("f0e4c2f76c58916ec258f246851bea091d14d4247a2fc3e18694461b1816e13b")). + SetComputeLimit(42). + SetProposalKey(flow.HexToAddress("01"), 4, 10). + AddAuthorizer(flow.HexToAddress("02")) +} + func copyTxPayload(tx *flow.Transaction) *flow.Transaction { return &flow.Transaction{ Script: tx.Script, @@ -835,6 +844,21 @@ func TestTransaction_RLPMessages(t *testing.T) { payload: "f8afb07472616e73616374696f6e207b2065786563757465207b206c6f67282248656c6c6f2c20576f726c64212229207d207df83c9f7b2276616c7565223a22666f6f222c2274797065223a22537472696e67227d9b7b2276616c7565223a223432222c2274797065223a22496e74227da0f0e4c2f76c58916ec258f246851bea091d14d4247a2fc3e18694461b1816e13b2a880000000000000001040a880000000000000001c9880000000000000001", envelope: "f8d6f8afb07472616e73616374696f6e207b2065786563757465207b206c6f67282248656c6c6f2c20576f726c64212229207d207df83c9f7b2276616c7565223a22666f6f222c2274797065223a22537472696e67227d9b7b2276616c7565223a223432222c2274797065223a22496e74227da0f0e4c2f76c58916ec258f246851bea091d14d4247a2fc3e18694461b1816e13b2a880000000000000001040a880000000000000001c9880000000000000001e4e38004a0f7225388c1d69d57e6251c9fda50cbbf9e05131e5adb81e5aa0422402f048162", }, + { + // System transactions (Payer == EmptyAddress) preserve trailing newlines in arguments. + name: "System transaction with single argument", + tx: baseSystemTx().AddRawArgument(jsoncdc.MustEncode(cadence.String("foo"))), + payload: "f893b07472616e73616374696f6e207b2065786563757465207b206c6f67282248656c6c6f2c20576f726c64212229207d207de1a07b2276616c7565223a22666f6f222c2274797065223a22537472696e67227d0aa0f0e4c2f76c58916ec258f246851bea091d14d4247a2fc3e18694461b1816e13b2a880000000000000001040a880000000000000000c9880000000000000002", + envelope: "f896f893b07472616e73616374696f6e207b2065786563757465207b206c6f67282248656c6c6f2c20576f726c64212229207d207de1a07b2276616c7565223a22666f6f222c2274797065223a22537472696e67227d0aa0f0e4c2f76c58916ec258f246851bea091d14d4247a2fc3e18694461b1816e13b2a880000000000000001040a880000000000000000c9880000000000000002c0", + }, + { + name: "System transaction with multiple arguments", + tx: baseSystemTx(). + AddRawArgument(jsoncdc.MustEncode(cadence.String("foo"))). + AddRawArgument(jsoncdc.MustEncode(cadence.NewInt(42))), + payload: "f8b1b07472616e73616374696f6e207b2065786563757465207b206c6f67282248656c6c6f2c20576f726c64212229207d207df83ea07b2276616c7565223a22666f6f222c2274797065223a22537472696e67227d0a9c7b2276616c7565223a223432222c2274797065223a22496e74227d0aa0f0e4c2f76c58916ec258f246851bea091d14d4247a2fc3e18694461b1816e13b2a880000000000000001040a880000000000000000c9880000000000000002", + envelope: "f8b4f8b1b07472616e73616374696f6e207b2065786563757465207b206c6f67282248656c6c6f2c20576f726c64212229207d207df83ea07b2276616c7565223a22666f6f222c2274797065223a22537472696e67227d0a9c7b2276616c7565223a223432222c2274797065223a22496e74227d0aa0f0e4c2f76c58916ec258f246851bea091d14d4247a2fc3e18694461b1816e13b2a880000000000000001040a880000000000000000c9880000000000000002c0", + }, } for _, tt := range tests {