Skip to content

Commit 990411c

Browse files
Precompiles for Multi-Dimensional Multi-Constraint Pricer
1 parent f49a488 commit 990411c

File tree

3 files changed

+91
-0
lines changed

3 files changed

+91
-0
lines changed

ArbGasInfo.sol

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
pragma solidity >=0.4.21 <0.9.0;
66

7+
import {ArbMultiGasConstraintsTypes} from "./ArbMultiGasConstraintsTypes.sol";
8+
79
/// @title Provides insight into the cost of using the chain.
810
/// @notice These methods have been adjusted to account for Nitro's heavy use of calldata compression.
911
/// Of note to end-users, we no longer make a distinction between non-zero and zero-valued calldata bytes.
@@ -141,4 +143,21 @@ interface ArbGasInfo {
141143
/// @return constraints Array of triples (gas_target_per_second, adjustment_window_seconds, backlog)
142144
/// @notice Available in ArbOS version 50 and above.
143145
function getGasPricingConstraints() external view returns (uint64[3][] memory constraints);
146+
147+
/// @notice Get the current multi-gas pricing constraints used by the multi-dimensional multi-constraint pricing model.
148+
/// @notice Each constraint includes its target throughput, adjustment window, backlog, and weighted resource configuration.
149+
///
150+
/// @notice The array contains one `ResourceConstraint` struct per active constraint.
151+
/// @notice Each constraint provides the following fields:
152+
/// - `resources`: list of (resource kind, weight) pairs (see the ArbMultiGasConstraintsTypes library for definitions)
153+
/// - `adjustmentWindowSecs`: time window (seconds) over which the price rises by a factor of e if demand is 2x the target (uint64, seconds)
154+
/// - `targetPerSec`: target gas usage per second for this constraint (uint64, gas/sec)
155+
/// - `backlog`: current backlog value for this constraint (uint64, gas units)
156+
/// @return constraints Array of `ResourceConstraint` structs representing the current multi-gas pricing configuration.
157+
/// @notice Available in ArbOS version 60 and above.
158+
/// @notice See the `ArbMultiGasConstraintsTypes` library for struct definitions and field details.
159+
function getMultiGasPricingConstraints()
160+
external
161+
view
162+
returns (ArbMultiGasConstraintsTypes.ResourceConstraint[] memory constraints);
144163
}

ArbMultiGasConstraintsTypes.sol

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Copyright 2025, Offchain Labs, Inc.
2+
// For license information, see https://github.com/OffchainLabs/nitro-contracts/blob/main/LICENSE
3+
// SPDX-License-Identifier: BUSL-1.1
4+
5+
pragma solidity >=0.4.21 <0.9.0;
6+
7+
/// @title ArbMultiGasConstraintsTypes
8+
/// @notice Type definitions for configuring and inspecting multi-dimensional gas pricing constraints.
9+
/// @dev These structures are shared by the `ArbOwner` and `ArbGasInfo` precompiles.
10+
library ArbMultiGasConstraintsTypes {
11+
12+
/// @notice Enumerates the distinct resource kinds used for multi-dimensional gas accounting.
13+
/// @dev The numeric values of this enum must remain consistent with the corresponding
14+
/// @dev The values defined here must stay synchronized with `go-ethereum/arbitrum/multigas/resources.go`.
15+
enum ResourceKind {
16+
Unknown,
17+
Computation,
18+
HistoryGrowth,
19+
StorageAccess,
20+
StorageGrowth,
21+
L1Calldata,
22+
L2Calldata,
23+
WasmComputation
24+
}
25+
26+
/// @notice Defines the relative contribution of a specific resource type within a constraint.
27+
/// @param resource The resource kind being weighted.
28+
/// @param weight The proportional weight that determines this resource kind’s influence on backlog growth.
29+
struct WeightedResource {
30+
ResourceKind resource;
31+
uint64 weight;
32+
}
33+
34+
/// @notice Describes a single pricing constraint that applies to one or more weighted resources.
35+
/// @param resources The list of weighted resources that participate in this constraint.
36+
/// @param adjustmentWindowSecs Time window (seconds) over which the price rises by a factor of e if demand is 2x the target (uint64, seconds)
37+
/// @param targetPerSec The target gas usage per second for this constraint (uint64, gas/sec).
38+
/// @param backlog The current or initial backlogfor this constraint (uint64, gas units).
39+
struct ResourceConstraint {
40+
WeightedResource[] resources;
41+
uint32 adjustmentWindowSecs;
42+
uint64 targetPerSec;
43+
uint64 backlog;
44+
}
45+
}

ArbOwner.sol

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
pragma solidity >=0.4.21 <0.9.0;
66

7+
import {ArbMultiGasConstraintsTypes} from "./ArbMultiGasConstraintsTypes.sol";
8+
79
/**
810
* @title Provides owners with tools for managing the rollup.
911
* @notice Calls by non-owners will always revert.
@@ -302,6 +304,31 @@ interface ArbOwner {
302304
uint64[3][] calldata constraints
303305
) external;
304306

307+
/// @notice Sets the list of multi-gas pricing constraints for the multi-dimensional multi-constraint pricing model.
308+
/// @notice Replaces the existing configuration and initializes each constraint’s starting backlog value.
309+
/// @notice Any previous multi-gas constraints are discarded.
310+
///
311+
/// @notice This method defines both the target throughput and relative weights
312+
/// @notice of each resource kind participating in multi-dimensional gas pricing.
313+
/// @notice Each constraint may specify multiple resources with different weight multipliers.
314+
/// @notice The final base fee is determined by the most congested resource dimension.
315+
///
316+
/// @notice Model selection:
317+
/// @notice - If one or more multi-gas constraints are provided, ArbOS switches to the multi-dimensional
318+
/// @notice pricing model and uses exactly the provided parameters.
319+
/// @notice - If zero constraints are provided, the chain reverts to the previous pricing model
320+
/// @notice (either the single-constraint or single-dimensional multi-constraint configuration).
321+
///
322+
/// @notice Available in ArbOS version 60 and above.
323+
/// @param constraints Array of `ResourceConstraint` structs, each containing:
324+
/// - `resources`: list of (resource kind, weight) pairs (see the ArbMultiGasConstraintsTypes library for definitions)
325+
/// - `adjustmentWindowSecs`: time window (seconds) over which the price rises by a factor of e if demand is 2x the target (uint64, seconds)
326+
/// - `targetPerSec`: target gas usage per second for this constraint (uint64, gas/sec)
327+
/// - `backlog`: initial backlog value for this constraint (uint64, gas units)
328+
function setMultiGasPricingConstraints(
329+
ArbMultiGasConstraintsTypes.ResourceConstraint[] calldata constraints
330+
) external;
331+
305332
/// Emitted when a successful call is made to this precompile
306333
event OwnerActs(bytes4 indexed method, address indexed owner, bytes data);
307334
}

0 commit comments

Comments
 (0)