Skip to content

adr: modular hasher #6773

Closed
JayT106 wants to merge 12 commits intotendermint:masterfrom
JayT106:adr-069
Closed

adr: modular hasher #6773
JayT106 wants to merge 12 commits intotendermint:masterfrom
JayT106:adr-069

Conversation

@JayT106
Copy link
Contributor

@JayT106 JayT106 commented Jul 28, 2021

ref: #6539

Copy link
Contributor

@tac0turtle tac0turtle left a comment

Choose a reason for hiding this comment

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

would love to get a review from @ValarDragon and possibly @robert-zaremba if they would look at using something similar in the sdk.

@JayT106
Copy link
Contributor Author

JayT106 commented Jul 28, 2021

would love to get a review from @ValarDragon and possibly @robert-zaremba if they would look at using something similar in the sdk.

Thanks for the comments @marbar3778, definitely it needs more reviews and discussion, like which hash algorithm should be included and implemented in the ADR, the setup for the SDK and other projects.

@fedekunze, is there anything you think we should draft more in the ADR?

@JayT106 JayT106 changed the title doc: ADR-069 hasher (draft) adr: ADR-070 hasher (draft) Jul 28, 2021
@JayT106 JayT106 changed the title adr: ADR-070 hasher (draft) adr: hasher (draft) Jul 28, 2021
@github-actions
Copy link

github-actions bot commented Aug 8, 2021

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@github-actions github-actions bot added the stale for use by stalebot label Aug 8, 2021
@cmwaters cmwaters removed the stale for use by stalebot label Aug 9, 2021
@tessr
Copy link
Contributor

tessr commented Aug 9, 2021

Echoing @marbar3778's comments above - would love reviews from @ValarDragon, @robert-zaremba, and @fedekunze on this one!

@tac0turtle tac0turtle mentioned this pull request Aug 11, 2021
4 tasks
@robert-zaremba
Copy link
Contributor

In SDK: we were discussing alternative (to sha256) hashing algorithms in SDK in various contexts: fast state sync (snapshot), ADR-40 (SMT), ADR-28...
The consensus was;

  • we don't want to have different hardcoded hashing algorithms
  • we want to have configurable hasher - but implementing it was a low priority.

So the idea would be to have an app config option for providing a hasher. That hasher can be provided as a dependency to modules / keepers etc... I would rather avoid things like a global config (see GetConfig). Implementing it should be much easier once Dependency Injection is implemented (implementation is lead by Aaron with the app wiring working group).

Copy link
Contributor

@robert-zaremba robert-zaremba left a comment

Choose a reason for hiding this comment

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

Cusomizing hasher is an interesting feature. Few things to clarify:

  • probably we will need to have both SDK and tendermint to use the same hasher
  • I don't think we need to create a new interface - the standard hash.Hash interface should be good enough.
  • Need to specify where the container is stored

2. Initialize the `HasherContainer` in the node constructor. Might require passing the hasher to the reactors.
3. Replace the hard-coded tmhash function call using `HasherContainer.GetHasher(SHA256)`.
4. Mock custom hasher and test it.
5. Add new objects into the genesis file, register `Hasher` base on settings, and implement the custom transaction hash.
Copy link
Contributor

Choose a reason for hiding this comment

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

So, you are proposing to have a global instance of HashContainer? In SDK we can use the Dependency Injection framework we are working on.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the suggestion. Let me go check again.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Rewrote the proposal after checking the other projects and SDK, I think to put the Container into tmhash as a global instance, do init() in the package, and then provide the Set functions to allow SDK user to inject their hasher.

"hash": {
"types": "sha256",
"custom_tx_hash_enable": "true"
}
Copy link
Contributor

Choose a reason for hiding this comment

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

does it have to be a genesis param? It should be enough if it's an app param - the node will not sync if it's using different setting than the rest of the network.

Copy link
Contributor

Choose a reason for hiding this comment

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

however, external tools will need to know the hashing algorithm as well (eg to monitor TX confirmation), so having it in the genesis makes it more accessible. WDYT?

Copy link
Contributor Author

@JayT106 JayT106 Aug 17, 2021

Choose a reason for hiding this comment

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

does it have to be a genesis param? It should be enough if it's an app param - the node will not sync if it's using different setting than the rest of the network.

Is it okay to put it into the app param? In my mind, it's a genesis-bound param.

however, external tools will need to know the hashing algorithm as well (eg to monitor TX confirmation), so having it in the genesis makes it more accessible. WDYT?

Didn't think about the tooling level. But I agree, if the monitor/explorers are able to utilize it, it might make the tooling easier to integrate with the TM projects?

Copy link
Contributor

Choose a reason for hiding this comment

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

yes

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this should be a consensus parameter. This would imply that it could change on-chain which would imply we need to build logic to handle the case of the hasher changing. We can add it to the genesis file though and expose what hasher is used via the RPC and app's gRPC.

Copy link
Contributor

Choose a reason for hiding this comment

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

would be good to introduce genesis params #6814

Copy link
Contributor

Choose a reason for hiding this comment

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

BTW: by app param I meant an app option - not a x/param thing.

Copy link
Contributor Author

@JayT106 JayT106 Aug 25, 2021

Choose a reason for hiding this comment

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

@alexanderbez @marbar3778 I moved the hasher out of the consensus parameter, but still in the genesis.json. Any better place we can add the setting before the genesis params got implemented.

@Wondertan
Copy link

A small note from a stranger passing by. It might be worth considering using Multihashes for this case, as they are:

  • Self-described - actual hash gets prepended with information describing the hash itself. Hence, it is possible to have multiple hashes types in runtime. Hence, if sha2(or other) get compromised, the running chain can just move to a new hashing function, while keeping support for the existing history.
  • Standardised and implemented for various, most common languages
  • Have the ref implementation in Go and follows all the best practices.

@JayT106
Copy link
Contributor Author

JayT106 commented Aug 18, 2021

Multihashes

@Wondertan
Thanks for the suggestion, I've used this for a small Ipfs project a while ago. What about the benchmark compare with just using the hash algorithm itself?

Will it be too corpulent to include it into Tendermint? @alexanderbez @marbar3778

@JayT106 JayT106 requested a review from creachadair as a code owner August 25, 2021 19:45
@Wondertan
Copy link

What about the benchmark compare with just using the hash algorithm itself?

There shouldn't be any difference in performance for any hash algorithm in use. For sha256 multihashes they use sha-simd and similar for other algos they aim to use the most performant implementation. The only overhead is prepended bytes to self-describe the hash type in use.

@tac0turtle tac0turtle changed the title adr: hasher (draft) adr: hasher Aug 30, 2021
@tac0turtle tac0turtle changed the title adr: hasher adr: modular hasher Aug 30, 2021
Copy link
Contributor

@cmwaters cmwaters left a comment

Choose a reason for hiding this comment

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

So the way I see it, the chief aspect to be decided is where on the scale of hashing customization Tendermint wants to position itself. There are a few dimensions to this.

The first of which is does Tendermint offer a set of possible options for developers to choose from or allow any hasher algorithm. For me this depends on how widespread these hashing algorithms are. If 95% of projects use 3 types of hashers then I'd tend towards supporting those three only. If there's hundreds of different hashes and they all offer unique benefits then it's probably okay to allow injection of custom algorithms.

The second dimension looks at how many different components within Tendermint shall we allow for configurable hashes. Here it looks like a developer could have a different tx.Hash() to how evidence or the commit get's hashed. For me personally (at least in the short term), I think a single hasher should be used across all types that are public i.e. when a developer sets a hash it's the only one used for that network. If more demand for increasing hashing customisation comes in the future we can review it then.

@github-actions
Copy link

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@github-actions github-actions bot added the stale for use by stalebot label Sep 13, 2021
@cmwaters cmwaters removed the stale for use by stalebot label Sep 13, 2021
@github-actions
Copy link

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@github-actions
Copy link

github-actions bot commented Oct 5, 2021

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@github-actions github-actions bot added the stale for use by stalebot label Oct 5, 2021
@cmwaters cmwaters removed the stale for use by stalebot label Oct 6, 2021
```

### Chain parameter settings
For the project built on top of Tendermint can use `Hashers.RegisterHasher` to change the main hasher it would like to use. For Tendermint itself, it requires a chain parameter to indicate which hasher should be used in the service when the beginning. Therefore, we need to add a `hasher` param into the `genesis.json`.
Copy link
Contributor

Choose a reason for hiding this comment

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

wdym chain parameter here. It is not, and should not become an "on-chain parameter", changeable on the fly like consensus params.

Copy link
Contributor

Choose a reason for hiding this comment

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

i believe this was inline with #6814. As you said its meant to avoid on the fly changing stuff that shouldnt be

Copy link
Contributor Author

@JayT106 JayT106 Oct 20, 2021

Choose a reason for hiding this comment

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

I will rephrase it to genesis parameter. Sorry for the ambiguity.

@github-actions
Copy link

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@github-actions github-actions bot added the stale for use by stalebot label Oct 31, 2021
@creachadair creachadair removed the stale for use by stalebot label Oct 31, 2021
@github-actions
Copy link

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@github-actions github-actions bot added the stale for use by stalebot label Nov 11, 2021
@fedekunze
Copy link
Contributor

what's the status of this ADR @marbar3778 @cmwaters?

@fedekunze fedekunze removed the stale for use by stalebot label Nov 14, 2021
@cmwaters
Copy link
Contributor

what's the status of this ADR @marbar3778 @cmwaters?

This was ice boxed as we felt it wasn't really a priority. Personally, I think that custom hashing should only be used for transactions which is the only place where I can see it being a concern for applications. We can bring up this topic at the next dev call.

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.