From cff599d2b6671d6023eed31d9ecb3f89ce752af5 Mon Sep 17 00:00:00 2001 From: Gabriel de Quadros Ligneul Date: Fri, 1 Aug 2025 14:34:05 -0300 Subject: [PATCH 1/5] Add resource constraint methods to ArbOwner Part of NIT-3488 --- ArbOwner.sol | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/ArbOwner.sol b/ArbOwner.sol index ac6963a..9ccf20a 100644 --- a/ArbOwner.sol +++ b/ArbOwner.sol @@ -268,6 +268,23 @@ interface ArbOwner { bool enable ) external; + /// @notice Adds or updates a resource constraint + /// @notice Available on ArbOS version 50 and above + /// @param resource the resource kind (see Nitro documentation for the list of resources) + /// @param periodSecs the time window for the constraint + /// @param targetPerPeriod the target limit for the given period and resource + function setResourceConstraint( + uint8 resource, + uint32 periodSecs, + uint64 targetPerPeriod + ) external; + + /// @notice Removes a resource constraint + /// @notice Available on ArbOS version 50 and above + /// @param resource the resource kind (see Nitro documentation for the list of resources) + /// @param periodSecs the time window for the constraint + function clearConstraint(uint8 resource, uint32 periodSecs) external; + /// Emitted when a successful call is made to this precompile event OwnerActs(bytes4 indexed method, address indexed owner, bytes data); } From 8edee1557381090a201e54744fde5dc7686c4591 Mon Sep 17 00:00:00 2001 From: Mikhail Rogachev Date: Fri, 10 Oct 2025 19:46:39 +0200 Subject: [PATCH 2/5] feat: add weights to recource constraints --- ArbOwner.sol | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/ArbOwner.sol b/ArbOwner.sol index 9ccf20a..eb6ddcd 100644 --- a/ArbOwner.sol +++ b/ArbOwner.sol @@ -268,15 +268,23 @@ interface ArbOwner { bool enable ) external; + /// @notice A pair representing a resource kind and its weight in constraint calculations. + /// @param resource the resource kind (see Nitro documentation for list of resources) + /// @param weight the relative weight of this resource in the constraint + struct ResourceWeight { + uint8 resource; + uint64 weight; + } + /// @notice Adds or updates a resource constraint /// @notice Available on ArbOS version 50 and above - /// @param resource the resource kind (see Nitro documentation for the list of resources) + /// @param resources an array of (resource, weight) pairs /// @param periodSecs the time window for the constraint - /// @param targetPerPeriod the target limit for the given period and resource + /// @param targetPerSec allowed usage per second across weighted resources function setResourceConstraint( - uint8 resource, + ResourceWeight[] calldata resources, uint32 periodSecs, - uint64 targetPerPeriod + uint64 targetPerSec ) external; /// @notice Removes a resource constraint From b4e4f69a530b3a02c669e177b7e4cd0a4f9e848b Mon Sep 17 00:00:00 2001 From: Mikhail Rogachev Date: Fri, 10 Oct 2025 20:11:02 +0200 Subject: [PATCH 3/5] feat: add listResourceConstraints view and fix clearConstraint --- ArbGasInfo.sol | 9 +++++++++ ArbOwner.sol | 18 ++++++------------ ArbResourceConstraintsTypes.sol | 23 +++++++++++++++++++++++ 3 files changed, 38 insertions(+), 12 deletions(-) create mode 100644 ArbResourceConstraintsTypes.sol diff --git a/ArbGasInfo.sol b/ArbGasInfo.sol index 0261252..a56b1e9 100644 --- a/ArbGasInfo.sol +++ b/ArbGasInfo.sol @@ -4,6 +4,8 @@ pragma solidity >=0.4.21 <0.9.0; +import {ArbResourceConstraintsTypes} from "./ArbResourceConstraintsTypes.sol"; + /// @title Provides insight into the cost of using the chain. /// @notice These methods have been adjusted to account for Nitro's heavy use of calldata compression. /// Of note to end-users, we no longer make a distinction between non-zero and zero-valued calldata bytes. @@ -120,4 +122,11 @@ interface ArbGasInfo { /// @notice Returns the L1 pricing surplus as of the last update (may be negative). /// @notice Available in ArbOS version 20 and above function getLastL1PricingSurplus() external view returns (int256); + + /// @notice Lists all resource constraints currently configured in ArbOS. + /// @notice Available on ArbOS version 50 and above + function listResourceConstraints() + external + view + returns (ArbResourceConstraintsTypes.ResourceConstraint[] memory constraints); } diff --git a/ArbOwner.sol b/ArbOwner.sol index eb6ddcd..b43bf7e 100644 --- a/ArbOwner.sol +++ b/ArbOwner.sol @@ -4,6 +4,8 @@ pragma solidity >=0.4.21 <0.9.0; +import {ArbResourceConstraintsTypes} from "./ArbResourceConstraintsTypes.sol"; + /** * @title Provides owners with tools for managing the rollup. * @notice Calls by non-owners will always revert. @@ -268,30 +270,22 @@ interface ArbOwner { bool enable ) external; - /// @notice A pair representing a resource kind and its weight in constraint calculations. - /// @param resource the resource kind (see Nitro documentation for list of resources) - /// @param weight the relative weight of this resource in the constraint - struct ResourceWeight { - uint8 resource; - uint64 weight; - } - /// @notice Adds or updates a resource constraint /// @notice Available on ArbOS version 50 and above - /// @param resources an array of (resource, weight) pairs + /// @param resources an array of resource–weight pairs (see Nitro documentation for the list of resources) /// @param periodSecs the time window for the constraint /// @param targetPerSec allowed usage per second across weighted resources function setResourceConstraint( - ResourceWeight[] calldata resources, + ArbResourceConstraintsTypes.ResourceWeight[] calldata resources, uint32 periodSecs, uint64 targetPerSec ) external; /// @notice Removes a resource constraint /// @notice Available on ArbOS version 50 and above - /// @param resource the resource kind (see Nitro documentation for the list of resources) + /// @param resources the list of resource kinds to be removed (see Nitro documentation for the list of resources) /// @param periodSecs the time window for the constraint - function clearConstraint(uint8 resource, uint32 periodSecs) external; + function clearConstraint(uint8[] calldata resources, uint32 periodSecs) external; /// Emitted when a successful call is made to this precompile event OwnerActs(bytes4 indexed method, address indexed owner, bytes data); diff --git a/ArbResourceConstraintsTypes.sol b/ArbResourceConstraintsTypes.sol new file mode 100644 index 0000000..9eafa85 --- /dev/null +++ b/ArbResourceConstraintsTypes.sol @@ -0,0 +1,23 @@ +// Copyright 2025, Offchain Labs, Inc. +// For license information, see https://github.com/OffchainLabs/nitro-contracts/blob/main/LICENSE +// SPDX-License-Identifier: BUSL-1.1 + +pragma solidity >=0.4.21 <0.9.0; + +/// @title ArbResourceConstraintsTypes +/// @notice Resource constraints type definitions used by ArbOwner and ArbOwnerPublic precompiles. +library ArbResourceConstraintsTypes { + /// @notice A pair representing a resource kind and its weight in constraint calculations. + struct ResourceWeight { + uint8 resource; + uint64 weight; + } + + /// @notice A constraint describing limits for a set of weighted resources. + struct ResourceConstraint { + ResourceWeight[] resources; + uint32 periodSecs; + uint64 targetPerSec; + uint64 backlog; + } +} From 56fe65fb27ca99ac767717e0df14b2c6f572112d Mon Sep 17 00:00:00 2001 From: Mikhail Rogachev Date: Tue, 14 Oct 2025 12:05:05 +0200 Subject: [PATCH 4/5] feat: add ResourceKind enum and fix comments --- ArbOwner.sol | 9 ++++++--- ArbResourceConstraintsTypes.sol | 17 +++++++++++++++-- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/ArbOwner.sol b/ArbOwner.sol index b43bf7e..2a9c9e8 100644 --- a/ArbOwner.sol +++ b/ArbOwner.sol @@ -271,7 +271,7 @@ interface ArbOwner { ) external; /// @notice Adds or updates a resource constraint - /// @notice Available on ArbOS version 50 and above + /// @notice Available on ArbOS version 60 and above /// @param resources an array of resource–weight pairs (see Nitro documentation for the list of resources) /// @param periodSecs the time window for the constraint /// @param targetPerSec allowed usage per second across weighted resources @@ -282,10 +282,13 @@ interface ArbOwner { ) external; /// @notice Removes a resource constraint - /// @notice Available on ArbOS version 50 and above + /// @notice Available on ArbOS version 60 and above /// @param resources the list of resource kinds to be removed (see Nitro documentation for the list of resources) /// @param periodSecs the time window for the constraint - function clearConstraint(uint8[] calldata resources, uint32 periodSecs) external; + function clearConstraint( + ArbResourceConstraintsTypes.ResourceKind[] calldata resources, + uint32 periodSecs + ) external; /// Emitted when a successful call is made to this precompile event OwnerActs(bytes4 indexed method, address indexed owner, bytes data); diff --git a/ArbResourceConstraintsTypes.sol b/ArbResourceConstraintsTypes.sol index 9eafa85..aa7df8c 100644 --- a/ArbResourceConstraintsTypes.sol +++ b/ArbResourceConstraintsTypes.sol @@ -7,9 +7,23 @@ pragma solidity >=0.4.21 <0.9.0; /// @title ArbResourceConstraintsTypes /// @notice Resource constraints type definitions used by ArbOwner and ArbOwnerPublic precompiles. library ArbResourceConstraintsTypes { + /// @notice Enumerates the distinct resource kinds used for multi-dimensional gas accounting. + /// @dev The numeric values of this enum must remain consistent with the corresponding + /// @dev The values defined here must stay synchronized with `go-ethereum/arbitrum/multigas/resources.go`. + enum ResourceKind { + Unknown, + Computation, + HistoryGrowth, + StorageAccess, + StorageGrowth, + L1Calldata, + L2Calldata, + WasmComputation + } + /// @notice A pair representing a resource kind and its weight in constraint calculations. struct ResourceWeight { - uint8 resource; + ResourceKind resource; uint64 weight; } @@ -18,6 +32,5 @@ library ArbResourceConstraintsTypes { ResourceWeight[] resources; uint32 periodSecs; uint64 targetPerSec; - uint64 backlog; } } From 56cca8a7222eaefb22584d2a5e0c125fe32200c5 Mon Sep 17 00:00:00 2001 From: Mikhail Rogachev Date: Thu, 16 Oct 2025 19:28:41 +0200 Subject: [PATCH 5/5] fix: listResourceConstraints arbos version --- ArbGasInfo.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ArbGasInfo.sol b/ArbGasInfo.sol index a56b1e9..3fb9fff 100644 --- a/ArbGasInfo.sol +++ b/ArbGasInfo.sol @@ -124,7 +124,7 @@ interface ArbGasInfo { function getLastL1PricingSurplus() external view returns (int256); /// @notice Lists all resource constraints currently configured in ArbOS. - /// @notice Available on ArbOS version 50 and above + /// @notice Available on ArbOS version 60 and above function listResourceConstraints() external view