From cd5a7d33913979fc18c129e8047416b7deab3c40 Mon Sep 17 00:00:00 2001 From: Arpit Temani Date: Thu, 9 Nov 2023 16:36:21 +0530 Subject: [PATCH 1/4] change withdrawals hash --- core/state_processor_test.go | 2 +- core/types/block.go | 7 +++---- core/types/hashes.go | 2 +- core/vm/jump_table.go | 3 ++- eth/catalyst/api.go | 2 +- eth/downloader/queue.go | 2 +- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/core/state_processor_test.go b/core/state_processor_test.go index fed9e18b0f..bf57aa705d 100644 --- a/core/state_processor_test.go +++ b/core/state_processor_test.go @@ -383,7 +383,7 @@ func GenerateBadBlock(parent *types.Block, engine consensus.Engine, txs types.Tr header.BaseFee = eip1559.CalcBaseFee(config, parent.Header()) } if config.IsShanghai(header.Number) { - header.WithdrawalsHash = &types.EmptyWithdrawalsHash + header.WithdrawalsHash = nil } var receipts []*types.Receipt diff --git a/core/types/block.go b/core/types/block.go index b3b8eea59d..3b143a2450 100644 --- a/core/types/block.go +++ b/core/types/block.go @@ -176,7 +176,7 @@ func (h *Header) SanityCheck() error { // that is: no transactions, no uncles and no withdrawals. func (h *Header) EmptyBody() bool { if h.WithdrawalsHash != nil { - return h.TxHash == EmptyTxsHash && *h.WithdrawalsHash == EmptyWithdrawalsHash + return h.TxHash == EmptyTxsHash && h.WithdrawalsHash == nil } return h.TxHash == EmptyTxsHash && h.UncleHash == EmptyUncleHash } @@ -323,7 +323,7 @@ func NewBlockWithWithdrawals(header *Header, txs []*Transaction, uncles []*Heade if withdrawals == nil { b.header.WithdrawalsHash = nil } else if len(withdrawals) == 0 { - b.header.WithdrawalsHash = &EmptyWithdrawalsHash + b.header.WithdrawalsHash = nil } else { h := DeriveSha(Withdrawals(withdrawals), hasher) b.header.WithdrawalsHash = &h @@ -353,8 +353,7 @@ func CopyHeader(h *Header) *Header { } if h.WithdrawalsHash != nil { - cpy.WithdrawalsHash = new(common.Hash) - *cpy.WithdrawalsHash = *h.WithdrawalsHash + cpy.WithdrawalsHash = nil } if h.ExcessBlobGas != nil { cpy.ExcessBlobGas = new(uint64) diff --git a/core/types/hashes.go b/core/types/hashes.go index 3a787aa136..1c4f8e9ddc 100644 --- a/core/types/hashes.go +++ b/core/types/hashes.go @@ -39,7 +39,7 @@ var ( EmptyReceiptsHash = common.HexToHash("56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421") // EmptyWithdrawalsHash is the known hash of the empty withdrawal set. - EmptyWithdrawalsHash = common.HexToHash("56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421") + // EmptyWithdrawalsHash = common.HexToHash("56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421") ) // TrieRootHash returns the hash itself if it's non-empty or the predefined diff --git a/core/vm/jump_table.go b/core/vm/jump_table.go index f05c3a8a95..72aa9fa858 100644 --- a/core/vm/jump_table.go +++ b/core/vm/jump_table.go @@ -83,7 +83,8 @@ func validate(jt JumpTable) JumpTable { func newCancunInstructionSet() JumpTable { instructionSet := newShanghaiInstructionSet() - enable4844(&instructionSet) // EIP-4844 (DATAHASH opcode) + // Not included in bor's cancun fork + // enable4844(&instructionSet) // EIP-4844 (DATAHASH opcode) enable1153(&instructionSet) // EIP-1153 "Transient Storage" enable5656(&instructionSet) // EIP-5656 (MCOPY opcode) enable6780(&instructionSet) // EIP-6780 SELFDESTRUCT only in same transaction diff --git a/eth/catalyst/api.go b/eth/catalyst/api.go index 0c122dca4b..b704fe7baa 100644 --- a/eth/catalyst/api.go +++ b/eth/catalyst/api.go @@ -793,7 +793,7 @@ func getBody(block *types.Block) *engine.ExecutionPayloadBodyV1 { // Post-shanghai withdrawals MUST be set to empty slice instead of nil if withdrawals == nil && block.Header().WithdrawalsHash != nil { - withdrawals = make([]*types.Withdrawal, 0) + withdrawals = nil } return &engine.ExecutionPayloadBodyV1{ diff --git a/eth/downloader/queue.go b/eth/downloader/queue.go index 2dd9a0a694..2cc1099936 100644 --- a/eth/downloader/queue.go +++ b/eth/downloader/queue.go @@ -78,7 +78,7 @@ func newFetchResult(header *types.Header, fastSync bool) *fetchResult { if !header.EmptyBody() { item.pending.Store(item.pending.Load() | (1 << bodyType)) } else if header.WithdrawalsHash != nil { - item.Withdrawals = make(types.Withdrawals, 0) + item.Withdrawals = nil } if fastSync && !header.EmptyReceipts() { From 3106cb143b75022266fa6d8f2fa5012295409673 Mon Sep 17 00:00:00 2001 From: Arpit Temani Date: Thu, 9 Nov 2023 18:09:39 +0530 Subject: [PATCH 2/4] Revert "change withdrawals hash" This reverts commit cd5a7d33913979fc18c129e8047416b7deab3c40. --- core/state_processor_test.go | 2 +- core/types/block.go | 7 ++++--- core/types/hashes.go | 2 +- core/vm/jump_table.go | 3 +-- eth/catalyst/api.go | 2 +- eth/downloader/queue.go | 2 +- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/core/state_processor_test.go b/core/state_processor_test.go index bf57aa705d..fed9e18b0f 100644 --- a/core/state_processor_test.go +++ b/core/state_processor_test.go @@ -383,7 +383,7 @@ func GenerateBadBlock(parent *types.Block, engine consensus.Engine, txs types.Tr header.BaseFee = eip1559.CalcBaseFee(config, parent.Header()) } if config.IsShanghai(header.Number) { - header.WithdrawalsHash = nil + header.WithdrawalsHash = &types.EmptyWithdrawalsHash } var receipts []*types.Receipt diff --git a/core/types/block.go b/core/types/block.go index 3b143a2450..b3b8eea59d 100644 --- a/core/types/block.go +++ b/core/types/block.go @@ -176,7 +176,7 @@ func (h *Header) SanityCheck() error { // that is: no transactions, no uncles and no withdrawals. func (h *Header) EmptyBody() bool { if h.WithdrawalsHash != nil { - return h.TxHash == EmptyTxsHash && h.WithdrawalsHash == nil + return h.TxHash == EmptyTxsHash && *h.WithdrawalsHash == EmptyWithdrawalsHash } return h.TxHash == EmptyTxsHash && h.UncleHash == EmptyUncleHash } @@ -323,7 +323,7 @@ func NewBlockWithWithdrawals(header *Header, txs []*Transaction, uncles []*Heade if withdrawals == nil { b.header.WithdrawalsHash = nil } else if len(withdrawals) == 0 { - b.header.WithdrawalsHash = nil + b.header.WithdrawalsHash = &EmptyWithdrawalsHash } else { h := DeriveSha(Withdrawals(withdrawals), hasher) b.header.WithdrawalsHash = &h @@ -353,7 +353,8 @@ func CopyHeader(h *Header) *Header { } if h.WithdrawalsHash != nil { - cpy.WithdrawalsHash = nil + cpy.WithdrawalsHash = new(common.Hash) + *cpy.WithdrawalsHash = *h.WithdrawalsHash } if h.ExcessBlobGas != nil { cpy.ExcessBlobGas = new(uint64) diff --git a/core/types/hashes.go b/core/types/hashes.go index 1c4f8e9ddc..3a787aa136 100644 --- a/core/types/hashes.go +++ b/core/types/hashes.go @@ -39,7 +39,7 @@ var ( EmptyReceiptsHash = common.HexToHash("56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421") // EmptyWithdrawalsHash is the known hash of the empty withdrawal set. - // EmptyWithdrawalsHash = common.HexToHash("56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421") + EmptyWithdrawalsHash = common.HexToHash("56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421") ) // TrieRootHash returns the hash itself if it's non-empty or the predefined diff --git a/core/vm/jump_table.go b/core/vm/jump_table.go index 72aa9fa858..f05c3a8a95 100644 --- a/core/vm/jump_table.go +++ b/core/vm/jump_table.go @@ -83,8 +83,7 @@ func validate(jt JumpTable) JumpTable { func newCancunInstructionSet() JumpTable { instructionSet := newShanghaiInstructionSet() - // Not included in bor's cancun fork - // enable4844(&instructionSet) // EIP-4844 (DATAHASH opcode) + enable4844(&instructionSet) // EIP-4844 (DATAHASH opcode) enable1153(&instructionSet) // EIP-1153 "Transient Storage" enable5656(&instructionSet) // EIP-5656 (MCOPY opcode) enable6780(&instructionSet) // EIP-6780 SELFDESTRUCT only in same transaction diff --git a/eth/catalyst/api.go b/eth/catalyst/api.go index b704fe7baa..0c122dca4b 100644 --- a/eth/catalyst/api.go +++ b/eth/catalyst/api.go @@ -793,7 +793,7 @@ func getBody(block *types.Block) *engine.ExecutionPayloadBodyV1 { // Post-shanghai withdrawals MUST be set to empty slice instead of nil if withdrawals == nil && block.Header().WithdrawalsHash != nil { - withdrawals = nil + withdrawals = make([]*types.Withdrawal, 0) } return &engine.ExecutionPayloadBodyV1{ diff --git a/eth/downloader/queue.go b/eth/downloader/queue.go index 2cc1099936..2dd9a0a694 100644 --- a/eth/downloader/queue.go +++ b/eth/downloader/queue.go @@ -78,7 +78,7 @@ func newFetchResult(header *types.Header, fastSync bool) *fetchResult { if !header.EmptyBody() { item.pending.Store(item.pending.Load() | (1 << bodyType)) } else if header.WithdrawalsHash != nil { - item.Withdrawals = nil + item.Withdrawals = make(types.Withdrawals, 0) } if fastSync && !header.EmptyReceipts() { From cee2c221b22887c43fbd6aac262082bb70ba1787 Mon Sep 17 00:00:00 2001 From: Arpit Temani Date: Thu, 9 Nov 2023 20:43:18 +0530 Subject: [PATCH 3/4] disbale 4844 --- core/vm/jump_table.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/vm/jump_table.go b/core/vm/jump_table.go index f05c3a8a95..e2e8342516 100644 --- a/core/vm/jump_table.go +++ b/core/vm/jump_table.go @@ -83,7 +83,8 @@ func validate(jt JumpTable) JumpTable { func newCancunInstructionSet() JumpTable { instructionSet := newShanghaiInstructionSet() - enable4844(&instructionSet) // EIP-4844 (DATAHASH opcode) + // Disabled in bor + // enable4844(&instructionSet) // EIP-4844 (DATAHASH opcode) enable1153(&instructionSet) // EIP-1153 "Transient Storage" enable5656(&instructionSet) // EIP-5656 (MCOPY opcode) enable6780(&instructionSet) // EIP-6780 SELFDESTRUCT only in same transaction From bee537ab9863393d9bfa0b1fe988d533545bb355 Mon Sep 17 00:00:00 2001 From: Arpit Temani Date: Thu, 9 Nov 2023 21:19:27 +0530 Subject: [PATCH 4/4] fix lint --- core/vm/eips.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/core/vm/eips.go b/core/vm/eips.go index a7ba15f382..1f7a9d68f0 100644 --- a/core/vm/eips.go +++ b/core/vm/eips.go @@ -294,16 +294,16 @@ func opBlobHash(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([ return nil, nil } -// enable4844 applies EIP-4844 (DATAHASH opcode) -func enable4844(jt *JumpTable) { - // New opcode - jt[BLOBHASH] = &operation{ - execute: opBlobHash, - constantGas: GasFastestStep, - minStack: minStack(1, 1), - maxStack: maxStack(1, 1), - } -} +// // enable4844 applies EIP-4844 (DATAHASH opcode) +// func enable4844(jt *JumpTable) { +// // New opcode +// jt[BLOBHASH] = &operation{ +// execute: opBlobHash, +// constantGas: GasFastestStep, +// minStack: minStack(1, 1), +// maxStack: maxStack(1, 1), +// } +// } // enable6780 applies EIP-6780 (deactivate SELFDESTRUCT) func enable6780(jt *JumpTable) {