Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: extend the maximum number of characters that can be decoded to 200 characters #159

Merged
merged 5 commits into from
Jan 25, 2021
Merged

Conversation

Kynea0b
Copy link
Contributor

@Kynea0b Kynea0b commented Jan 6, 2021

Closes: Finschia/finschia-sdk#47

Description


For contributor use:

  • Wrote tests

@codecov
Copy link

codecov bot commented Jan 6, 2021

Codecov Report

Merging #159 (2dcd9df) into feat/bech32plus (a01efd2) will increase coverage by 0.16%.
The diff coverage is 90.54%.

@@                 Coverage Diff                 @@
##           feat/bech32plus     #159      +/-   ##
===================================================
+ Coverage            62.52%   62.69%   +0.16%     
===================================================
  Files                  283      284       +1     
  Lines                26475    26617     +142     
===================================================
+ Hits                 16554    16688     +134     
- Misses                8576     8580       +4     
- Partials              1345     1349       +4     
Impacted Files Coverage Δ
types/protobuf.go 81.81% <ø> (ø)
crypto/composite/composite.go 96.07% <90.00%> (-3.93%) ⬇️
libs/bech32/bech32plus.go 90.08% <90.08%> (ø)
crypto/encoding/amino/amino.go 95.74% <100.00%> (ø)
libs/bech32/bech32.go 53.84% <100.00%> (ø)
lite2/trust_options.go 18.18% <0.00%> (-15.16%) ⬇️
consensus/state.go 77.93% <0.00%> (-0.10%) ⬇️
consensus/reactor.go 79.86% <0.00%> (+0.11%) ⬆️
blockchain/v0/pool.go 78.98% <0.00%> (+0.31%) ⬆️
... and 5 more

libs/bech32/bech32plus.go Show resolved Hide resolved
// Decode decodes a bech32 encoded string, returning the human-readable
// part and the data part excluding the checksum.
func Decode(bech string) (string, []byte, error) {
// The maximum allowed length for a bech32 string is 90. It must also
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a bech32 string is 90
Should update 90

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you. I will fix.

msg := bytes.NewBuffer(pk.SignKey.Bytes())
msg.Write(pk.VrfKey.Bytes())
return msg.Bytes()
bz, err := cdc.MarshalBinaryBare(pk)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we using bytes.NewBuffer?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI: https://github.com/line/tendermint/blob/develop/docs/architecture/adr-015-crypto-encoding.md

Context

We must standardize our method for encoding public keys and signatures on chain. Currently we amino encode the public keys and signatures. The reason we are using amino here is primarily due to ease of support in parsing for other languages. We don't need its upgradability properties in cryptosystems, as a change in the crypto that requires adapting the encoding, likely warrants being deemed a new cryptosystem. (I.e. using new public parameters)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you. It was used to identify it as a unique value as a [] byte array inside tendermint. However, according to the specifications of tendermint, it seems correct to use amino encoding.

@@ -67,7 +87,7 @@ func (sk PrivKeyComposite) Identity() crypto.PrivKey {
}

func (sk PrivKeyComposite) Bytes() []byte {
return sk.Identity().Bytes()
return cdc.MustMarshalBinaryBare(sk)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we using sk.Identity().Bytes()?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I answered above, the reason is the same as PubKeyComposite.

@@ -0,0 +1,255 @@
// Copyright (c) 2017 The btcsuite developers
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add our copylight?

Copy link
Contributor Author

@Kynea0b Kynea0b Jan 7, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you. No. I will delete it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, don't we need copyright? Really?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ISC license is a non-copyleft type license. In this case, the copyright is not inherited, so the copyright notice may or may not be present, but just in case, it is attached as it is.

Copy link
Contributor Author

@Kynea0b Kynea0b Jan 18, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we should. The above was a bit inaccurate. Sorry. It seems correct to describe the license for LINE. Since the license name has not been decided now, I treated it as TODO.

Copy link
Contributor

@torao torao Jan 21, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here, the non-copyleft license means that license inheritance doesn't apply. The "license inheritance" means that the source code to be copied must be under the identical license. However, license inheritance and copyright notice obligations are different concepts.

Therefore, we don't need to inherit the ISC license, but we do need to leave the copyright notice according to the ISC license.

@@ -0,0 +1,72 @@
// Copyright (c) 2017 The btcsuite developers
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add our copylight?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above.

Copy link
Contributor Author

@Kynea0b Kynea0b Jan 18, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we should. It seems correct to describe the license for LINE. Since the license name has not been decided now, I treated it as TODO.

@@ -0,0 +1,49 @@
// Copyright (c) 2017 The btcsuite developers
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add our copylight?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we should. It seems correct to describe the license for LINE. Since the license name has not been decided now, I treated it as TODO.

@Kynea0b Kynea0b changed the base branch from develop to feat/bech32plus January 7, 2021 01:52
@Kynea0b Kynea0b self-assigned this Jan 7, 2021
@Kynea0b Kynea0b requested review from torao, tnasu and egonspace and removed request for torao, tnasu and egonspace January 12, 2021 07:13
@Kynea0b Kynea0b changed the title feat: Extend the maximum number of characters that can be decoded to 200 characters feat: extend the maximum number of characters that can be decoded to 200 characters Jan 18, 2021
@@ -155,6 +168,7 @@ func TestPubkeyAminoName(t *testing.T) {
{ed25519.PubKeyEd25519{}, ed25519.PubKeyAminoName, true},
{sr25519.PubKeySr25519{}, sr25519.PubKeyAminoName, true},
{secp256k1.PubKeySecp256k1{}, secp256k1.PubKeyAminoName, true},
{composite.PubKeyComposite{}, composite.PubKeyAminoName, true},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to add bls?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you. I will add bls.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fixed. PTAL.

assert.NotNil(t, genDoc.ConsensusParams, "expected consensus params to be filled in")

// check validator's address is filled
assert.NotNil(t, genDoc.Validators[0].Address, "expected validator's address to be filled in")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't you check the composite fields? Is it enough to check Address since you add this test case?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it is. The address is generated from the pubkey. Therefore, the address check includes the pubkey check.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean that we should check the type whether composite or not.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you. I added the test case whether composite or not.

@@ -253,7 +254,7 @@ func TestEnvironmentalCompatibility(t *testing.T) {
// compare addresses to assumed value
compositePrivKey := composite.NewPrivKeyComposite(blsPrivKey, ed25519PrivKey)
compositePubKey := compositePrivKey.PubKey()
address, err := hex.DecodeString("7A68265205CB115AE35A13515C423F1721E87BB4")
address, err := hex.DecodeString(strings.ToUpper("72dd758835404175940f698cf3ddc29dd0d04afa"))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: No need to do ToUpper?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you. That's right.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fixed. PTAL.

tnasu
tnasu previously approved these changes Jan 20, 2021
Copy link
Contributor

@torao torao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@@ -0,0 +1,255 @@
// Copyright (c) 2017 The btcsuite developers
Copy link
Contributor

@torao torao Jan 21, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here, the non-copyleft license means that license inheritance doesn't apply. The "license inheritance" means that the source code to be copied must be under the identical license. However, license inheritance and copyright notice obligations are different concepts.

Therefore, we don't need to inherit the ISC license, but we do need to leave the copyright notice according to the ISC license.

@Kynea0b Kynea0b merged commit bda3271 into Finschia:feat/bech32plus Jan 25, 2021
Kynea0b added a commit that referenced this pull request Feb 18, 2021
feat:  extend the maximum number of characters that can be decoded to 200 characters (#159)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants