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

feature: Support for Hedera EVM block identifiers #118

Merged
merged 10 commits into from
May 20, 2024

Conversation

SamMayWork
Copy link
Contributor

@SamMayWork SamMayWork commented Mar 7, 2024

ref: https://discord.com/channels/905194001349627914/928377875827154984/1219628950393847860 (thread on Hyperledger discord on Hedera support with EVM Connect)

TL;DR: Hedera is a hashgraph not a blockchain (though is EVM compatible), and uses non-standard 'block' hashes which are 48 bytes rather than 32 bytes, EVM Connect cannot handle this currently. To promote integration with other ecosystems, Hedera expects that these 48 byte block headers be truncated to 32 bytes, this is a common feature in the Hedera ecosystem.

https://hips.hedera.com/hip/hip-415 - Hedera introduction of blocks (mentioning 48 bytes being referenced by the 32 byte prefix)

https://hips.hedera.com/hip/hip-482 - JSON RPC specification for Hedera

Block Hashes

Ethereum uses 32-byte hashes for blocks while Hedera uses 48-byte hashes. To compute a 32-byte Ethereum hash, take the leading 32 bytes from a 48-byte Hedera hash.

@SamMayWork SamMayWork changed the title fix: allow for bytes to be truncated down fix: Allow for non-standard block header lengths Mar 19, 2024
@SamMayWork SamMayWork marked this pull request as ready for review March 25, 2024 11:40
@SamMayWork SamMayWork requested a review from a team as a code owner March 25, 2024 11:40
go.mod Outdated
@@ -99,3 +99,5 @@ require (
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

replace github.com/hyperledger/firefly-signer => github.com/SamMayWork/firefly-signer v0.0.0-20240307121035-e654fb9ef55b
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will be removed after the pre-req changes are merged

Copy link
Contributor

Choose a reason for hiding this comment

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

Please see review comments on hyperledger/firefly-signer#61

Signed-off-by: SamMayWork <[email protected]>
Copy link
Contributor

@peterbroadhurst peterbroadhurst left a comment

Choose a reason for hiding this comment

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

Need a little more info on the solution you're proposing, and the alternatives you considered @SamMayWork if that's ok

}

if bl.nonStandardBlockHashSizeResolutionMethod == "truncate" {
h, err = h.Truncate(32)
Copy link
Contributor

@peterbroadhurst peterbroadhurst May 10, 2024

Choose a reason for hiding this comment

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

Suggested change
h, err = h.Truncate(32)
h = ethtypes.HexBytes0xPrefix(h[0:32])

... related to firefly-signer change proposal. But note the question overall around the intent of this change.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep agreed here - if we go with this approach, we'll do this and then remove the requirement on the firefly-signer PR.

ConfigTxCacheSize = ffc("config.connector.txCacheSize", "Maximum of transactions to hold in the transaction info cache", i18n.IntType)
ConfigMaxConcurrentRequests = ffc("config.connector.maxConcurrentRequests", "Maximum of concurrent requests to be submitted to the blockchain", i18n.IntType)
ConfigAllowNonStandardBlockHashSize = ffc("config.connector.allowNonStandardBlockHashSize", "Whether to permit block hases of a non-standard (i.e. not 32 bytes) length", i18n.BooleanType)
ConfigNonStandardBlockHashSizeResolutionMethod = ffc("config.connector.nonStandardBlockHashSizeResolutionMethod", "How to resolve block hashes that are non-standard (i.e. not 32 bytes) in length. Currently only 'truncate' is supported.", i18n.StringType)
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure I understand yet the intention here, and that suggests to me users of this setting might struggle to.

Is the intention here blockHashByteLength?

e.g. you are instructing the whole code stack that all block hashes should be X bytes, where the default is 32?

If so, what code is affected that needs this? And why?

Will try and answer from reading through the rest of the code

@@ -140,6 +144,28 @@ func (bl *blockListener) listenLoop() {
update := &ffcapi.BlockHashEvent{GapPotential: gapPotential}
var notifyPos *list.Element
for _, h := range blockHashes {
if len(h) != 32 {
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry @SamMayWork I couldn't understand in the end the problem and the solution. Could do with some help.

32 is the length of a "standard" Ethereum block hash. So if we get a standard one, it will be 32 bytes in length.

You are working with a EVM implementation against a ledger that uses a 48 byte block hash - so in that case, the length here would be 48.

Why would we truncate that? Surely we just need to acommodate that it's 48 bytes, and there will be some number of places in the code that need to be relaxed to avoid the assumption of 32 bytes. Maybe for example there are DB migration tables etc.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why would we truncate that? Surely we just need to acommodate that it's 48 bytes, and there will be some number of places in the code that need to be relaxed to avoid the assumption of 32 bytes. Maybe for example there are DB migration tables etc.

There was a brief Discord discussion on this, although in retrospect I don't think we considered what other alternative approaches we could use here.

The reason for using truncation here instead of changing the code everywhere to permit the change in header size was purely to reduce the scope of the changes required. I think the view was that Hedera is EVM compatible but also a little bit weird, and it might make more sense to truncate the hashes so there's no need to change existing code for a single use-case.

We could use this PR to permit non-standard block header sizes everywhere if that's something strategically we think EVM Connect should be able to do.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Had a conversation with @peterbroadhurst on this topic, one thing this PR doesn't call out that it absolutely should be is that it is expected in the Hedera ecosystem to refer to blocks by their truncated hash. Block headers are 48 bytes, truncation down to 32 bytes for EVM compatiblity is baked into the Hedera ecosystem, so this isn't a case of FireFly doing something strange, this is what we're expected to be doing.

Additionally on the spelling of the configuration we've agreed that in this case we're processing blocks slightly differently specifically for Hedera so in that sense we're essentially running compatibility adjustments, as such we've change the name of the configuration to be hederaCompatibilityMode.

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if len(h) != 32 {
if len(h) == 48 {

Signed-off-by: SamMayWork <[email protected]>
Signed-off-by: SamMayWork <[email protected]>
Signed-off-by: SamMayWork <[email protected]>
@peterbroadhurst
Copy link
Contributor

fix: Allow for non-standard block header lengths

Maybe worth changing to:

"feature: Support for Hedera EVM block identifiers"

continue
}

h = h[0:32]
Copy link
Contributor

Choose a reason for hiding this comment

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

Note above to make this safe we need to be confident we have at least 32b

Copy link
Contributor

@peterbroadhurst peterbroadhurst left a comment

Choose a reason for hiding this comment

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

Minor suggestion to tweak the length check before merge, and a request to change the PR title for the release when that happens.

@SamMayWork SamMayWork changed the title fix: Allow for non-standard block header lengths feature: Support for Hedera EVM block identifiers May 20, 2024
Signed-off-by: SamMayWork <[email protected]>
Copy link
Contributor

@EnriqueL8 EnriqueL8 left a comment

Choose a reason for hiding this comment

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

Approving and merging based on above approvals!

@EnriqueL8 EnriqueL8 merged commit 684d91e into hyperledger:main May 20, 2024
3 checks passed
This pull request was closed.
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