Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions txnprovider/shutter/internal/crypto/hash.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,16 @@ func keccak256(ds ...[]byte) []byte {
}

func hashWithPrefix(p byte, b []byte) []byte {
return keccak256(append([]byte{p}, b...))
buf := make([]byte, 1+len(b))
buf[0] = p
copy(buf[1:], b)
return keccak256(buf)
}

func Hash1(b []byte) *blst.P1Affine {
bWithPrefix := append([]byte{1}, b...)
bWithPrefix := make([]byte, 1+len(b))
bWithPrefix[0] = 1
copy(bWithPrefix[1:], b)
p := blst.HashToG1(bWithPrefix, []byte(HashToG1DST))
return p.ToAffine()
}
Expand Down
23 changes: 23 additions & 0 deletions txnprovider/shutter/internal/crypto/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,26 @@ func EnsureGobable(t *testing.T, src, dst any) {
require.NoError(t, err)
assert.Equal(t, src, dst)
}

var globalBuf []byte

func BenchmarkAppend(b *testing.B) {
data := make([]byte, 32)
p := byte(1)
b.ResetTimer()
for i := 0; i < b.N; i++ {
globalBuf = append([]byte{p}, data...)
}
}

func BenchmarkMakeCopy(b *testing.B) {
data := make([]byte, 32)
p := byte(1)
b.ResetTimer()
for i := 0; i < b.N; i++ {
buf := make([]byte, 1+len(data))
buf[0] = p
copy(buf[1:], data)
globalBuf = buf
}
}
Loading