Skip to content

Commit

Permalink
Add ImpossibleForkId
Browse files Browse the repository at this point in the history
  • Loading branch information
cffls committed Oct 24, 2024
1 parent afa4cd6 commit b627c04
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 8 deletions.
6 changes: 3 additions & 3 deletions core/vm/zk_counters.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (
"math/big"

"github.com/holiman/uint256"
"github.com/ledgerwatch/erigon-lib/chain"
"github.com/ledgerwatch/erigon/core/types"
"github.com/ledgerwatch/erigon/zk/hermez_db"
"github.com/ledgerwatch/erigon-lib/chain"
)

const (
Expand Down Expand Up @@ -610,7 +610,7 @@ func (cc *CounterCollector) finishBatchProcessing() {

func (cc *CounterCollector) isColdAddress() {
cc.Deduct(S, 100)
if cc.forkId >= chain.ForkId13Durian {
if cc.forkId >= uint16(chain.ForkId13Durian) {
cc.Deduct(B, 3+1)
} else {
cc.Deduct(B, 2+1)
Expand Down Expand Up @@ -850,7 +850,7 @@ func (cc *CounterCollector) preModExp(callDataLength, returnDataLength, bLen, mL

func (cc *CounterCollector) modExp(bLen, mLen, eLen int, base, exponent, modulus *big.Int) {
var steps, binary, arith *big.Int
if cc.forkId >= chain.ForkId13Durian {
if cc.forkId >= uint16(chain.ForkId13Durian) {
steps, binary, arith = expectedModExpCounters(
int(math.Ceil(float64(bLen)/32)),
int(math.Ceil(float64(eLen)/32)),
Expand Down
4 changes: 2 additions & 2 deletions core/vm/zk_transaction_counters.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import (
"fmt"
"math"

"github.com/ledgerwatch/erigon-lib/chain"
"github.com/ledgerwatch/erigon-lib/common/hexutil"
"github.com/ledgerwatch/erigon/core/state"
"github.com/ledgerwatch/erigon/core/types"
"github.com/ledgerwatch/erigon/zk/tx"
"github.com/ledgerwatch/erigon-lib/chain"
)

type TransactionCounter struct {
Expand Down Expand Up @@ -183,7 +183,7 @@ func (tc *TransactionCounter) ProcessTx(ibs *state.IntraBlockState, returnData [

cc := NewCounterCollector(tc.smtLevels, tc.forkId)
cc.Deduct(S, 300)
if tc.forkId >= chain.ForkId13Durian {
if tc.forkId >= uint16(chain.ForkId13Durian) {
cc.Deduct(B, 12+7)
} else {
cc.Deduct(B, 11+7)
Expand Down
3 changes: 3 additions & 0 deletions erigon-lib/chain/chain_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
// this needs to always be in descending order
// add new forkIds at the beginning of the array
var ForkIdsOrdered = []ForkId{
ForkId13Durian,
ForkID12Banana,
ForkID11,
ForkID10,
Expand Down Expand Up @@ -180,6 +181,8 @@ func (c *Config) SetForkIdBlock(forkIdNumber ForkId, blockNum uint64) error {
c.ForkID11 = new(big.Int).SetUint64(blockNum)
case ForkID12Banana:
c.ForkID12BananaBlock = new(big.Int).SetUint64(blockNum)
case ForkId13Durian:
c.ForkId13Durian = new(big.Int).SetUint64(blockNum)
default:
return fmt.Errorf("unknown fork id number %d", forkIdNumber)
}
Expand Down
6 changes: 5 additions & 1 deletion erigon-lib/chain/zk_constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,9 @@ const (
ForkID10
ForkID11
ForkID12Banana
ForkId13Durian = 13
ForkId13Durian

// ImpossibleForkId is a fork ID that is greater than any possible fork ID
// Nothing should be added after this line
ImpossibleForkId
)
1 change: 0 additions & 1 deletion zk/stages/stage_batches.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import (
)

const (
HIGHEST_KNOWN_FORK = 13
STAGE_PROGRESS_SAVE = 3000000
NEW_BLOCKS_ON_DS_LIMIT = 10000
)
Expand Down
2 changes: 1 addition & 1 deletion zk/stages/stage_batches_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ func (p *BatchesProcessor) processFullBlock(blockEntry *types.FullL2Block) (rest
// channels can be read in random orders which then creates problems in detecting fork changes during
// execution
if blockEntry.BatchNumber > p.highestSeenBatchNo && p.lastForkId < blockEntry.ForkId {
if blockEntry.ForkId > HIGHEST_KNOWN_FORK {
if blockEntry.ForkId >= uint64(chain.ImpossibleForkId) {
message := fmt.Sprintf("unsupported fork id %v received from the data stream", blockEntry.ForkId)
panic(message)
}
Expand Down

0 comments on commit b627c04

Please sign in to comment.