From 0d658023881d7fae3da145e759039f68c1bf315b Mon Sep 17 00:00:00 2001 From: Valentin Staykov <79150443+V-Staykov@users.noreply.github.com> Date: Fri, 28 Jun 2024 12:12:41 +0300 Subject: [PATCH] added steps for forkid 10 and 11 (#677) --- core/vm/zk_counters_limits.go | 44 ++++++++++++++++++++++++----------- zk/constants/constants.go | 2 ++ 2 files changed, 33 insertions(+), 13 deletions(-) diff --git a/core/vm/zk_counters_limits.go b/core/vm/zk_counters_limits.go index b78466e09a6..311c37c3d88 100644 --- a/core/vm/zk_counters_limits.go +++ b/core/vm/zk_counters_limits.go @@ -7,16 +7,9 @@ import ( ) var ( - defaultTotalSteps = 1 << 23 - defaultCounterLimits = counterLimits{ - totalSteps: defaultTotalSteps, - arith: defaultTotalSteps >> 5, - binary: defaultTotalSteps >> 4, - memAlign: defaultTotalSteps >> 5, - keccaks: int(math.Floor(float64(defaultTotalSteps)/155286) * 44), - padding: int(math.Floor(float64(defaultTotalSteps) / 56)), - poseidon: int(math.Floor(float64(defaultTotalSteps) / 30)), - } + defaultTotalSteps = 1 << 23 + forkId10TotalSteps = 1 << 24 + forkId11TotalSteps = 1 << 25 unlimitedCounters = counterLimits{ totalSteps: math.MaxInt32, @@ -26,6 +19,7 @@ var ( keccaks: math.MaxInt32, padding: math.MaxInt32, poseidon: math.MaxInt32, + sha256: math.MaxInt32, } ) @@ -80,9 +74,33 @@ func createCountrsByLimits(c counterLimits) *Counters { // tp ne used on next forkid counters func getCounterLimits(forkId uint16) *Counters { - if forkId <= uint16(zk_consts.ForkID9Elderberry2) { - return createCountrsByLimits(defaultCounterLimits) + totalSteps := getTotalSteps(forkId) + + counterLimits := counterLimits{ + totalSteps: totalSteps, + arith: totalSteps >> 5, + binary: totalSteps >> 4, + memAlign: totalSteps >> 5, + keccaks: int(math.Floor(float64(totalSteps)/155286) * 44), + padding: int(math.Floor(float64(totalSteps) / 56)), + poseidon: int(math.Floor(float64(totalSteps) / 30)), + sha256: int(math.Floor(float64(totalSteps-1)/31488)) * 7, + } + + return createCountrsByLimits(counterLimits) +} + +func getTotalSteps(forkId uint16) int { + var totalSteps int + + switch forkId { + case uint16(zk_consts.ForkID10): + totalSteps = forkId10TotalSteps + case uint16(zk_consts.ForkID11): + totalSteps = forkId11TotalSteps + default: + totalSteps = defaultTotalSteps } - return createCountrsByLimits(defaultCounterLimits) + return totalSteps } diff --git a/zk/constants/constants.go b/zk/constants/constants.go index 719d1484736..39e99154ac6 100644 --- a/zk/constants/constants.go +++ b/zk/constants/constants.go @@ -9,4 +9,6 @@ const ( ForkID7Etrog ForkId = 7 ForkID8Elderberry ForkId = 8 ForkID9Elderberry2 ForkId = 9 + ForkID10 ForkId = 10 + ForkID11 ForkId = 11 )