Skip to content

Commit 5f81875

Browse files
authored
feat: add arbos 30 methods (#12)
1 parent 024a8db commit 5f81875

File tree

5 files changed

+257
-1
lines changed

5 files changed

+257
-1
lines changed

ArbDebug.sol

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ interface ArbDebug {
3131
uint64 number
3232
) external pure;
3333

34+
/// @notice Available in ArbOS version 30 and above
35+
function panic() external;
36+
3437
function legacyError() external pure;
3538

3639
error Custom(uint64, string, bool);

ArbOwner.sol

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,86 @@ interface ArbOwner {
136136
uint256 maxWeiToRelease
137137
) external returns (uint256);
138138

139+
/// @notice Sets the amount of ink 1 gas buys
140+
/// @notice Available in ArbOS version 30 and above
141+
/// @param price the conversion rate (must fit in a uint24)
142+
function setInkPrice(
143+
uint32 price
144+
) external;
145+
146+
/// @notice Sets the maximum depth (in wasm words) a wasm stack may grow
147+
/// @notice Available in ArbOS version 30 and above
148+
function setWasmMaxStackDepth(
149+
uint32 depth
150+
) external;
151+
152+
/// @notice Sets the number of free wasm pages a tx gets
153+
/// @notice Available in ArbOS version 30 and above
154+
function setWasmFreePages(
155+
uint16 pages
156+
) external;
157+
158+
/// @notice Sets the base cost of each additional wasm page
159+
/// @notice Available in ArbOS version 30 and above
160+
function setWasmPageGas(
161+
uint16 gas
162+
) external;
163+
164+
/// @notice Sets the maximum number of pages a wasm may allocate
165+
/// @notice Available in ArbOS version 30 and above
166+
function setWasmPageLimit(
167+
uint16 limit
168+
) external;
169+
170+
/// @notice Sets the maximum size of the uncompressed wasm code in bytes
171+
/// @notice Available in ArbOS version 30 and above
172+
function setWasmMaxSize(
173+
uint32 size
174+
) external;
175+
176+
/// @notice Sets the minimum costs to invoke a program
177+
/// @notice Available in ArbOS version 30 and above
178+
/// @param gas amount of gas paid in increments of 256 when not the program is not cached
179+
/// @param cached amount of gas paid in increments of 64 when the program is cached
180+
function setWasmMinInitGas(uint8 gas, uint16 cached) external;
181+
182+
/// @notice Sets the linear adjustment made to program init costs.
183+
/// @notice Available in ArbOS version 30 and above
184+
/// @param percent the adjustment (100% = no adjustment).
185+
function setWasmInitCostScalar(
186+
uint64 percent
187+
) external;
188+
189+
/// @notice Sets the number of days after which programs deactivate
190+
/// @notice Available in ArbOS version 30 and above
191+
function setWasmExpiryDays(
192+
uint16 _days
193+
) external;
194+
195+
/// @notice Sets the age a program must be to perform a keepalive
196+
/// @notice Available in ArbOS version 30 and above
197+
function setWasmKeepaliveDays(
198+
uint16 _days
199+
) external;
200+
201+
/// @notice Sets the number of extra programs ArbOS caches during a given block
202+
/// @notice Available in ArbOS version 30 and above
203+
function setWasmBlockCacheSize(
204+
uint16 count
205+
) external;
206+
207+
/// @notice Adds account as a wasm cache manager
208+
/// @notice Available in ArbOS version 30 and above
209+
function addWasmCacheManager(
210+
address manager
211+
) external;
212+
213+
/// @notice Removes account from the list of wasm cache managers
214+
/// @notice Available in ArbOS version 30 and above
215+
function removeWasmCacheManager(
216+
address manager
217+
) external;
218+
139219
/// @notice Sets serialized chain config in ArbOS state
140220
/// @notice Available in ArbOS version 11 and above
141221
function setChainConfig(

ArbWasm.sol

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
// Copyright 2022-2024, Offchain Labs, Inc.
2+
// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE
3+
// SPDX-License-Identifier: BUSL-1.1
4+
5+
pragma solidity >=0.4.21 <0.9.0;
6+
7+
/**
8+
* @title Methods for managing user programs
9+
* @notice Precompiled contract that exists in every Arbitrum chain at 0x0000000000000000000000000000000000000071.
10+
* @notice Available in ArbOS version 30 and above
11+
*/
12+
interface ArbWasm {
13+
/// @notice Activate a wasm program
14+
/// @param program the program to activate
15+
/// @return version the stylus version the program was activated against
16+
/// @return dataFee the data fee paid to store the activated program
17+
function activateProgram(
18+
address program
19+
) external payable returns (uint16 version, uint256 dataFee);
20+
21+
/// @notice Gets the latest stylus version
22+
/// @return version the stylus version
23+
function stylusVersion() external view returns (uint16 version);
24+
25+
/// @notice Gets the stylus version the program with codehash was most recently activated against
26+
/// @return version the program version (reverts for EVM contracts)
27+
function codehashVersion(
28+
bytes32 codehash
29+
) external view returns (uint16 version);
30+
31+
/// @notice Extends a program's expiration date.
32+
/// Reverts if too soon or if the program is not up to date.
33+
function codehashKeepalive(
34+
bytes32 codehash
35+
) external payable;
36+
37+
/// @notice Gets a program's asm size.
38+
/// Reverts if program is not active.
39+
/// @return size the size in bytes
40+
function codehashAsmSize(
41+
bytes32 codehash
42+
) external view returns (uint32 size);
43+
44+
/// @notice Gets the stylus version the program was most recently activated against
45+
/// @return version the program version (reverts for EVM contracts)
46+
function programVersion(
47+
address program
48+
) external view returns (uint16 version);
49+
50+
/// @notice Gets the cost to invoke the program
51+
/// @return gas the amount of gas
52+
/// @return gasWhenCached the amount of gas if the program was recently used
53+
function programInitGas(
54+
address program
55+
) external view returns (uint64 gas, uint64 gasWhenCached);
56+
57+
/// @notice Gets the memory footprint of the program at the given address in pages
58+
/// @return footprint the memory footprint of program in pages (reverts for EVM contracts)
59+
function programMemoryFootprint(
60+
address program
61+
) external view returns (uint16 footprint);
62+
63+
/// @notice Gets the amount of time remaining until the program expires
64+
/// @return _secs the time left in seconds (reverts for EVM contracts)
65+
function programTimeLeft(
66+
address program
67+
) external view returns (uint64 _secs);
68+
69+
/// @notice Gets the conversion rate between gas and ink
70+
/// @return price the amount of ink 1 gas buys
71+
function inkPrice() external view returns (uint32 price);
72+
73+
/// @notice Gets the wasm stack size limit
74+
/// @return depth the maximum depth (in wasm words) a wasm stack may grow
75+
function maxStackDepth() external view returns (uint32 depth);
76+
77+
/// @notice Gets the number of free wasm pages a program gets
78+
/// @return pages the number of wasm pages (2^16 bytes)
79+
function freePages() external view returns (uint16 pages);
80+
81+
/// @notice Gets the base cost of each additional wasm page (2^16 bytes)
82+
/// @return gas base amount of gas needed to grow another wasm page
83+
function pageGas() external view returns (uint16 gas);
84+
85+
/// @notice Gets the ramp that drives exponential memory costs
86+
/// @return ramp bits representing the floating point value
87+
function pageRamp() external view returns (uint64 ramp);
88+
89+
/// @notice Gets the maximum number of pages a wasm may allocate
90+
/// @return limit the number of pages
91+
function pageLimit() external view returns (uint16 limit);
92+
93+
/// @notice Gets the minimum costs to invoke a program
94+
/// @return gas amount of gas in increments of 256 when not cached
95+
/// @return cached amount of gas in increments of 64 when cached
96+
function minInitGas() external view returns (uint64 gas, uint64 cached);
97+
98+
/// @notice Gets the linear adjustment made to program init costs.
99+
/// @return percent the adjustment (100% = no adjustment).
100+
function initCostScalar() external view returns (uint64 percent);
101+
102+
/// @notice Gets the number of days after which programs deactivate
103+
/// @return _days the number of days
104+
function expiryDays() external view returns (uint16 _days);
105+
106+
/// @notice Gets the age a program must be to perform a keepalive
107+
/// @return _days the number of days
108+
function keepaliveDays() external view returns (uint16 _days);
109+
110+
/// @notice Gets the number of extra programs ArbOS caches during a given block.
111+
/// @return count the number of same-block programs.
112+
function blockCacheSize() external view returns (uint16 count);
113+
114+
event ProgramActivated(
115+
bytes32 indexed codehash,
116+
bytes32 moduleHash,
117+
address program,
118+
uint256 dataFee,
119+
uint16 version
120+
);
121+
event ProgramLifetimeExtended(bytes32 indexed codehash, uint256 dataFee);
122+
123+
error ProgramNotWasm();
124+
error ProgramNotActivated();
125+
error ProgramNeedsUpgrade(uint16 version, uint16 stylusVersion);
126+
error ProgramExpired(uint64 ageInSeconds);
127+
error ProgramUpToDate();
128+
error ProgramKeepaliveTooSoon(uint64 ageInSeconds);
129+
error ProgramInsufficientValue(uint256 have, uint256 want);
130+
}

ArbWasmCache.sol

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Copyright 2022-2024, Offchain Labs, Inc.
2+
// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE
3+
// SPDX-License-Identifier: BUSL-1.1
4+
5+
pragma solidity >=0.4.21 <0.9.0;
6+
7+
/**
8+
* @title Methods for managing Stylus caches
9+
* @notice Precompiled contract that exists in every Arbitrum chain at 0x0000000000000000000000000000000000000072.
10+
* @notice Available in ArbOS version 30 and above
11+
*/
12+
interface ArbWasmCache {
13+
/// @notice See if the user is a cache manager.
14+
function isCacheManager(
15+
address manager
16+
) external view returns (bool);
17+
18+
/// @notice Retrieve all address managers.
19+
/// @return managers the list of managers.
20+
function allCacheManagers() external view returns (address[] memory managers);
21+
22+
/// @notice Caches all programs with the given codehash.
23+
/// @notice Reverts if the programs have expired.
24+
/// @notice Caller must be a cache manager or chain owner.
25+
/// @notice If you're looking for how to bid for position, interact with the chain's cache manager contract.
26+
/// @notice Available in ArbOS version 30.
27+
function cacheCodehash(
28+
bytes32 codehash
29+
) external;
30+
31+
/// @notice Evicts all programs with the given codehash.
32+
/// @notice Caller must be a cache manager or chain owner.
33+
function evictCodehash(
34+
bytes32 codehash
35+
) external;
36+
37+
/// @notice Gets whether a program is cached. Note that the program may be expired.
38+
function codehashIsCached(
39+
bytes32 codehash
40+
) external view returns (bool);
41+
42+
event UpdateProgramCache(address indexed manager, bytes32 indexed codehash, bool cached);
43+
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@arbitrum/nitro-precompile-interfaces",
3-
"version": "20.0.0",
3+
"version": "30.0.0",
44
"description": "Solidity interfaces for Arbitrum Nitro precompiled contracts",
55
"author": "Offchain Labs, Inc.",
66
"license": "BUSL-1.1",

0 commit comments

Comments
 (0)