From 9cf40d0d8b2e42c2555ed2c1003265e2ca6c26b0 Mon Sep 17 00:00:00 2001 From: John Jannotti Date: Wed, 18 Dec 2024 11:01:54 -0800 Subject: [PATCH] compare whole bytes without loop --- ledger/apply/challenge.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/ledger/apply/challenge.go b/ledger/apply/challenge.go index 18dadae894..8885d0e0ff 100644 --- a/ledger/apply/challenge.go +++ b/ledger/apply/challenge.go @@ -17,6 +17,7 @@ package apply import ( + "bytes" "math/bits" "github.com/algorand/go-algorand/config" @@ -97,12 +98,11 @@ func bitsMatch(a, b []byte, n int) bool { return false } - // Compare entire bytes when n is bigger than 8 - for i := 0; i < n/8; i++ { - if a[i] != b[i] { - return false - } + // Compare entire bytes when we care about enough bits + if !bytes.Equal(a[:n/8], b[:n/8]) { + return false } + remaining := n % 8 if remaining == 0 { return true