Skip to content

Commit

Permalink
feat: Add support for Blake2b/2s/3 hash functions (#212)
Browse files Browse the repository at this point in the history
* 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] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Carlos Rodriguez <carlos@interchain.io>

* 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] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Carlos Rodriguez <carlos@interchain.io>

* 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] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Carlos Rodriguez <carlos@interchain.io>

* go mod tidy

* remove print statement

* review comment: rename blake2b -> blake2b_512 and blake2s -> blake2s_256

* go mod tidy

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: Carlos Rodriguez <carlos@interchain.io>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Nov 21, 2023
1 parent 9b23800 commit d583e12
Show file tree
Hide file tree
Showing 19 changed files with 348 additions and 99 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
| ------------------ | ------------------------------------------------- | ---------------------------------------------- |
| [Go](./go) | [![Go Test][go-test-badge]][go-test-link] | [![Go Cov][go-cov-badge]][go-cov-link] |
| [Rust](./rust) | [![Rust Test][rust-test-badge]][rust-test-link] | [![Rust Cov][rust-cov-badge]][rust-cov-link] |
| [TypeScript](./ts) | [![TypeScript Test][ts-test-badge]][ts-test-link] | [![TypeScript Cov][ts-cov-badge]][ts-cov-link] |
| [TypeScript](./js) | [![TypeScript Test][ts-test-badge]][ts-test-link] | [![TypeScript Cov][ts-cov-badge]][ts-cov-link] |

[cosmos-link]: https://cosmos.network
[go-test-link]: https://github.com/cosmos/ics23/actions/workflows/go.yml
Expand Down
2 changes: 1 addition & 1 deletion go/Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
test:
go test .

.PHONY: test
.PHONY: test
##### Linting #####

golangci_lint_cmd=golangci-lint
Expand Down
1 change: 1 addition & 0 deletions go/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ require (
require (
github.com/google/go-cmp v0.5.9 // indirect
golang.org/x/exp v0.0.0-20230811145659-89c5cff77bcb // indirect
golang.org/x/sys v0.14.0 // indirect
google.golang.org/protobuf v1.31.0 // indirect
)

Expand Down
2 changes: 2 additions & 0 deletions go/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ golang.org/x/crypto v0.15.0 h1:frVn1TEaCEaZcn3Tmd7Y2b5KKPaZ+I32Q2OA3kYp5TA=
golang.org/x/crypto v0.15.0/go.mod h1:4ChreQoLWfG3xLDer1WdlH5NdlQ3+mwnQq1YTKY+72g=
golang.org/x/exp v0.0.0-20230811145659-89c5cff77bcb h1:mIKbk8weKhSeLH2GmUTrvx8CjkyJmnU1wFmg59CUjFA=
golang.org/x/exp v0.0.0-20230811145659-89c5cff77bcb/go.mod h1:FXUEEKJgO7OQYeo8N01OfiKP8RXMtf6e8aTskBGqWdc=
golang.org/x/sys v0.14.0 h1:Vz7Qs629MkJkGyHxUlRHizWJRG2j8fbQKjELVSNhy7Q=
golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8=
Expand Down
38 changes: 35 additions & 3 deletions go/ops.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ import (
_ "crypto/sha256"
// adds sha512 capability to crypto.SHA512
_ "crypto/sha512"
// adds blake2b capability to crypto.BLAKE2b_512
_ "golang.org/x/crypto/blake2b"
// adds blake2s capability to crypto.BLAKE2s_256
_ "golang.org/x/crypto/blake2s"
// adds ripemd160 capability to crypto.RIPEMD160
_ "golang.org/x/crypto/ripemd160" //nolint:staticcheck
)
Expand Down Expand Up @@ -181,6 +185,22 @@ func doHash(hashOp HashOp, preimage []byte) ([]byte, error) {
return nil, err
}
return shaHash.Sum(nil), nil
case HashOp_BLAKE2B_512:
blakeHash := crypto.BLAKE2b_512.New()
_, err := blakeHash.Write(preimage)
if err != nil {
return nil, err
}
return blakeHash.Sum(nil), nil
case HashOp_BLAKE2S_256:
blakeHash := crypto.BLAKE2s_256.New()
_, err := blakeHash.Write(preimage)
if err != nil {
return nil, err
}
return blakeHash.Sum(nil), nil
// TODO: there doesn't seem to be an "official" implementation of BLAKE3 in Go,
// so we are unable to support it for now
}
return nil, fmt.Errorf("unsupported hashop: %d", hashOp)
}
Expand Down Expand Up @@ -239,16 +259,28 @@ func doLengthOp(lengthOp LengthOp, data []byte) ([]byte, error) {
return nil, fmt.Errorf("data was %d bytes, not 64", len(data))
}
return data, nil
case LengthOp_FIXED32_BIG:
res := make([]byte, 4, 4+len(data))
binary.BigEndian.PutUint32(res[:4], uint32(len(data)))
res = append(res, data...)
return res, nil
case LengthOp_FIXED32_LITTLE:
res := make([]byte, 4, 4+len(data))
binary.LittleEndian.PutUint32(res[:4], uint32(len(data)))
res = append(res, data...)
return res, nil
case LengthOp_FIXED64_BIG:
res := make([]byte, 8, 8+len(data))
binary.BigEndian.PutUint64(res[:8], uint64(len(data)))
res = append(res, data...)
return res, nil
case LengthOp_FIXED64_LITTLE:
res := make([]byte, 8, 8+len(data))
binary.LittleEndian.PutUint64(res[:8], uint64(len(data)))
res = append(res, data...)
return res, nil
// TODO
// case LengthOp_VAR_RLP:
// case LengthOp_FIXED32_BIG:
// case LengthOp_FIXED64_BIG:
// case LengthOp_FIXED64_LITTLE:
}
return nil, fmt.Errorf("unsupported lengthop: %d", lengthOp)
}
Expand Down
169 changes: 90 additions & 79 deletions go/proofs.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions js/src/generated/codecimpl.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ export namespace ics23 {
RIPEMD160 = 4,
BITCOIN = 5,
SHA512_256 = 6,
BLAKE2B_512 = 7,
BLAKE2S_256 = 8,
BLAKE3 = 9,
}

/**
Expand Down
6 changes: 6 additions & 0 deletions js/src/generated/codecimpl.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ $root.ics23 = (function() {
* @property {number} RIPEMD160=4 RIPEMD160 value
* @property {number} BITCOIN=5 BITCOIN value
* @property {number} SHA512_256=6 SHA512_256 value
* @property {number} BLAKE2B_512=7 BLAKE2B value
* @property {number} BLAKE2S_256=8 BLAKE2S value
* @property {number} BLAKE3=9 BLAKE3 value
*/
ics23.HashOp = (function() {
var valuesById = {}, values = Object.create(valuesById);
Expand All @@ -39,6 +42,9 @@ $root.ics23 = (function() {
values[valuesById[4] = "RIPEMD160"] = 4;
values[valuesById[5] = "BITCOIN"] = 5;
values[valuesById[6] = "SHA512_256"] = 6;
values[valuesById[7] = "BLAKE2B_512"] = 7;
values[valuesById[8] = "BLAKE2S_256"] = 8;
values[valuesById[9] = "BLAKE3"] = 9;
return values;
})();

Expand Down
Loading

0 comments on commit d583e12

Please sign in to comment.