Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 5dda41e

Browse files
authoredMar 18, 2025··
Merge branch 'main' into add-simulate-anything
2 parents 6e4cd3d + 26ad7f8 commit 5dda41e

File tree

2 files changed

+12
-13
lines changed

2 files changed

+12
-13
lines changed
 

‎CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ adheres to the format set out by [Keep a Changelog](https://keepachangelog.com/e
77

88
- Add ability to simulate for any transaction including multi-agent and fee payer
99
- [`Fix`] Ensure proper cleanup of response body on read error to prevent potential memory leak.
10+
- [`Fix`] Fixes possible conflicts between signatures of multiple goroutines
1011

1112
# v1.5.0 (2/10/2024)
1213

‎rawTransaction.go

+11-13
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,24 @@ import (
55
"github.com/aptos-labs/aptos-go-sdk/bcs"
66
"github.com/aptos-labs/aptos-go-sdk/crypto"
77
"golang.org/x/crypto/sha3"
8+
"sync"
89
)
910

1011
//region RawTransaction
1112

1213
var rawTransactionPrehash []byte
14+
var rawTransactionWithPrehashOnce sync.Once
1315

1416
const rawTransactionPrehashStr = "APTOS::RawTransaction"
1517

1618
// RawTransactionPrehash Return the sha3-256 prehash for RawTransaction
1719
// Do not write to the []byte returned
1820
func RawTransactionPrehash() []byte {
1921
// Cache the prehash
20-
if rawTransactionPrehash == nil {
22+
rawTransactionWithPrehashOnce.Do(func() {
2123
b32 := sha3.Sum256([]byte(rawTransactionPrehashStr))
22-
out := make([]byte, len(b32))
23-
copy(out, b32[:])
24-
rawTransactionPrehash = out
25-
return out
26-
}
24+
rawTransactionPrehash = b32[:]
25+
})
2726
return rawTransactionPrehash
2827
}
2928

@@ -130,21 +129,20 @@ func (txn *RawTransaction) Sign(signer crypto.Signer) (authenticator *crypto.Acc
130129
//region RawTransactionWithData
131130

132131
var rawTransactionWithDataPrehash []byte
132+
var rawTransactionWithDataPrehashOnce sync.Once
133133

134134
const rawTransactionWithDataPrehashStr = "APTOS::RawTransactionWithData"
135135

136136
// RawTransactionWithDataPrehash Return the sha3-256 prehash for RawTransactionWithData
137137
// Do not write to the []byte returned
138138
func RawTransactionWithDataPrehash() []byte {
139139
// Cache the prehash
140-
if rawTransactionWithDataPrehash == nil {
140+
rawTransactionWithDataPrehashOnce.Do(func() {
141141
b32 := sha3.Sum256([]byte(rawTransactionWithDataPrehashStr))
142-
out := make([]byte, len(b32))
143-
copy(out, b32[:])
144-
rawTransactionPrehash = out
145-
return out
146-
}
147-
return rawTransactionPrehash
142+
rawTransactionWithDataPrehash = b32[:]
143+
})
144+
return rawTransactionWithDataPrehash
145+
148146
}
149147

150148
type RawTransactionWithDataVariant uint32

0 commit comments

Comments
 (0)
Please sign in to comment.