Skip to content

Commit 44810d3

Browse files
feat: add BPO1 and BPO2 hardfork support (#9)
* feat: add BPO1 and BPO2 hardfork support Add BPO1 (Blob Parameter Only fork 1, EIP-7892) and BPO2 SpecId variants between Osaka and Amsterdam, with corresponding blob fraction and max blob count constants. - Add `bpo1` and `bpo2` to `SpecId` enum (between osaka and amsterdam) - Add `HardforkName.BPO1`/`BPO2` string constants - Add `specIdFromString`/`specIdToString` mappings for BPO1/BPO2 - Add `BLOB_BASE_FEE_UPDATE_FRACTION_BPO1` (8346193) and `_BPO2` (11684671) - Add `MAX_BLOB_NUMBER_PER_BLOCK_BPO1` (15) and `_BPO2` (21) - Add `BLOB_BASE_FEE_UPDATE_FRACTION_CANCUN` alias for clarity - Map bpo1/bpo2 to Osaka precompile set in `PrecompileSpecId` Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * fix: wire BPO1/BPO2 blob fractions into blobBaseFeeUpdateFraction The new bpo1/bpo2 SpecId variants were added but blobBaseFeeUpdateFraction only checked for Prague, returning 3,338,477 for all post-Prague forks instead of the correct values. Cascade the spec check to return the correct fraction per fork: - BPO2+: 11,684,671 (BLOB_BASE_FEE_UPDATE_FRACTION_BPO2) - BPO1+: 8,346,193 (BLOB_BASE_FEE_UPDATE_FRACTION_BPO1) - Osaka+: 5,007,716 (BLOB_BASE_FEE_UPDATE_FRACTION_OSAKA, EIP-7691) - Cancun+: 3,338,477 (BLOB_BASE_FEE_UPDATE_FRACTION_CANCUN) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * fix: activate EIP-7691 blob fraction at Prague instead of Osaka BLOB_BASE_FEE_UPDATE_FRACTION_OSAKA (5007716) is renamed to BLOB_BASE_FEE_UPDATE_FRACTION_PRAGUE since EIP-7691 activates at Prague, not Osaka. The redundant Prague alias for the Cancun fraction (3338477) is removed. blobBaseFeeUpdateFraction now branches on .prague instead of .osaka. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent c728935 commit 44810d3

File tree

3 files changed

+40
-16
lines changed

3 files changed

+40
-16
lines changed

src/context/cfg.zig

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ pub const CfgEnv = struct {
3939
/// If this config is not set, the blob base fee update fraction will be set to the default value.
4040
/// See also [CfgEnv::blob_base_fee_update_fraction].
4141
///
42-
/// Default values for Cancun is [`primitives::eip4844::BLOB_BASE_FEE_UPDATE_FRACTION_CANCUN`]
43-
/// and for Prague is [`primitives::eip4844::BLOB_BASE_FEE_UPDATE_FRACTION_PRAGUE`].
42+
/// Default values: Cancun (3338477), Prague/Osaka (5007716), BPO1 (8346193), BPO2 (11684671).
43+
/// See [`CfgEnv::blobBaseFeeUpdateFraction`] for the resolution logic.
4444
blob_base_fee_update_fraction: ?u64,
4545
/// Configures the gas limit cap for the transaction.
4646
///
@@ -341,15 +341,21 @@ pub const CfgEnv = struct {
341341

342342
/// Returns the blob base fee update fraction from [CfgEnv::blob_base_fee_update_fraction].
343343
///
344-
/// If this field is not set, return the default value for the spec.
345-
///
346-
/// Default values for Cancun is [`primitives::eip4844::BLOB_BASE_FEE_UPDATE_FRACTION_CANCUN`]
347-
/// and for Prague is [`primitives::eip4844::BLOB_BASE_FEE_UPDATE_FRACTION_PRAGUE`].
344+
/// If this field is not set, the default is derived from the active spec:
345+
/// - BPO2+: 11684671 (`BLOB_BASE_FEE_UPDATE_FRACTION_BPO2`)
346+
/// - BPO1: 8346193 (`BLOB_BASE_FEE_UPDATE_FRACTION_BPO1`)
347+
/// - Prague+: 5007716 (`BLOB_BASE_FEE_UPDATE_FRACTION_PRAGUE`, EIP-7691)
348+
/// - Cancun: 3338477 (`BLOB_BASE_FEE_UPDATE_FRACTION_CANCUN`)
348349
pub fn blobBaseFeeUpdateFraction(self: CfgEnv) u64 {
349-
return self.blob_base_fee_update_fraction orelse if (self.spec.isEnabledIn(primitives.SpecId.Prague))
350-
primitives.BLOB_BASE_FEE_UPDATE_FRACTION_PRAGUE
351-
else
352-
primitives.BLOB_BASE_FEE_UPDATE_FRACTION_CANCUN;
350+
return self.blob_base_fee_update_fraction orelse
351+
if (self.spec.isEnabledIn(.bpo2))
352+
primitives.BLOB_BASE_FEE_UPDATE_FRACTION_BPO2
353+
else if (self.spec.isEnabledIn(.bpo1))
354+
primitives.BLOB_BASE_FEE_UPDATE_FRACTION_BPO1
355+
else if (self.spec.isEnabledIn(.prague))
356+
primitives.BLOB_BASE_FEE_UPDATE_FRACTION_PRAGUE
357+
else
358+
primitives.BLOB_BASE_FEE_UPDATE_FRACTION_CANCUN;
353359
}
354360

355361
pub fn chainId(self: CfgEnv) u64 {

src/precompile/main.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ pub const PrecompileSpecId = enum {
180180
.berlin, .london, .arrow_glacier, .gray_glacier, .merge, .shanghai => .Berlin,
181181
.cancun => .Cancun,
182182
.prague => .Prague,
183-
.osaka, .amsterdam => .Osaka,
183+
.osaka, .bpo1, .bpo2, .amsterdam => .Osaka,
184184
};
185185
}
186186
};

src/primitives/main.zig

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,14 @@ pub const STACK_LIMIT: usize = 1024;
8181
/// EVM call stack limit
8282
pub const CALL_STACK_LIMIT: u64 = 1024;
8383

84-
/// Blob base fee update fraction for Prague hardfork
85-
pub const BLOB_BASE_FEE_UPDATE_FRACTION_PRAGUE: u64 = 3338477;
86-
/// Blob base fee update fraction for Osaka hardfork (EIP-7691)
87-
pub const BLOB_BASE_FEE_UPDATE_FRACTION_OSAKA: u64 = 5007716;
84+
/// Blob base fee update fraction for Cancun hardfork (EIP-4844)
85+
pub const BLOB_BASE_FEE_UPDATE_FRACTION_CANCUN: u64 = 3338477;
86+
/// Blob base fee update fraction for Prague/Osaka hardfork (EIP-7691)
87+
pub const BLOB_BASE_FEE_UPDATE_FRACTION_PRAGUE: u64 = 5007716;
88+
/// Blob base fee update fraction for BPO1 hardfork (EIP-7892)
89+
pub const BLOB_BASE_FEE_UPDATE_FRACTION_BPO1: u64 = 8346193;
90+
/// Blob base fee update fraction for BPO2/Amsterdam/Glamsterdam hardfork
91+
pub const BLOB_BASE_FEE_UPDATE_FRACTION_BPO2: u64 = 11684671;
8892
/// EIP-7918: blob base cost (2**13) used for reserve price calculation
8993
pub const BLOB_BASE_COST: u64 = 8192;
9094

@@ -93,8 +97,12 @@ pub const GAS_PER_BLOB: u64 = 131_072;
9397

9498
/// EIP-4844: maximum blobs per block (Cancun: 6, Prague+: 9 via EIP-7691)
9599
pub const MAX_BLOB_NUMBER_PER_BLOCK: usize = 6;
96-
/// EIP-7691: maximum blobs per block for Prague (9)
100+
/// EIP-7691: maximum blobs per block for Prague/Osaka (9)
97101
pub const MAX_BLOB_NUMBER_PER_BLOCK_PRAGUE: usize = 9;
102+
/// EIP-7892: maximum blobs per block for BPO1 (15)
103+
pub const MAX_BLOB_NUMBER_PER_BLOCK_BPO1: usize = 15;
104+
/// Maximum blobs per block for BPO2/Amsterdam/Glamsterdam (21)
105+
pub const MAX_BLOB_NUMBER_PER_BLOCK_BPO2: usize = 21;
98106
/// EIP-7594: maximum blobs per transaction for Osaka (6)
99107
pub const MAX_BLOB_NUMBER_PER_TX: usize = 6;
100108

@@ -155,6 +163,10 @@ pub const SpecId = enum(u8) {
155163
prague,
156164
/// Osaka hard fork - Activated at block TBD
157165
osaka,
166+
/// BPO1 hard fork - Blob Parameter Only fork 1 (EIP-7892)
167+
bpo1,
168+
/// BPO2 hard fork - Blob Parameter Only fork 2
169+
bpo2,
158170
/// Amsterdam hard fork - Activated at block TBD
159171
amsterdam,
160172
};
@@ -191,6 +203,8 @@ pub const HardforkName = struct {
191203
pub const CANCUN = "Cancun";
192204
pub const PRAGUE = "Prague";
193205
pub const OSAKA = "Osaka";
206+
pub const BPO1 = "BPO1";
207+
pub const BPO2 = "BPO2";
194208
pub const AMSTERDAM = "Amsterdam";
195209
pub const LATEST = "Latest";
196210
};
@@ -220,6 +234,8 @@ pub fn specIdFromString(s: []const u8) UnknownHardfork!SpecId {
220234
if (std.mem.eql(u8, s, HardforkName.CANCUN)) return .cancun;
221235
if (std.mem.eql(u8, s, HardforkName.PRAGUE)) return .prague;
222236
if (std.mem.eql(u8, s, HardforkName.OSAKA)) return .osaka;
237+
if (std.mem.eql(u8, s, HardforkName.BPO1)) return .bpo1;
238+
if (std.mem.eql(u8, s, HardforkName.BPO2)) return .bpo2;
223239
if (std.mem.eql(u8, s, HardforkName.AMSTERDAM)) return .amsterdam;
224240
return UnknownHardfork.UnknownHardfork;
225241
}
@@ -247,6 +263,8 @@ pub fn specIdToString(spec_id: SpecId) []const u8 {
247263
.cancun => HardforkName.CANCUN,
248264
.prague => HardforkName.PRAGUE,
249265
.osaka => HardforkName.OSAKA,
266+
.bpo1 => HardforkName.BPO1,
267+
.bpo2 => HardforkName.BPO2,
250268
.amsterdam => HardforkName.AMSTERDAM,
251269
};
252270
}

0 commit comments

Comments
 (0)