Skip to content

Commit 618bae2

Browse files
envestccCopilot
andauthored
fix: ensure deterministic probation list encoding (#4786)
Map iteration in Go is non-deterministic. ConvertProbationListFromState iterated over ProbationInfo map directly, producing non-deterministic output ordering. This fix sorts the map keys before iteration to ensure consistent, deterministic encoding. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 7812bdc commit 618bae2

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

action/protocol/poll/ethabi/probation.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package ethabi
33
import (
44
"encoding/hex"
55
"math/big"
6+
"sort"
67

78
"github.com/cockroachdb/errors"
89
"github.com/ethereum/go-ethereum/accounts/abi"
@@ -51,7 +52,14 @@ func ConvertProbationListFromState(stateProbationList *vote.ProbationList) (*Pro
5152

5253
probationInfos := make([]ProbationInfo, 0, len(stateProbationList.ProbationInfo))
5354

54-
for addrStr, count := range stateProbationList.ProbationInfo {
55+
keys := make([]string, 0, len(stateProbationList.ProbationInfo))
56+
for addrStr := range stateProbationList.ProbationInfo {
57+
keys = append(keys, addrStr)
58+
}
59+
sort.Strings(keys)
60+
61+
for _, addrStr := range keys {
62+
count := stateProbationList.ProbationInfo[addrStr]
5563
probationInfo, err := NewProbationInfoFromState(addrStr, count)
5664
if err != nil {
5765
return nil, errors.Wrapf(err, "failed to convert probation info for address %s", addrStr)

0 commit comments

Comments
 (0)