Skip to content

Commit d583e12

Browse files
larry0xcrodriguezvegadependabot[bot]
authored
feat: Add support for Blake2b/2s/3 hash functions (#212)
* update proto files * update rust files * update go files (blake3 unimplemented) * fix a typo in readme * update js files * add tests * remove test case for keccak due to a confusion (#211) * add missing implementations for a few `LengthOp`s * implement a few missing `LengthOp`s in Go * fix Go linter warnings * fix Rust dev dependencies * add tests for new length ops implementations * chore: bump golang.org/x/crypto from 0.13.0 to 0.14.0 in /go (#206) Bumps [golang.org/x/crypto](https://github.com/golang/crypto) from 0.13.0 to 0.14.0. - [Commits](golang/crypto@v0.13.0...v0.14.0) --- updated-dependencies: - dependency-name: golang.org/x/crypto dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Carlos Rodriguez <[email protected]> * chore: bump bufbuild/buf-setup-action from 1.26.1 to 1.27.1 (#215) Bumps [bufbuild/buf-setup-action](https://github.com/bufbuild/buf-setup-action) from 1.26.1 to 1.27.1. - [Release notes](https://github.com/bufbuild/buf-setup-action/releases) - [Commits](bufbuild/buf-setup-action@v1.26.1...v1.27.1) --- updated-dependencies: - dependency-name: bufbuild/buf-setup-action dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Carlos Rodriguez <[email protected]> * chore: bump eslint from 8.50.0 to 8.52.0 in /js (#214) Bumps [eslint](https://github.com/eslint/eslint) from 8.50.0 to 8.52.0. - [Release notes](https://github.com/eslint/eslint/releases) - [Changelog](https://github.com/eslint/eslint/blob/main/CHANGELOG.md) - [Commits](eslint/eslint@v8.50.0...v8.52.0) --- updated-dependencies: - dependency-name: eslint dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Carlos Rodriguez <[email protected]> * go mod tidy * remove print statement * review comment: rename blake2b -> blake2b_512 and blake2s -> blake2s_256 * go mod tidy --------- Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: Carlos Rodriguez <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
1 parent 9b23800 commit d583e12

19 files changed

+348
-99
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
| ------------------ | ------------------------------------------------- | ---------------------------------------------- |
77
| [Go](./go) | [![Go Test][go-test-badge]][go-test-link] | [![Go Cov][go-cov-badge]][go-cov-link] |
88
| [Rust](./rust) | [![Rust Test][rust-test-badge]][rust-test-link] | [![Rust Cov][rust-cov-badge]][rust-cov-link] |
9-
| [TypeScript](./ts) | [![TypeScript Test][ts-test-badge]][ts-test-link] | [![TypeScript Cov][ts-cov-badge]][ts-cov-link] |
9+
| [TypeScript](./js) | [![TypeScript Test][ts-test-badge]][ts-test-link] | [![TypeScript Cov][ts-cov-badge]][ts-cov-link] |
1010

1111
[cosmos-link]: https://cosmos.network
1212
[go-test-link]: https://github.com/cosmos/ics23/actions/workflows/go.yml

go/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
test:
22
go test .
33

4-
.PHONY: test
4+
.PHONY: test
55
##### Linting #####
66

77
golangci_lint_cmd=golangci-lint

go/go.mod

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ require (
1010
require (
1111
github.com/google/go-cmp v0.5.9 // indirect
1212
golang.org/x/exp v0.0.0-20230811145659-89c5cff77bcb // indirect
13+
golang.org/x/sys v0.14.0 // indirect
1314
google.golang.org/protobuf v1.31.0 // indirect
1415
)
1516

go/go.sum

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ golang.org/x/crypto v0.15.0 h1:frVn1TEaCEaZcn3Tmd7Y2b5KKPaZ+I32Q2OA3kYp5TA=
88
golang.org/x/crypto v0.15.0/go.mod h1:4ChreQoLWfG3xLDer1WdlH5NdlQ3+mwnQq1YTKY+72g=
99
golang.org/x/exp v0.0.0-20230811145659-89c5cff77bcb h1:mIKbk8weKhSeLH2GmUTrvx8CjkyJmnU1wFmg59CUjFA=
1010
golang.org/x/exp v0.0.0-20230811145659-89c5cff77bcb/go.mod h1:FXUEEKJgO7OQYeo8N01OfiKP8RXMtf6e8aTskBGqWdc=
11+
golang.org/x/sys v0.14.0 h1:Vz7Qs629MkJkGyHxUlRHizWJRG2j8fbQKjELVSNhy7Q=
12+
golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
1113
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
1214
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
1315
google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8=

go/ops.go

+35-3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ import (
1212
_ "crypto/sha256"
1313
// adds sha512 capability to crypto.SHA512
1414
_ "crypto/sha512"
15+
// adds blake2b capability to crypto.BLAKE2b_512
16+
_ "golang.org/x/crypto/blake2b"
17+
// adds blake2s capability to crypto.BLAKE2s_256
18+
_ "golang.org/x/crypto/blake2s"
1519
// adds ripemd160 capability to crypto.RIPEMD160
1620
_ "golang.org/x/crypto/ripemd160" //nolint:staticcheck
1721
)
@@ -181,6 +185,22 @@ func doHash(hashOp HashOp, preimage []byte) ([]byte, error) {
181185
return nil, err
182186
}
183187
return shaHash.Sum(nil), nil
188+
case HashOp_BLAKE2B_512:
189+
blakeHash := crypto.BLAKE2b_512.New()
190+
_, err := blakeHash.Write(preimage)
191+
if err != nil {
192+
return nil, err
193+
}
194+
return blakeHash.Sum(nil), nil
195+
case HashOp_BLAKE2S_256:
196+
blakeHash := crypto.BLAKE2s_256.New()
197+
_, err := blakeHash.Write(preimage)
198+
if err != nil {
199+
return nil, err
200+
}
201+
return blakeHash.Sum(nil), nil
202+
// TODO: there doesn't seem to be an "official" implementation of BLAKE3 in Go,
203+
// so we are unable to support it for now
184204
}
185205
return nil, fmt.Errorf("unsupported hashop: %d", hashOp)
186206
}
@@ -239,16 +259,28 @@ func doLengthOp(lengthOp LengthOp, data []byte) ([]byte, error) {
239259
return nil, fmt.Errorf("data was %d bytes, not 64", len(data))
240260
}
241261
return data, nil
262+
case LengthOp_FIXED32_BIG:
263+
res := make([]byte, 4, 4+len(data))
264+
binary.BigEndian.PutUint32(res[:4], uint32(len(data)))
265+
res = append(res, data...)
266+
return res, nil
242267
case LengthOp_FIXED32_LITTLE:
243268
res := make([]byte, 4, 4+len(data))
244269
binary.LittleEndian.PutUint32(res[:4], uint32(len(data)))
245270
res = append(res, data...)
246271
return res, nil
272+
case LengthOp_FIXED64_BIG:
273+
res := make([]byte, 8, 8+len(data))
274+
binary.BigEndian.PutUint64(res[:8], uint64(len(data)))
275+
res = append(res, data...)
276+
return res, nil
277+
case LengthOp_FIXED64_LITTLE:
278+
res := make([]byte, 8, 8+len(data))
279+
binary.LittleEndian.PutUint64(res[:8], uint64(len(data)))
280+
res = append(res, data...)
281+
return res, nil
247282
// TODO
248283
// case LengthOp_VAR_RLP:
249-
// case LengthOp_FIXED32_BIG:
250-
// case LengthOp_FIXED64_BIG:
251-
// case LengthOp_FIXED64_LITTLE:
252284
}
253285
return nil, fmt.Errorf("unsupported lengthop: %d", lengthOp)
254286
}

go/proofs.pb.go

+90-79
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/src/generated/codecimpl.d.ts

+3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ export namespace ics23 {
1010
RIPEMD160 = 4,
1111
BITCOIN = 5,
1212
SHA512_256 = 6,
13+
BLAKE2B_512 = 7,
14+
BLAKE2S_256 = 8,
15+
BLAKE3 = 9,
1316
}
1417

1518
/**

js/src/generated/codecimpl.js

+6
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ $root.ics23 = (function() {
2929
* @property {number} RIPEMD160=4 RIPEMD160 value
3030
* @property {number} BITCOIN=5 BITCOIN value
3131
* @property {number} SHA512_256=6 SHA512_256 value
32+
* @property {number} BLAKE2B_512=7 BLAKE2B value
33+
* @property {number} BLAKE2S_256=8 BLAKE2S value
34+
* @property {number} BLAKE3=9 BLAKE3 value
3235
*/
3336
ics23.HashOp = (function() {
3437
var valuesById = {}, values = Object.create(valuesById);
@@ -39,6 +42,9 @@ $root.ics23 = (function() {
3942
values[valuesById[4] = "RIPEMD160"] = 4;
4043
values[valuesById[5] = "BITCOIN"] = 5;
4144
values[valuesById[6] = "SHA512_256"] = 6;
45+
values[valuesById[7] = "BLAKE2B_512"] = 7;
46+
values[valuesById[8] = "BLAKE2S_256"] = 8;
47+
values[valuesById[9] = "BLAKE3"] = 9;
4248
return values;
4349
})();
4450

0 commit comments

Comments
 (0)