From c1cc88dba0991e8f621d5bc6e78453b490bec9ae Mon Sep 17 00:00:00 2001 From: Stephen Buttolph Date: Thu, 5 Jun 2025 13:30:54 -0400 Subject: [PATCH 1/7] Refactor AP1 ExtData checks --- plugin/evm/atomic_block_extension.go | 48 +++++++++++++--------------- 1 file changed, 22 insertions(+), 26 deletions(-) diff --git a/plugin/evm/atomic_block_extension.go b/plugin/evm/atomic_block_extension.go index 9060447f28..54b10653c7 100644 --- a/plugin/evm/atomic_block_extension.go +++ b/plugin/evm/atomic_block_extension.go @@ -90,28 +90,6 @@ func (be *blockExtension) SyntacticVerify(rules extras.Rules) error { blockHash := ethBlock.Hash() headerExtra := customtypes.GetHeaderExtra(ethHeader) - if !rules.IsApricotPhase1 { - if blockExtender.extDataHashes != nil { - extData := customtypes.BlockExtData(ethBlock) - extDataHash := customtypes.CalcExtDataHash(extData) - // If there is no extra data, check that there is no extra data in the hash map either to ensure we do not - // have a block that is unexpectedly missing extra data. - expectedExtDataHash, ok := blockExtender.extDataHashes[blockHash] - if len(extData) == 0 { - if ok { - return fmt.Errorf("found block with unexpected missing extra data (%s, %d), expected extra data hash: %s", blockHash, b.Height(), expectedExtDataHash) - } - } else { - // If there is extra data, check to make sure that the extra data hash matches the expected extra data hash for this - // block - if extDataHash != expectedExtDataHash { - return fmt.Errorf("extra data hash in block (%s, %d): %s, did not match the expected extra data hash: %s", blockHash, b.Height(), extDataHash, expectedExtDataHash) - } - } - } - } - - // Verify the ExtDataHash field if rules.IsApricotPhase1 { extraData := customtypes.BlockExtData(ethBlock) hash := customtypes.CalcExtDataHash(extraData) @@ -119,11 +97,29 @@ func (be *blockExtension) SyntacticVerify(rules extras.Rules) error { return fmt.Errorf("extra data hash mismatch: have %x, want %x", headerExtra.ExtDataHash, hash) } } else { + // Prior to AP1, the extra data hash was not properly initialized. if headerExtra.ExtDataHash != (common.Hash{}) { - return fmt.Errorf( - "expected ExtDataHash to be empty but got %x", - headerExtra.ExtDataHash, - ) + return fmt.Errorf("expected ExtDataHash to be empty but got %x", headerExtra.ExtDataHash) + } + + // Because the extra data hash was not included, the extra data prior to + // AP1 is not committed to based on the block hash. Therefore, we must + // manually verify that the extra data is correct for each block. + extData := customtypes.BlockExtData(ethBlock) + + // If extra data hashes map includes the block hash, we must enforce + // that the extra data provided in the block bytes matches the expected + // hash. + // + // Otherwise, if the extra data hashes map does not include the block + // hash, it is expected for no extra data to have been provided. + if expectedExtDataHash, ok := blockExtender.extDataHashes[blockHash]; ok { + extDataHash := customtypes.CalcExtDataHash(extData) + if extDataHash != expectedExtDataHash { + return fmt.Errorf("extra data hash in block (%s, %d): %s, did not match the expected extra data hash: %s", blockHash, b.Height(), extDataHash, expectedExtDataHash) + } + } else if len(extData) != 0 { + return fmt.Errorf("unexpectedly provided extra data in block (%s, %d)", blockHash, b.Height()) } } From 8a2d838edaaff900d94f7824aea420ce078f506f Mon Sep 17 00:00:00 2001 From: Stephen Buttolph Date: Thu, 5 Jun 2025 13:31:46 -0400 Subject: [PATCH 2/7] nit --- plugin/evm/atomic_block_extension.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/evm/atomic_block_extension.go b/plugin/evm/atomic_block_extension.go index 54b10653c7..c80698fe7f 100644 --- a/plugin/evm/atomic_block_extension.go +++ b/plugin/evm/atomic_block_extension.go @@ -107,7 +107,7 @@ func (be *blockExtension) SyntacticVerify(rules extras.Rules) error { // manually verify that the extra data is correct for each block. extData := customtypes.BlockExtData(ethBlock) - // If extra data hashes map includes the block hash, we must enforce + // If the extra data hashes map includes the block hash, we must enforce // that the extra data provided in the block bytes matches the expected // hash. // From 88f00bab3419899178743927006febb21a85961b Mon Sep 17 00:00:00 2001 From: Stephen Buttolph Date: Thu, 5 Jun 2025 13:33:51 -0400 Subject: [PATCH 3/7] nit --- plugin/evm/atomic_block_extension.go | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/plugin/evm/atomic_block_extension.go b/plugin/evm/atomic_block_extension.go index c80698fe7f..dcb810636f 100644 --- a/plugin/evm/atomic_block_extension.go +++ b/plugin/evm/atomic_block_extension.go @@ -90,11 +90,10 @@ func (be *blockExtension) SyntacticVerify(rules extras.Rules) error { blockHash := ethBlock.Hash() headerExtra := customtypes.GetHeaderExtra(ethHeader) - if rules.IsApricotPhase1 { - extraData := customtypes.BlockExtData(ethBlock) - hash := customtypes.CalcExtDataHash(extraData) - if headerExtra.ExtDataHash != hash { - return fmt.Errorf("extra data hash mismatch: have %x, want %x", headerExtra.ExtDataHash, hash) + if extData := customtypes.BlockExtData(ethBlock); rules.IsApricotPhase1 { + extDataHash := customtypes.CalcExtDataHash(extData) + if headerExtra.ExtDataHash != extDataHash { + return fmt.Errorf("extra data hash mismatch: have %x, want %x", headerExtra.ExtDataHash, extDataHash) } } else { // Prior to AP1, the extra data hash was not properly initialized. @@ -105,8 +104,7 @@ func (be *blockExtension) SyntacticVerify(rules extras.Rules) error { // Because the extra data hash was not included, the extra data prior to // AP1 is not committed to based on the block hash. Therefore, we must // manually verify that the extra data is correct for each block. - extData := customtypes.BlockExtData(ethBlock) - + // // If the extra data hashes map includes the block hash, we must enforce // that the extra data provided in the block bytes matches the expected // hash. From 5a28c54b0733d9dbf16daa16038cf06e63eb9ad5 Mon Sep 17 00:00:00 2001 From: Stephen Buttolph Date: Thu, 5 Jun 2025 13:34:11 -0400 Subject: [PATCH 4/7] nit --- plugin/evm/atomic_block_extension.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugin/evm/atomic_block_extension.go b/plugin/evm/atomic_block_extension.go index dcb810636f..cf7a0fb28b 100644 --- a/plugin/evm/atomic_block_extension.go +++ b/plugin/evm/atomic_block_extension.go @@ -90,7 +90,8 @@ func (be *blockExtension) SyntacticVerify(rules extras.Rules) error { blockHash := ethBlock.Hash() headerExtra := customtypes.GetHeaderExtra(ethHeader) - if extData := customtypes.BlockExtData(ethBlock); rules.IsApricotPhase1 { + extData := customtypes.BlockExtData(ethBlock) + if rules.IsApricotPhase1 { extDataHash := customtypes.CalcExtDataHash(extData) if headerExtra.ExtDataHash != extDataHash { return fmt.Errorf("extra data hash mismatch: have %x, want %x", headerExtra.ExtDataHash, extDataHash) From 34c75cbc34a18d1f08e19e828cea3ef63ec9ae9b Mon Sep 17 00:00:00 2001 From: Stephen Buttolph Date: Thu, 5 Jun 2025 13:36:16 -0400 Subject: [PATCH 5/7] Keep verification in order --- plugin/evm/atomic_block_extension.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/plugin/evm/atomic_block_extension.go b/plugin/evm/atomic_block_extension.go index cf7a0fb28b..134a5fdfbf 100644 --- a/plugin/evm/atomic_block_extension.go +++ b/plugin/evm/atomic_block_extension.go @@ -91,12 +91,7 @@ func (be *blockExtension) SyntacticVerify(rules extras.Rules) error { headerExtra := customtypes.GetHeaderExtra(ethHeader) extData := customtypes.BlockExtData(ethBlock) - if rules.IsApricotPhase1 { - extDataHash := customtypes.CalcExtDataHash(extData) - if headerExtra.ExtDataHash != extDataHash { - return fmt.Errorf("extra data hash mismatch: have %x, want %x", headerExtra.ExtDataHash, extDataHash) - } - } else { + if !rules.IsApricotPhase1 { // Prior to AP1, the extra data hash was not properly initialized. if headerExtra.ExtDataHash != (common.Hash{}) { return fmt.Errorf("expected ExtDataHash to be empty but got %x", headerExtra.ExtDataHash) @@ -120,6 +115,11 @@ func (be *blockExtension) SyntacticVerify(rules extras.Rules) error { } else if len(extData) != 0 { return fmt.Errorf("unexpectedly provided extra data in block (%s, %d)", blockHash, b.Height()) } + } else { + extDataHash := customtypes.CalcExtDataHash(extData) + if headerExtra.ExtDataHash != extDataHash { + return fmt.Errorf("extra data hash mismatch: have %x, want %x", headerExtra.ExtDataHash, extDataHash) + } } // Block must not be empty From f4e328ae69f477d2f85869b2f738eea46a513af3 Mon Sep 17 00:00:00 2001 From: Stephen Buttolph Date: Thu, 5 Jun 2025 13:40:55 -0400 Subject: [PATCH 6/7] nit --- plugin/evm/atomic_block_extension.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugin/evm/atomic_block_extension.go b/plugin/evm/atomic_block_extension.go index 134a5fdfbf..43a8d4e65b 100644 --- a/plugin/evm/atomic_block_extension.go +++ b/plugin/evm/atomic_block_extension.go @@ -97,8 +97,8 @@ func (be *blockExtension) SyntacticVerify(rules extras.Rules) error { return fmt.Errorf("expected ExtDataHash to be empty but got %x", headerExtra.ExtDataHash) } - // Because the extra data hash was not included, the extra data prior to - // AP1 is not committed to based on the block hash. Therefore, we must + // Because the extra data hash was not initialized, the extra data prior + // to AP1 is not committed to with the block hash. Therefore, we must // manually verify that the extra data is correct for each block. // // If the extra data hashes map includes the block hash, we must enforce From 13169593e73d2023c6aeea6a917046e7f7ca19dc Mon Sep 17 00:00:00 2001 From: Stephen Buttolph Date: Thu, 5 Jun 2025 13:41:54 -0400 Subject: [PATCH 7/7] comment --- plugin/evm/atomic_block_extension.go | 1 + 1 file changed, 1 insertion(+) diff --git a/plugin/evm/atomic_block_extension.go b/plugin/evm/atomic_block_extension.go index 43a8d4e65b..a806df4007 100644 --- a/plugin/evm/atomic_block_extension.go +++ b/plugin/evm/atomic_block_extension.go @@ -116,6 +116,7 @@ func (be *blockExtension) SyntacticVerify(rules extras.Rules) error { return fmt.Errorf("unexpectedly provided extra data in block (%s, %d)", blockHash, b.Height()) } } else { + // After AP1, the extra data hash must be properly initialized. extDataHash := customtypes.CalcExtDataHash(extData) if headerExtra.ExtDataHash != extDataHash { return fmt.Errorf("extra data hash mismatch: have %x, want %x", headerExtra.ExtDataHash, extDataHash)