From 20f96dab44a7fe889ef7cd4e7c07f4d5befcd6d3 Mon Sep 17 00:00:00 2001 From: NC <17676176+ensi321@users.noreply.github.com> Date: Fri, 6 Sep 2024 14:59:06 -0700 Subject: [PATCH 1/7] Update slashing calculation to be more aligned with spec style --- packages/state-transition/src/epoch/processSlashings.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/state-transition/src/epoch/processSlashings.ts b/packages/state-transition/src/epoch/processSlashings.ts index ba4b483dffc2..0e587e1c7610 100644 --- a/packages/state-transition/src/epoch/processSlashings.ts +++ b/packages/state-transition/src/epoch/processSlashings.ts @@ -50,6 +50,9 @@ export function processSlashings( totalBalanceByIncrement ); const increment = EFFECTIVE_BALANCE_INCREMENT; + const adjustedTotalSlashingBalance = adjustedTotalSlashingBalanceByIncrement * increment; + + const penaltyPerEffectiveBalanceIncrement = Math.floor(adjustedTotalSlashingBalance / totalBalanceByIncrement); const penalties: number[] = []; const penaltiesByEffectiveBalanceIncrement = new Map(); @@ -57,8 +60,7 @@ export function processSlashings( const effectiveBalanceIncrement = effectiveBalanceIncrements[index]; let penalty = penaltiesByEffectiveBalanceIncrement.get(effectiveBalanceIncrement); if (penalty === undefined) { - const penaltyNumeratorByIncrement = effectiveBalanceIncrement * adjustedTotalSlashingBalanceByIncrement; - penalty = Math.floor(penaltyNumeratorByIncrement / totalBalanceByIncrement) * increment; + penalty = penaltyPerEffectiveBalanceIncrement * effectiveBalanceIncrement; penaltiesByEffectiveBalanceIncrement.set(effectiveBalanceIncrement, penalty); } From 1b798e620248a3eac8b00a91e603e9692f9d3fdc Mon Sep 17 00:00:00 2001 From: NC <17676176+ensi321@users.noreply.github.com> Date: Fri, 6 Sep 2024 15:17:14 -0700 Subject: [PATCH 2/7] Update calculation --- packages/state-transition/src/epoch/processSlashings.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/state-transition/src/epoch/processSlashings.ts b/packages/state-transition/src/epoch/processSlashings.ts index 0e587e1c7610..c4bdc00af889 100644 --- a/packages/state-transition/src/epoch/processSlashings.ts +++ b/packages/state-transition/src/epoch/processSlashings.ts @@ -50,9 +50,8 @@ export function processSlashings( totalBalanceByIncrement ); const increment = EFFECTIVE_BALANCE_INCREMENT; - const adjustedTotalSlashingBalance = adjustedTotalSlashingBalanceByIncrement * increment; - const penaltyPerEffectiveBalanceIncrement = Math.floor(adjustedTotalSlashingBalance / totalBalanceByIncrement); + const penaltyPerEffectiveBalanceIncrement = Math.floor(adjustedTotalSlashingBalanceByIncrement / totalBalanceByIncrement) * increment; const penalties: number[] = []; const penaltiesByEffectiveBalanceIncrement = new Map(); From 8c498c9d3fe5759b5a3be046622f3f0de6160952 Mon Sep 17 00:00:00 2001 From: NC <17676176+ensi321@users.noreply.github.com> Date: Sat, 7 Sep 2024 09:19:07 -0700 Subject: [PATCH 3/7] Lint --- packages/state-transition/src/epoch/processSlashings.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/state-transition/src/epoch/processSlashings.ts b/packages/state-transition/src/epoch/processSlashings.ts index c4bdc00af889..7cba5905018c 100644 --- a/packages/state-transition/src/epoch/processSlashings.ts +++ b/packages/state-transition/src/epoch/processSlashings.ts @@ -51,7 +51,8 @@ export function processSlashings( ); const increment = EFFECTIVE_BALANCE_INCREMENT; - const penaltyPerEffectiveBalanceIncrement = Math.floor(adjustedTotalSlashingBalanceByIncrement / totalBalanceByIncrement) * increment; + const penaltyPerEffectiveBalanceIncrement = + Math.floor(adjustedTotalSlashingBalanceByIncrement / totalBalanceByIncrement) * increment; const penalties: number[] = []; const penaltiesByEffectiveBalanceIncrement = new Map(); From d3bec5af6b70112db729741318f8f560840801f5 Mon Sep 17 00:00:00 2001 From: NC <17676176+ensi321@users.noreply.github.com> Date: Mon, 9 Sep 2024 15:04:08 -0700 Subject: [PATCH 4/7] Fix rounding issue --- packages/state-transition/src/epoch/processSlashings.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/state-transition/src/epoch/processSlashings.ts b/packages/state-transition/src/epoch/processSlashings.ts index 7cba5905018c..6548f2dd8be6 100644 --- a/packages/state-transition/src/epoch/processSlashings.ts +++ b/packages/state-transition/src/epoch/processSlashings.ts @@ -51,8 +51,7 @@ export function processSlashings( ); const increment = EFFECTIVE_BALANCE_INCREMENT; - const penaltyPerEffectiveBalanceIncrement = - Math.floor(adjustedTotalSlashingBalanceByIncrement / totalBalanceByIncrement) * increment; + const penaltyPerEffectiveBalanceIncrement = Math.floor((adjustedTotalSlashingBalanceByIncrement * increment) / totalBalanceByIncrement); const penalties: number[] = []; const penaltiesByEffectiveBalanceIncrement = new Map(); From e07ed10bbdc3df56987be9c432f50ffdbb650f74 Mon Sep 17 00:00:00 2001 From: NC <17676176+ensi321@users.noreply.github.com> Date: Mon, 9 Sep 2024 15:50:30 -0700 Subject: [PATCH 5/7] Update calculation --- packages/state-transition/src/epoch/processSlashings.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/state-transition/src/epoch/processSlashings.ts b/packages/state-transition/src/epoch/processSlashings.ts index 6548f2dd8be6..92c6b5b2d7af 100644 --- a/packages/state-transition/src/epoch/processSlashings.ts +++ b/packages/state-transition/src/epoch/processSlashings.ts @@ -59,7 +59,12 @@ export function processSlashings( const effectiveBalanceIncrement = effectiveBalanceIncrements[index]; let penalty = penaltiesByEffectiveBalanceIncrement.get(effectiveBalanceIncrement); if (penalty === undefined) { - penalty = penaltyPerEffectiveBalanceIncrement * effectiveBalanceIncrement; + if (fork < ForkSeq.electra) { + const penaltyNumeratorByIncrement = effectiveBalanceIncrement * adjustedTotalSlashingBalanceByIncrement; + penalty = Math.floor(penaltyNumeratorByIncrement / totalBalanceByIncrement) * increment; + } else { + penalty = penaltyPerEffectiveBalanceIncrement * effectiveBalanceIncrement; + } penaltiesByEffectiveBalanceIncrement.set(effectiveBalanceIncrement, penalty); } From ba0e0b4702df968841c2492f1fc858eae3a7d026 Mon Sep 17 00:00:00 2001 From: NC <17676176+ensi321@users.noreply.github.com> Date: Tue, 24 Sep 2024 19:00:05 -0700 Subject: [PATCH 6/7] Enable slashing spec test --- packages/beacon-node/test/spec/utils/specTestIterator.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/beacon-node/test/spec/utils/specTestIterator.ts b/packages/beacon-node/test/spec/utils/specTestIterator.ts index bd5142627e3f..d8b4f9c0574c 100644 --- a/packages/beacon-node/test/spec/utils/specTestIterator.ts +++ b/packages/beacon-node/test/spec/utils/specTestIterator.ts @@ -66,8 +66,6 @@ export const defaultSkipOpts: SkipOpts = { /^capella\/light_client\/single_merkle_proof\/BeaconBlockBody.*/, /^deneb\/light_client\/single_merkle_proof\/BeaconBlockBody.*/, /^electra\/light_client\/single_merkle_proof\/BeaconBlockBody.*/, - // TODO Electra: slashings tests to be enabled in PR#7071 - /^electra\/epoch_processing\/slashings.*/, ], skippedTests: [], skippedRunners: ["merkle_proof", "networking"], From 8d6062320ab943d143b634b16c8a618b09692142 Mon Sep 17 00:00:00 2001 From: NC <17676176+ensi321@users.noreply.github.com> Date: Thu, 26 Sep 2024 15:15:30 -0700 Subject: [PATCH 7/7] lint --- packages/state-transition/src/epoch/processSlashings.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/state-transition/src/epoch/processSlashings.ts b/packages/state-transition/src/epoch/processSlashings.ts index 92c6b5b2d7af..23ee815cabb3 100644 --- a/packages/state-transition/src/epoch/processSlashings.ts +++ b/packages/state-transition/src/epoch/processSlashings.ts @@ -51,7 +51,9 @@ export function processSlashings( ); const increment = EFFECTIVE_BALANCE_INCREMENT; - const penaltyPerEffectiveBalanceIncrement = Math.floor((adjustedTotalSlashingBalanceByIncrement * increment) / totalBalanceByIncrement); + const penaltyPerEffectiveBalanceIncrement = Math.floor( + (adjustedTotalSlashingBalanceByIncrement * increment) / totalBalanceByIncrement + ); const penalties: number[] = []; const penaltiesByEffectiveBalanceIncrement = new Map();