|
| 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 | +} |
0 commit comments