IC Interface Specification
Introduction
Section titled “Introduction”Welcome to the Internet Computer! We speak of “the” Internet Computer, because although under the hood a large number of physical computers are working together in a blockchain protocol, in the end we have the appearance of a single, shared, secure and world-wide accessible computer. Developers who want to build decentralized applications (or dapps for short) that run on the Internet Computer blockchain and end-users who want to use those dapps need to know very little, if anything, about the underlying protocol. However, knowing some details about the interfaces that the Internet Computer exposes can allow interested developers and architects to take fuller advantages of the unique features that the Internet Computer provides.
Target audience
Section titled “Target audience”This document describes this external view of the Internet Computer, i.e. the low-level interfaces it provides to dapp developers and users, and what will happen when they use these interfaces.
The target audience of this document are
-
those who use these low-level interfaces (e.g. implement agents, canister developments kits, emulators, other tooling).
-
those who implement these low-level interfaces (e.g. developers of the Internet Computer implementation)
-
those who want to understand the intricacies of the Internet Computer’s behavior in great detail (e.g. to do a security analysis)
Scope of this document
Section titled “Scope of this document”If you think of the Internet Computer as a distributed engine that executes WebAssembly-based dapps, then this document describes exclusively the aspect of executing those dapps. To the extent possible, this document will not talk about consensus protocols, nodes, subnets, orthogonal persistence or governance.
This document tries to be implementation agnostic: It would apply just as well to a (hypothetical) compatible reimplementation of the Internet Computer. This implies that this document does not cover interfaces towards those running the Internet Computer (e.g. data center operators, protocol developers, governance users), as topics like node update, monitoring, logging are inherently tied to the actual implementation and its architecture.
Overview of the Internet Computer
Section titled “Overview of the Internet Computer”Dapps on the Internet Computer, or IC for short, are implemented as canister smart contracts, or canisters for short. If you want to build on the Internet Computer as a dapp developer, you first create a canister module that contains the WebAssembly code and configuration for your dapp, and deploy it using the HTTPS interface. You can create canister modules using the Motoko language and the SDK, which is more convenient. If you want to use your own tooling, however, then this document describes what a canister module looks like and how the WebAssembly code can interact with the IC.
Once your dapp is running on the Internet Computer, it is a canister smart contract, and users can interact with it. They can use the HTTPS interface to interact with the canister according to the System API.
The user can also use the HTTPS interface to issue read-only queries, which are faster, but cannot change the state of a canister.
A typical use of the Internet Computer. (This is a simplified view; some of the arrows represent multiple interaction steps or polling.)
Sections “HTTPS Interface” and “Canister interface (System API)” describe these interfaces, together with a brief description of what they do. Afterwards, you will find a more formal description of the Internet Computer that describes its abstract behavior with more rigor.
Nomenclature
Section titled “Nomenclature”To get some consistency in this document, we try to use the following terms with precision:
We avoid the term “client”, as it could be the client of the Internet Computer or the client inside the distributed network that makes up the Internet Computer. Instead, we use the term user to denote the external entity interacting with the Internet Computer, even if in most cases it will be some code (sometimes called “agent”) acting on behalf of a (human) user.
The public entry points of canisters are called methods. Methods can be declared to be either update methods (state mutation is preserved, can call update and query methods of arbitrary canisters), query methods (state mutation is discarded, no further calls can be made), or composite query methods (state mutation is discarded, can call query and composite query methods of canisters on the same subnet).
Methods can be called, from caller to callee, and will eventually incur a response which is either a reply or a reject. A method may have parameters, which are provided with concrete arguments in a method call.
External calls can be update calls, which can only call update and query methods, and query calls, which can only call query and composite query methods. Inter-canister calls issued while evaluating an update call can call update and query methods (just like update calls). Inter-canister calls issued while evaluating a query call (to a composite query method) can call query and composite query methods (just like query calls). Note that calls from a canister to itself also count as “inter-canister”. Update and query call offer a security/efficiency trade-off. Update calls are executed in replicated mode, i.e. execution takes place in parallel on multiple replicas who need to arrive at a consensus on what the result of the call is. Query calls are fast but offer less guarantees since they are executed in non-replicated mode, by a single replica.
Internally, a call or a response is transmitted as a message from a sender to a receiver. Messages do not have a response.
WebAssembly functions are exported by the WebAssembly module or provided by the System API. These are invoked and can either trap or return, possibly with a return value. A trap is caused by an irrecoverable error in the WebAssembly module (e.g., division by zero) or System API execution (e.g., running out of memory or exceeding the instruction limit for a single message execution imposed by the Internet Computer). Functions, too, have parameters and take arguments.
External users interact with the Internet Computer by issuing requests on the HTTPS interface. Requests have responses which can either be replies or rejects. Some requests cause internal messages to be created.
Canisters and users are identified by a principal, sometimes also called an id.
Pervasive concepts
Section titled “Pervasive concepts”Before going into the details of the four public interfaces described in this document (namely the agent-facing HTTPS interface, the canister-facing System API, the virtual Management canister and the System State Tree), this section introduces some concepts that transcend multiple interfaces.
Unspecified constants and limits
Section titled “Unspecified constants and limits”This specification may refer to certain constants and limits without specifying their concrete value (yet), i.e. they are implementation defined. Many are resource limits which are relevant only to specify the error-handling behavior of the IC (which, as mentioned above, is also not yet precisely described in this document). This list is not complete.
-
MAX_CYCLES_PER_MESSAGEAmount of cycles that a canister has to have before a message is attempted to be executed, which is deducted from the canister balance before message execution. See Message execution.
-
MAX_CYCLES_PER_RESPONSEAmount of cycles that the IC sets aside when a canister performs a call. This is used to pay for processing the response message, and unused cycles after the execution of the response are refunded. See Message execution.
-
MAX_CYCLES_PER_QUERYMaximum amount of cycles that can be used in total (across all calls to query and composite query methods and their callbacks) during evaluation of a query call.
-
CHUNK_STORE_SIZEMaximum number of chunks that can be stored within the chunk store of a canister.
-
MAX_CHUNKS_IN_LARGE_WASMMaximum number of chunks that can comprise a large Wasm module.
-
DEFAULT_PROVISIONAL_CYCLES_BALANCEAmount of cycles allocated to a new canister by default, if not explicitly specified. See IC method.
-
MAX_CALL_DEPTH_COMPOSITE_QUERYMaximum nesting level of calls during evaluation of a query call to a composite query method.
-
MAX_WALL_CLOCK_TIME_COMPOSITE_QUERYMaximum wall clock time spent on evaluation of a query call.
-
MAX_SNAPSHOTSMaximum number of canister snapshots per canister.
-
MAX_CALL_TIMEOUTThe maximum timeout (in seconds) for an inter-canister call.
-
MAX_ENV_VAR_NAME_LENGTHThe maximum length of an environment variable name.
-
MAX_ENV_VAR_VALUE_LENGTHThe maximum length of an environment variable value.
-
MAX_ENV_VAR_COUNTThe maximum number of environment variables allowed.
Principals
Section titled “Principals”Principals are generic identifiers for canisters, users and possibly other concepts in the future. As far as most uses of the IC are concerned they are opaque binary blobs with a length between 0 and 29 bytes, and there is intentionally no mechanism to tell canister ids and user ids apart.
There is, however, some structure to them to encode specific authentication and authorization behavior.
Special forms of Principals
Section titled “Special forms of Principals”In this section, H denotes SHA-224, · denotes blob concatenation and |p| denotes the length of p in bytes, encoded as a single byte.
There are several classes of ids:
-
Opaque ids.
These are always generated by the IC and have no structure of interest outside of it.
-
Self-authenticating ids.
These have the form
H(public_key) · 0x02(29 bytes).An external user can use these ids as the
senderof a request if they own the corresponding private key. The public key uses one of the encodings described in Signatures. -
Derived ids
These have the form
H(|registering_principal| · registering_principal · derivation_nonce) · 0x03(29 bytes).These ids are treated specially when an id needs to be registered. In such a request, whoever requests an id can provide a
derivation_nonce. By hashing that together with the principal of the caller, every principal has a space of ids that only they can register ids from.
-
Anonymous id
This has the form
0x04, and is used for the anonymous caller. It can be used in call and query requests without a signature. -
Reserved ids
These have the form of
blob · 0x7f,0 ≤ |blob| < 29.These ids can be useful for applications that want to re-use the Textual representation of principals but want to indicate explicitly that the blob does not address any canisters or a user.
When the IC creates a fresh id, it never creates a self-authenticating id, reserved id, an anonymous id or an id derived from what could be a canister or user.
Textual representation of principals
Section titled “Textual representation of principals”We specify a canonical textual format that is recommended whenever principals need to be printed or read in textual format, e.g. in log messages, transactions browser, command line tools, source code.
The textual representation of a blob b is Grouped(Base32(CRC32(b) · b)) where
-
CRC32is a four byte check sequence, calculated as defined by ISO 3309, ITU-T V.42, and elsewhere, and stored as big-endian, i.e., the most significant byte comes first and then the less significant bytes come in descending order of significance (MSB B2 B1 LSB). -
Base32is the Base32 encoding as defined in RFC 4648, with no padding character added. -
The middle dot denotes concatenation.
-
Groupedtakes an ASCII string and inserts the separator-(dash) every 5 characters. The last group may contain less than 5 characters. A separator never appears at the beginning or end.
The textual representation is conventionally printed with lower case letters, but parsed case-insensitively.
Because the maximum size of a principal is 29 bytes, the textual representation will be no longer than 63 characters (10 times 5 plus 3 characters with 10 separators in between them).
Canister lifecycle
Section titled “Canister lifecycle”Dapps on the Internet Computer are called canisters. Conceptually, they consist of the following pieces of state:
-
A canister id (a principal)
-
Their controllers (a possibly empty list of principal)
-
A cycle balance
-
A reserved cycles balance, which are cycles set aside from the main cycle balance for resource payments.
-
The canister status, which is one of
running,stoppingorstopped. -
Resource reservations
A canister can be empty (e.g. directly after creation) or non-empty. A non-empty canister also has
-
code, in the form of a canister module
-
memories (heap and stable memory)
-
globals
-
possibly further data that is specific to the implementation of the IC (e.g. queues)
Canisters are empty after creation and uninstallation, and become non-empty through code installation.
If an empty canister receives a response, that response is dropped, as if the canister trapped when processing the response. The cycles set aside for its processing and the cycles carried on the responses are added to the canister’s cycles balance.
Canister cycles
Section titled “Canister cycles”The IC relies on cycles, a utility token, to manage its resources. A canister pays for the resources it uses from its cycle balances. A cycle_balance is stored as 128-bit unsigned integers and operations on them are saturating. In particular, if cycles are added to a canister that would bring its main cycle balance beyond 2128-1, then the balance will be capped at 2128-1 and any additional cycles will be lost.
When both the main and the reserved cycles balances of a canister fall to zero, the canister is deallocated. This has the same effect as
-
uninstalling the canister (as described in IC method)
-
setting all resource reservations to zero
Afterwards the canister is empty. It can be reinstalled after topping up its main balance.
Canister status
Section titled “Canister status”The canister status can be used to control whether the canister is processing calls:
-
In status
running, calls to the canister are processed as normal. -
In status
stopping, calls to the canister are rejected by the IC with reject codeCANISTER_ERROR(5), but responses to the canister are processed as normal. -
In status
stopped, calls to the canister are rejected by the IC with reject codeCANISTER_ERROR(5), and there are no outstanding responses.
In all cases, calls to the management canister are processed, regardless of the state of the managed canister.
The controllers of the canister or subnet admins can initiate transitions between these states using stop_canister and start_canister, and query the state using canister_status (NB: this call returns additional information, such as the cycle balance of the canister). The canister itself can also query its state using ic0.canister_status.
Signatures
Section titled “Signatures”Digital signature schemes are used for authenticating messages in various parts of the IC infrastructure. Signatures are domain separated, which means that every message is prefixed with a byte string that is unique to the purpose of the signature.
The IC supports multiple signature schemes, with details given in the following subsections. For each scheme, we specify the data encoded in the public key (which is always DER-encoded, and indicates the scheme to use) as well as the form of the signatures (which are opaque blobs for the purposes of the rest of this specification).
In all cases, the signed payload is the concatenation of the domain separator and the message. All uses of signatures in this specification indicate a domain separator, to uniquely identify the purpose of the signature. The domain separators are prefix-free by construction, as their first byte indicates their length.
Ed25519 and ECDSA signatures
Section titled “Ed25519 and ECDSA signatures”Plain signatures are supported for the schemes
-
Ed25519 or
-
ECDSA on curve P-256 (also known as
secp256r1), using SHA-256 as hash function, as well as on the Koblitz curvesecp256k1. -
Public keys must be valid for signature schemes Ed25519 or ECDSA and are encoded as DER.
-
See RFC 8410 for DER encoding of Ed25519 public keys.
-
See RFC 5480 for DER encoding of ECDSA public keys; the DER encoding must not specify a hash function. For curve
secp256k1, the OID 1.3.132.0.10 is used. The points must be specified in uncompressed form (i.e.0x04followed by the big-endian 32-byte encodings ofxandy).
-
-
The signatures are encoded as the concatenation of the 32-byte big endian encodings of the two values r and s.
Web Authentication
Section titled “Web Authentication”The allowed signature schemes for web authentication are
-
ECDSA on curve P-256 (also known as
secp256r1), using SHA-256 as hash function. -
RSA PKCS#1v1.5 (RSASSA-PKCS1-v1_5), using SHA-256 as hash function.
The signature is calculated by using the payload as the challenge in the web authentication assertion.
The signature is checked by verifying that the challenge field contains the base64url encoding of the payload, and that signature verifies on authenticatorData · SHA-256(utf8(clientDataJSON)), as specified in the WebAuthn w3c recommendation.
-
The public key is encoded as a DER-wrapped COSE key.
It uses the
SubjectPublicKeyInfotype used for other types of public keys (see, e.g., RFC 8410, Section 4), with OID 1.3.6.1.4.1.56387.1.1 (iso.org.dod.internet.private.enterprise.dfinity.mechanisms.der-wrapped-cose). TheBIT STRINGfieldsubjectPublicKeycontains the COSE encoding. See WebAuthn w3c recommendation or RFC 8152 for details on the COSE encoding.
-
The signature is a CBOR (see CBOR) value consisting of a data item with major type 6 (“Semantic tag”) and tag value
55799, followed by a map with three mandatory fields:-
authenticator_data(blob): WebAuthn authenticator data. -
client_data_json(text): WebAuthn client data in JSON representation. -
signature(blob): Signature as specified in the WebAuthn w3c recommendation, which means DER encoding in the case of an ECDSA signature.
-
Canister signatures
Section titled “Canister signatures”The IC also supports a scheme where a canister can sign a payload by declaring a special “certified variable”.
This section makes forward references to other concepts in this document, in particular the section Certification.
-
The public key is a DER-wrapped structure that indicates the signing canister, and includes a freely choosable seed. Each choice of seed yields a distinct public key for the canister, and the canister can choose to encode information, such as a user id, in the seed.
More concretely, it uses the
SubjectPublicKeyInfotype used for other types of public keys (see, e.g., RFC 8410, Section 4), with OID 1.3.6.1.4.1.56387.1.2 (iso.org.dod.internet.private.enterprise.dfinity.mechanisms.canister-signature).The
BIT STRINGfieldsubjectPublicKeyis the blob|signing_canister_id| · signing_canister_id · seed, where|signing_canister_id|is the one-byte encoding of the the length of thesigning_canister_idand·denotes blob concatenation. -
The signature is a CBOR (see CBOR) value consisting of a data item with major type 6 (“Semantic tag”) and tag value
55799, followed by a map with two mandatory fields:-
certificate(blob): A CBOR-encoded certificate as per Encoding of certificates. -
tree(hash-tree): A hash tree as per Encoding of certificates.
-
-
Given a payload together with public key and signature in the format described above the signature can be verified by checking the following two conditions:
- The
certificatemust be a valid certificate as described in Certification, withlookup_path(["canister", <signing_canister_id>, "certified_data"], certificate.tree) = Found (reconstruct(tree))
where
signing_canister_idis the id of the signing canister andreconstructis a function that computes a root-hash for the tree.-
If the
certificateincludes a subnet delegation, then thesigning_canister_idmust be included in the delegation’s canister id range (see Delegation), and the subnet type (obtained by looking up the path/subnet/<subnet_id>/typein the delegation’s certificate) must be present and it must not becloud_engine. -
The
treemust be awell_formedtree withlookup_path(["sig", <s>, <m>], tree) = Found ""
where
sis the SHA-256 hash of theseedused in the public key andmis the SHA-256 hash of the payload. - The
Supplementary Technologies
Section titled “Supplementary Technologies”Concise Binary Object Representation (CBOR) is a data format with a small code footprint, small message size and an extensible interface. CBOR is used extensively throughout the Internet Computer as the primary format for data exchange between components within the system.
cbor.io and wikipedia.org contain a lot of helpful background information and relevant tools. cbor.me in particular, is very helpful for converting between CBOR hex and diagnostic information.
For example, the following CBOR hex:
82 61 61 a1 61 62 61 63Can be converted into the following CBOR diagnostic format:
["a", {"b": "c"}]Particular concepts to note from the spec are:
The Concise Data Definition Language (CDDL) is a data description language for CBOR. It is used at various points throughout this document to describe how certain data structures are encoded with CBOR.
The system state tree
Section titled “The system state tree”Parts of the IC state are publicly exposed (e.g. via Request: Read state or Certified data) in a verified way (see Certification for the machinery for certifying). This section describes the content of this system state abstractly.
Conceptually, the system state is a tree with labeled children, and values in the leaves. Equivalently, the system state is a mapping from paths (sequences of labels) to values, where the domain is prefix-free.
Labels are always blobs (but often with a human readable representation). In this document, paths are written suggestively with slashes as separators; the actual encoding is not actually using slashes as delimiters, and labels may contain the 0x2F byte (ASCII /) just fine. Values are either natural numbers, text values or blob values.
This section specifies the publicly relevant paths in the tree.
-
/time(natural):All partial state trees include a timestamp, expressed in nanoseconds since 1970-01-01, indicating the time at which the state is current.
Api boundary nodes information
Section titled “Api boundary nodes information”The state tree contains information about all API boundary nodes (the source of truth for these API boundary node records is stored in the NNS registry canister).
-
/api_boundary_nodes/<node_id>/domain(text)Domain name associated with a node. All domains are unique across nodes. Example:
api-bn1.example.com. -
/api_boundary_nodes/<node_id>/ipv4_address(text)Public IPv4 address of a node in the dotted-decimal notation. If no
ipv4_addressis available for the corresponding node, then this path does not exist.
Example:192.168.10.150. -
/api_boundary_nodes/<node_id>/ipv6_address(text)Public IPv6 address of a node in the hexadecimal notation with colons. Example:
3002:0bd6:0000:0000:0000:ee00:0033:6778.
Subnet information
Section titled “Subnet information”The state tree contains information about the topology of the Internet Computer.
-
/subnet/<subnet_id>/public_key(blob)The public key of the subnet (a DER-encoded BLS key, see Certification)
-
/subnet/<subnet_id>/type(text)The subnet type of the subnet. Possible values are “application”, “system”, “verified_application”, and “cloud_engine” (without quotes).
-
/subnet/<subnet_id>/canister_ranges(blob)The set of canister ids assigned to this subnet, represented as a list of closed intervals of canister ids, ordered lexicographically, and encoded as CBOR (see CBOR) according to this CDDL (see CDDL):
canister_ranges = tagged<[*canister_range]>canister_range = [principal principal]principal = bytes .size (0..29)tagged<t> = #6.55799(t) ; the CBOR tag -
/subnet/<subnet_id>/metrics(blob)A collection of subnet-wide metrics related to this subnet’s current resource usage and/or performance. The metrics are a CBOR map with the following fields:
num_canisters(nat): The number of canisters on this subnet.canister_state_bytes(nat): The total size of the state in bytes taken by canisters on this subnet since this subnet was created.consumed_cycles_total(map): The total number of cycles consumed by all current and deleted canisters on this subnet. It’s a map of two values, a low part of typenatand a high part of typeopt nat.update_transactions_total(nat): The total number of transactions processed on this subnet since this subnet was created.
-
/subnet/<subnet_id>/node/<node_id>/public_key(blob)The public key of a node (a DER-encoded Ed25519 signing key, see RFC 8410 for reference) with principal
<node_id>belonging to the subnet with principal<subnet_id>.
Canister ranges
Section titled “Canister ranges”The state tree also stores the canister ID ranges of subnets on the Internet Computer in a sharded form.
-
/canister_ranges/<subnet_id>/<canister_id>(blob)The set of canister IDs assigned to this subnet is represented as a list of closed intervals of canister IDs, ordered lexicographically.
This list is then split into non-overlapping shards, with each shard stored under a path of the above form and encoded as CBOR (see CBOR).Specifically:
- Each shard contains a non-empty list of ranges.
- The first range in the shard starts with the
<canister_id>in its path. - The next shard (if any) begins with a strictly greater starting canister ID.
- All shards together cover the entire set of canister ID ranges for the subnet without overlap.
Example: Suppose a subnet has these canister ID ranges:
[1, 3], [5, 8], [10, 12], [20, 25]They could be split into two shards:
/canister_ranges/<subnet_id>/1→[1, 3], [5, 8]/canister_ranges/<subnet_id>/10→[10, 12], [20, 25]
Each shard is represented as a CBOR-encoded list of ranges.
The encoding follows the same CDDL (see CDDL) as for subnet-level canister ranges:canister_ranges = tagged<[*canister_range]> ; unlike before, this now represents a single shardcanister_range = [principal principal]principal = bytes .size (0..29)tagged<t> = #6.55799(t) ; the CBOR tagDifference from
/subnet/<subnet_id>/canister_ranges:/subnet/<subnet_id>/canister_rangesstores the complete set of ranges in one blob./canister_ranges/<subnet_id>/<canister_id>stores the same ranges split into consecutive shards, each identified by its starting<canister_id>in the path. This facilitates e.g., binary searching.
Request status
Section titled “Request status”For each update call request known to the Internet Computer, its status is in a subtree at /request_status/<request_id>. Please see Overview of canister calling for more details on how update call requests work.
-
/request_status/<request_id>/status(text)One of
received,processing,replied,rejectedordone, see Overview of canister calling for more details on what each status means. -
/request_status/<request_id>/reply(blob)If the status is
replied, then this path contains the reply blob, else it is not present. -
/request_status/<request_id>/reject_code(natural)If the status is
rejected, then this path contains the reject code (see Reject codes), else it is not present. -
/request_status/<request_id>/reject_message(text)If the status is
rejected, then this path contains a textual diagnostic message, else it is not present. -
/request_status/<request_id>/error_code(text)If the status is
rejected, then this path might be present and contain an implementation-specific error code (see Error codes), else it is not present.
Certified data
Section titled “Certified data”-
/canister/<canister_id>/certified_data(blob):The certified data of the canister with the given id, see Certified data.
Canister information
Section titled “Canister information”Users have the ability to learn about the hash of the canister’s module, its current controllers, and metadata in a certified way.
-
/canister/<canister_id>/module_hash(blob):If the canister is empty, this path does not exist. If the canister is not empty, it exists and contains the SHA256 hash of the currently installed canister module. Cf. IC method.
-
/canister/<canister_id>/controllers(blob):The current controllers of the canister. The value consists of a CBOR (see CBOR) data item with major type 6 (“Semantic tag”) and tag value
55799, followed by an array of principals in their binary form (CDDL#6.55799([* bytes .size (0..29)]), see CDDL). -
/canister/<canister_id>/metadata/<name>(blob):If the canister has a custom section called
icp:public <name>oricp:private <name>, this path contains the content of the custom section. Otherwise, this path does not exist.It is recommended for the canister to have a custom section called “icp:public candid:service”, which contains the UTF-8 encoding of the Candid interface for the canister.