Skip to main content

Contracts and testnet IDs

The network runs on two Move packages on IOTA:

PackageWhat it contains
iota_storageThe system (System: BLS committee, prices, capacity, accounting per epoch), Blob and Storage, staking (Staking, pools, committee by stake, epochs), the project treasury (treasury), events and Display. Payments and stake are in iota::iota::IOTA.
sitesSites: Site (with Display), one Resource per path, routes, redirects, metadata and events.

IOTA testnet​

ObjectID
Package iota_storage0x4d2ca05e1922584aedd9e879e6973313830b9bb786af265de6fad0df39ca55c3
System0x765f9b7d1564f0c7f68a378318bf60a1e1e60551052a22417e223f337b51241d
Staking0x60013ac4eeddbb77421073bb23a040bfe75ef5e8be2766b57c1435331efec743
Treasury0x476c2fc76c10ce66c0d12c908aae72f9473ced51a51f1d75384c61c30eb91d10
UpgradeTimelock0x8e5492406b5fb1386dfeb0cd6b74d8cad4632a7a8671a0e6f313216413af954b
PauseCap0x21b735f658855c984ceb81bab60248eb364113759f5fb3d6fd8d94c9eb95fe6b
Custody (multisig, 2 of 3)0xd8abbfc37ab9b0bd8c85334d9f7c8f859d6764728cefc91a695be2b715b3d389
Package sites0xfffd81708ef3474d7cbd5a496246b03603a27c8a747415ea1d1e2632019a3c30
  • Chain: IOTA testnet. Public RPC: https://api.testnet.iota.cafe, the shared endpoint of the IOTA networks, which is rate limited and comes with no guarantee of service: for a production application, the IOTA documentation recommends infrastructure of your own.
  • Configuration: 4 storage nodes with 25 shards each (100 shards), 1 IOTA of stake in each, 1-day epochs and at most 53 epochs per purchase.
  • Types: a stored blob is a <iota_storage>::blob::Blob and a site is a <sites>::site::Site, where <iota_storage> and <sites> are the package IDs above.

Main functions​

Storing and managing blobs (package iota_storage):

FunctionWhat it does
system::reserve_spaceBuys a Storage of a given encoded size for some epochs, paying in IOTA.
system::reserve_space_for_epochsThe same, from a given start epoch to an end epoch. The clients use it to add the missing epochs to a Storage from the wallet.
storage_resource::split_by_sizeSplits a Storage in two: the original keeps the given size and a new one gets the rest.
storage_resource::fuse_periodsJoins two Storage of the same size that cover consecutive epochs.
system::register_blobRegisters a blob ID on a Storage and creates the Blob, paying the write fee. The contract recomputes the blob ID from the Merkle root and the size.
system::certify_blobCertifies the blob with the aggregated BLS signature of a quorum of shards and the bitmap of the signers.
system::extend_blobRenews a certified, unexpired Blob for more epochs, paying in IOTA.
system::delete_blobDeletes a deletable Blob and returns its Storage.
blob::burnDestroys a Blob object.

reserve_space, reserve_space_for_epochs, register_blob and extend_blob take the payment as a &mut Coin<IOTA> and charge exactly what is due, so the client can pay storage from the gas coin in the same transaction.

Sites (package sites, module site): new_site, new_resource, add_header, add_resource, remove_resource_if_exists, create_routes, insert_route, remove_all_routes_if_exist, create_redirects, insert_redirect, take_redirects_if_exist, update_name, update_metadata and burn.

Treasury (module treasury): only the holder of its TreasuryAdminCap can withdraw; from version 8 of iota_storage, a multisig of the project (below, «Timelock and custody»). From version 8, only the contract itself deposits (at the change of epoch and when a node is slashed), withdrawing 0 aborts and a cap only works with the treasury it was created with; before, anyone could deposit. Version 8 changes the Treasury type, so it comes with a new deployment of the network, not as an upgrade.

Storage challenges (from version 6 of iota_storage): system::certify_storage takes the aggregated BLS signature of nodes holding a quorum of shards that say a node passed their storage challenges in the current epoch, and emits StorageCertified. At the change of epoch, the rewards of the nodes of the committee without a certificate go to the treasury (StorageRewardsWithheld). system::storage_certified_nodes and system::storage_challenges_first_epoch read the state. See storage challenges.

Committee allowlist (from version 5 of iota_storage): while staking is not open to third parties, only the storage nodes in staking::committee_allowlist can be selected for the committee. The project sets it with upgrade::set_committee_allowlist (and could remove it with upgrade::remove_committee_allowlist), using its emergency capability (from version 8, through its timelock: below); each change emits CommitteeAllowlistSet. Any node can still register and receive stake, but gets no shards.

Emergency exit for stake (from version 7 of iota_storage): if a change of epoch has not completed two epoch durations after it was due (the epoch has lasted three times its duration, for example because nodes holding more than a third of the shards stopped confirming it), anyone can withdraw a stake receipt (StorageStake; before version 8, StakedIota) in one step with staking::emergency_withdraw_stake, whatever its state, with its rewards up to the current epoch. It emits EmergencyStakeWithdrawn. Without it, the normal withdrawal (request_withdraw_stake, then withdraw_stake one or two epochs later) would never arrive. The committee keeps its shards, and the exit closes as soon as a change of epoch completes. From version 11 (not yet on testnet), the withdrawn stake leaves the node's pool when a requested withdrawal would: in the next change of epoch or, if the next committee has already been selected with it, in the one after, so no node of that committee is left with shards and no stake. And the rewards of a node of the committee without stake go to the treasury instead of stopping the change of epoch. staking::is_epoch_change_stalled and staking::epoch_change_due read the state.

Timelock and custody​

From version 8 of iota_storage, the project's capabilities are held by a multisig of the project (several keys, with a threshold), not by a single key: the TreasuryAdminCap, the capabilities of the sites package, the capability to pause the network's entries (pause::PauseCap) and the emergency capability (upgrade::EmergencyUpgradeCap), which goes inside a timelock (module timelock, object UpgradeTimelock):

  • Everything the emergency capability can do (an upgrade without the votes of the nodes, setting or removing the committee allowlist, burning it) and changing the delay itself is first proposed with timelock::propose. The proposal is public: it is in the UpgradeTimelock object and in an ActionProposed event, with the time from which it can be executed.
  • It can only be executed once the delay has passed (on testnet, two epochs: 48 hours, as long as withdrawing stake takes) and within the next 7 days, and only what was proposed: an upgrade, only to the package with the proposed digest. Executing it emits ActionExecuted; a withdrawn proposal, ActionCanceled. The capability only leaves the timelock by being burned.
  • The project's storage nodes vote through the same timelock. When the network is deployed, each of them hands its governance (the authority that votes for package upgrades on its behalf) over to an object kept inside the UpgradeTimelock (timelock::NodeGovernance), which only the timelock module can use. Their vote for an upgrade (timelock::vote_upgrade_action) is proposed and executed like the other actions (timelock::vote_for_upgrade); with the quorum of shards, upgrade::authorize_upgrade gives the upgrade in the same transaction. Neither the operator key that each node uses every epoch nor the multisig can vote for them outside a proposal, and handing the governance of a node over to someone else (timelock::set_node_governance_action) also waits for the delay.
  • So, if you stake or store in the network, you can see any upgrade the project can make coming, and have time to withdraw your stake or your data before it applies. Burning the emergency capability keeps the timelock, for the votes of the project's nodes; independent operators, when there are any, vote with their own governance and their votes add up.
  • The commission of the project's nodes is collected by the multisig, not by the node's StorageNodeCap.

Pause​

Since every change of the package waits for the delay of the timelock, the project's multisig can also pause the network's entries at once, while an urgent fix waits (module pause, from version 8):

  • pause::pause pauses them until the start of a later epoch (at most 97 days of epochs); pause::unpause lifts the pause, which also ends on its own at that epoch. They emit NetworkPaused (with epoch and until_epoch) and NetworkUnpaused.
  • While paused, what puts new data or IOTA into the network, or makes the nodes delete data, aborts with ENetworkPaused (system, code 4; staking, code 5): reserve_space, reserve_space_for_epochs, register_blob, certify_blob, add_subsidy, add_per_epoch_subsidies, invalidate_blob_id, delete_deny_listed_blob, register_candidate and stake_with_pool.
  • Never paused: withdrawing stake (request_withdraw_stake, withdraw_stake and the emergency exit), deleting a blob, extending a blob (also a SharedBlob, so that no blob expires because of a pause), collecting the commission, the changes of epoch, the storage challenges and the votes of the nodes. A pause stops new data and new stake for a while; it cannot take anything, delete data or keep anyone in.
  • The pause is a dynamic field of System and of Staking (system::PausedKey and staking::PausedKey, with the epoch at whose start it ends). The aggregator's /v1/status gives it as pausedUntil, the publisher answers 503 while it lasts, and the app shows a notice.

Package upgrades​

The iota_storage package can be upgraded, either with the votes of a quorum of the storage nodes (those of the project's nodes, through its timelock) or, for now, with an emergency capability held by the project (from version 8, also in its timelock). An upgrade keeps the shared objects and their IDs. What changes for an integrator:

  • Types and events keep the ID of the package that first defined them: the original package (the one above) for <iota_storage>::blob::Blob, <iota_storage>::events::BlobCertified and the rest of the first version. Types added by an upgrade, such as the events CommitteeAllowlistSet (version 5), StorageCertified and StorageRewardsWithheld (version 6) and EmergencyStakeWithdrawn (version 7), carry the ID of the package of that upgrade.
  • Calls go to the current package: the package_id field of System (the same in Staking). After an upgrade is migrated, both objects move to the new version and the previous package aborts with EWrongVersion when it touches them. From version 8, the Treasury is versioned in the same way and moves to the new version with them. The client, the storage nodes and the app read package_id and follow upgrades on their own.
  • Each migration emits ContractUpgraded with the new package ID and version.

Events​

The storage nodes follow the events of the events module: BlobRegistered, BlobCertified (also emitted by a renewal, with is_extension), BlobDeleted and InvalidBlobID, among others. The treasury emits TreasuryDeposit and TreasuryWithdrawal (from version 8, with the sender of the withdrawal; before, the same address was in a field called recipient). The timelock (from version 8) emits ActionProposed, ActionExecuted and ActionCanceled, with the kind of action and its arguments. The pause (from version 8) emits NetworkPaused and NetworkUnpaused. The votes for an upgrade emit ContractUpgradeProposed and, from the vote that reaches the quorum, ContractUpgradeQuorumReached.

Notes​

  • BLS keys. IOTA testnet and mainnet disable the uncompressed G1 functions, so the nodes' public keys are stored as Element<G1> and added with g1_add. A certificate is the aggregated signature of the signers, verified with bls12381_min_pk_verify against the sum of their keys.
  • Treasury. The treasury module receives 3 % of the rewards of each epoch, the rewards of the nodes without a storage certificate (and, from version 11, not yet on testnet, those of a node of the committee without stake) and the commission of slashed nodes.
  • IOTA Names. The sites package does not depend on IOTA Names: the portal resolves the names.

Tests​

  • iota_storage: 341/341 Move tests, 12 of them for the treasury, 11 for the migration of an upgrade, 3 for the committee allowlist, 11 for the storage challenges, 15 for the emergency exit for stake, 2 for payments before prices are set, 38 for the timelock and the governance of the project's nodes, 20 for the pause and 37 for the operator bond.
  • sites: 39/39 Move tests.
  • End-to-end tests on IOTA testnet: storing through the publisher, paying from a wallet and renewing, transferring and deleting, and publishing, serving, updating and destroying sites. On a local network, also two upgrades of iota_storage, proposed in the timelock and applied after its delay (the second one voted by the nodes), with the nodes and the client following them; the multisig signing separately; an operator key that can no longer vote; an upgrade voted with the emergency capability burned, with the votes of independent operators; the pause of the network's entries, with storing refused and deleting, extending and withdrawing stake still working; and a change of epoch stalled by two stopped nodes, with the emergency exit for stake.