From 76971dcecd4ce7811f668331ab5927e88b569e65 Mon Sep 17 00:00:00 2001 From: Michael Weigelt Date: Mon, 27 Jan 2025 15:28:17 +0000 Subject: [PATCH 01/24] cost api --- docs/references/ic-interface-spec.md | 54 ++++++++++++++++++++++++++-- 1 file changed, 52 insertions(+), 2 deletions(-) diff --git a/docs/references/ic-interface-spec.md b/docs/references/ic-interface-spec.md index b011081f80..b30020d1d0 100644 --- a/docs/references/ic-interface-spec.md +++ b/docs/references/ic-interface-spec.md @@ -1487,8 +1487,16 @@ defaulting to `I = i32` if the canister declares no memory. ic0.time : () -> (timestamp : i64); // * ic0.global_timer_set : (timestamp : i64) -> i64; // I G U Ry Rt C T ic0.performance_counter : (counter_type : i32) -> (counter : i64); // * s - ic0.is_controller: (src : I, size : I) -> ( result: i32); // * s - ic0.in_replicated_execution: () -> (result: i32); // * s + ic0.is_controller : (src : I, size : I) -> ( result : i32); // * s + ic0.in_replicated_execution : () -> (result : i32); // * s + + ic0.cost_call : (method_name_size: i64, payload_size : i64, dst : I) -> (); // * s + ic0.cost_create_canister : (dst : I) -> (); // * s + ic0.cost_http_request(request_size : i64, max_res_bytes : i64, dst : I) -> (); // * s + ic0.cost_ecdsa(src : I, size : I, dst : I) -> (); // * s + ic0.cost_schnorr(src : I, size : I, dst : I) -> (); // * s + ic0.cost_vetkey(src : I, size : I, dst : I) -> (); // * s + ic0.replication_factor : (src : I, size : I) -> i32; // * s ic0.debug_print : (src : I, size : I) -> (); // * s ic0.trap : (src : I, size : I) -> (); // * s @@ -2027,6 +2035,48 @@ When executing a query or composite query method via a query call (i.e. in non-r This traps if `ic0.data_certificate_present()` returns `0`. +### Cycle cost calculation + +Inter-canister calls have an implicit cost, and some calls to the management canister require the caller to attach cycles to the call explicitly. +The various cost factors may change over time, so the following system calls serve to give the canister programmatic, up-to-date information about the costs. + +These system calls return costs in Cycles, represented by 128 bits, which will be written to the caller-specified `dst` pointer. + +- `ic0.cost_call : (method_name_size: i64, payload_size : i64, dst : I) -> () `I ∈ {i32, i64}` + + The cost of an inter-canister call. `method_name_size` is the byte length of the method name, and `payload_size` is the length of the encoded argument to the method. + +- `ic0.cost_create_canister : (dst : I) -> (); `I ∈ {i32, i64}` + + The cost of creating a canister on the same subnet as the calling canister via [`create_canister`](#ic-create_canister). Note that canister creation via a call to the CMC can have a different cost if the target subnet has a different replication factor. In order to facilitate conversions, see `ic0.replication_factor`. + +- `ic0.cost_http_request(request_size : i64, max_res_bytes : i64, dst : I) -> (); `I ∈ {i32, i64}` + + The cost of a request via [`http_request`](#ic-http_request). `request_size` is the sum of the byte lengths of the following components of an http request: + - url + - method + - headers - i.e., the sum of the lengths of all keys and values + - body + - transform - i.e., the sum of the transform method name length and the length of the transform context + + `max_res_bytes` is the maximum response length the caller wishes to accept. + +- `ic0.cost_ecdsa(src : I, size : I, dst : I) -> (); `I ∈ {i32, i64}` + +- `ic0.cost_schnorr(src : I, size : I, dst : I) -> (); `I ∈ {i32, i64}` + +- `ic0.cost_vetkey(src : I, size : I, dst : I) -> (); `I ∈ {i32, i64}` + + These system calls accept a key name via `src` + `size` for the specific signing scheme / key. See [`sign_with_ecdsa`](#ic-sign_with_ecdsa), [`sign_with_schnorr`](#ic-sign_with_schnorr) and [`vetkd_encrypted_key`](#ic-vetkd_encrypted_key) for more information. + + These system calls trap if `src` + `size` do not decode to a valid key name. + +- `ic0.replication_factor : (src : I, size : I) -> i32; `I ∈ {i32, i64}` + + Returns the replication factor (subnet size) of the subnet identified by the `Principal` at `src` + `size`. + + This system call traps if `src` + `size` do not decode to a valid `Principal` or the given `Principal` is not a subnet. + ### Debugging aids In a local canister execution environment, the canister needs a way to emit textual trace messages. On the "real" network, these do not do anything. From d7ccf8276c2ab468052640c2cff183a76faf9ca5 Mon Sep 17 00:00:00 2001 From: Michael Weigelt Date: Mon, 27 Jan 2025 15:40:34 +0000 Subject: [PATCH 02/24] title link --- docs/references/ic-interface-spec.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/references/ic-interface-spec.md b/docs/references/ic-interface-spec.md index b30020d1d0..a44be1af21 100644 --- a/docs/references/ic-interface-spec.md +++ b/docs/references/ic-interface-spec.md @@ -2035,7 +2035,7 @@ When executing a query or composite query method via a query call (i.e. in non-r This traps if `ic0.data_certificate_present()` returns `0`. -### Cycle cost calculation +### Cycle cost calculation {#system-api-cycle-cost} Inter-canister calls have an implicit cost, and some calls to the management canister require the caller to attach cycles to the call explicitly. The various cost factors may change over time, so the following system calls serve to give the canister programmatic, up-to-date information about the costs. From dd4dd3d2dcfc4d6e5834f7e9edbe0256392a1ae3 Mon Sep 17 00:00:00 2001 From: michael-weigelt <122277901+michael-weigelt@users.noreply.github.com> Date: Tue, 28 Jan 2025 21:12:51 +0100 Subject: [PATCH 03/24] Update docs/references/ic-interface-spec.md Co-authored-by: mraszyk <31483726+mraszyk@users.noreply.github.com> --- docs/references/ic-interface-spec.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/references/ic-interface-spec.md b/docs/references/ic-interface-spec.md index a44be1af21..04d5e3a4d7 100644 --- a/docs/references/ic-interface-spec.md +++ b/docs/references/ic-interface-spec.md @@ -2038,7 +2038,7 @@ When executing a query or composite query method via a query call (i.e. in non-r ### Cycle cost calculation {#system-api-cycle-cost} Inter-canister calls have an implicit cost, and some calls to the management canister require the caller to attach cycles to the call explicitly. -The various cost factors may change over time, so the following system calls serve to give the canister programmatic, up-to-date information about the costs. +The various cost factors may change over time, so the following system calls give the canister programmatic, up-to-date information about the costs. These system calls return costs in Cycles, represented by 128 bits, which will be written to the caller-specified `dst` pointer. From 75356a73db3d550661bb6bd647e8b4db91317d39 Mon Sep 17 00:00:00 2001 From: michael-weigelt <122277901+michael-weigelt@users.noreply.github.com> Date: Tue, 28 Jan 2025 21:13:11 +0100 Subject: [PATCH 04/24] Update docs/references/ic-interface-spec.md Co-authored-by: mraszyk <31483726+mraszyk@users.noreply.github.com> --- docs/references/ic-interface-spec.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/references/ic-interface-spec.md b/docs/references/ic-interface-spec.md index 04d5e3a4d7..0bbb94a0dd 100644 --- a/docs/references/ic-interface-spec.md +++ b/docs/references/ic-interface-spec.md @@ -2040,7 +2040,7 @@ When executing a query or composite query method via a query call (i.e. in non-r Inter-canister calls have an implicit cost, and some calls to the management canister require the caller to attach cycles to the call explicitly. The various cost factors may change over time, so the following system calls give the canister programmatic, up-to-date information about the costs. -These system calls return costs in Cycles, represented by 128 bits, which will be written to the caller-specified `dst` pointer. +These system calls return costs in Cycles, represented by 128 bits, which will be written to the heap memory starting at offset `dst`. - `ic0.cost_call : (method_name_size: i64, payload_size : i64, dst : I) -> () `I ∈ {i32, i64}` From a58f10c0af1267b3b9444d9aaec0749f2aa6306e Mon Sep 17 00:00:00 2001 From: michael-weigelt <122277901+michael-weigelt@users.noreply.github.com> Date: Tue, 28 Jan 2025 21:13:36 +0100 Subject: [PATCH 05/24] Update docs/references/ic-interface-spec.md Co-authored-by: mraszyk <31483726+mraszyk@users.noreply.github.com> --- docs/references/ic-interface-spec.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/references/ic-interface-spec.md b/docs/references/ic-interface-spec.md index 0bbb94a0dd..2ce4b851f1 100644 --- a/docs/references/ic-interface-spec.md +++ b/docs/references/ic-interface-spec.md @@ -2042,7 +2042,7 @@ The various cost factors may change over time, so the following system calls giv These system calls return costs in Cycles, represented by 128 bits, which will be written to the heap memory starting at offset `dst`. -- `ic0.cost_call : (method_name_size: i64, payload_size : i64, dst : I) -> () `I ∈ {i32, i64}` +- `ic0.cost_call : (method_name_size: i64, payload_size : i64, dst : I) -> ()`; `I ∈ {i32, i64}` The cost of an inter-canister call. `method_name_size` is the byte length of the method name, and `payload_size` is the length of the encoded argument to the method. From 1dda5a1fd8a47e7bf50d7304ed395a41e9dbf1f2 Mon Sep 17 00:00:00 2001 From: michael-weigelt <122277901+michael-weigelt@users.noreply.github.com> Date: Tue, 28 Jan 2025 21:14:16 +0100 Subject: [PATCH 06/24] Update docs/references/ic-interface-spec.md Co-authored-by: mraszyk <31483726+mraszyk@users.noreply.github.com> --- docs/references/ic-interface-spec.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/references/ic-interface-spec.md b/docs/references/ic-interface-spec.md index 2ce4b851f1..3268eb5341 100644 --- a/docs/references/ic-interface-spec.md +++ b/docs/references/ic-interface-spec.md @@ -2052,7 +2052,7 @@ These system calls return costs in Cycles, represented by 128 bits, which will b - `ic0.cost_http_request(request_size : i64, max_res_bytes : i64, dst : I) -> (); `I ∈ {i32, i64}` - The cost of a request via [`http_request`](#ic-http_request). `request_size` is the sum of the byte lengths of the following components of an http request: + The cost of a canister http outcall via [`http_request`](#ic-http_request). `request_size` is the sum of the byte lengths of the following components of an http request: - url - method - headers - i.e., the sum of the lengths of all keys and values From 4bc2bbbb0bf74e36905ab1b7509470fd5516d684 Mon Sep 17 00:00:00 2001 From: michael-weigelt <122277901+michael-weigelt@users.noreply.github.com> Date: Tue, 28 Jan 2025 21:37:04 +0100 Subject: [PATCH 07/24] Update docs/references/ic-interface-spec.md Co-authored-by: mraszyk <31483726+mraszyk@users.noreply.github.com> --- docs/references/ic-interface-spec.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/references/ic-interface-spec.md b/docs/references/ic-interface-spec.md index 3268eb5341..dcdd26f188 100644 --- a/docs/references/ic-interface-spec.md +++ b/docs/references/ic-interface-spec.md @@ -2044,7 +2044,7 @@ These system calls return costs in Cycles, represented by 128 bits, which will b - `ic0.cost_call : (method_name_size: i64, payload_size : i64, dst : I) -> ()`; `I ∈ {i32, i64}` - The cost of an inter-canister call. `method_name_size` is the byte length of the method name, and `payload_size` is the length of the encoded argument to the method. + The cost of an inter-canister call. `method_name_size` is the byte length of the method name, and `payload_size` is the byte length of the argument to the method. - `ic0.cost_create_canister : (dst : I) -> (); `I ∈ {i32, i64}` From d30ff7f573fc1b040af7a81cc8565469ebac81ee Mon Sep 17 00:00:00 2001 From: michael-weigelt <122277901+michael-weigelt@users.noreply.github.com> Date: Tue, 28 Jan 2025 21:37:52 +0100 Subject: [PATCH 08/24] Update docs/references/ic-interface-spec.md Co-authored-by: mraszyk <31483726+mraszyk@users.noreply.github.com> --- docs/references/ic-interface-spec.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/references/ic-interface-spec.md b/docs/references/ic-interface-spec.md index dcdd26f188..1fdeec1d79 100644 --- a/docs/references/ic-interface-spec.md +++ b/docs/references/ic-interface-spec.md @@ -2067,7 +2067,7 @@ These system calls return costs in Cycles, represented by 128 bits, which will b - `ic0.cost_vetkey(src : I, size : I, dst : I) -> (); `I ∈ {i32, i64}` - These system calls accept a key name via `src` + `size` for the specific signing scheme / key. See [`sign_with_ecdsa`](#ic-sign_with_ecdsa), [`sign_with_schnorr`](#ic-sign_with_schnorr) and [`vetkd_encrypted_key`](#ic-vetkd_encrypted_key) for more information. + These system calls accept a key name via a textual representation for the specific signing scheme / key of a given size stored in the heap memory starting at offset `src` . See [`sign_with_ecdsa`](#ic-sign_with_ecdsa), [`sign_with_schnorr`](#ic-sign_with_schnorr) and [`vetkd_encrypted_key`](#ic-vetkd_encrypted_key) for more information. These system calls trap if `src` + `size` do not decode to a valid key name. From 46f09cd3c518b32ed6d3708c2900939b99dacb52 Mon Sep 17 00:00:00 2001 From: Michael Weigelt Date: Wed, 29 Jan 2025 07:58:59 +0000 Subject: [PATCH 09/24] suggestions --- docs/references/ic-interface-spec.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/references/ic-interface-spec.md b/docs/references/ic-interface-spec.md index 1fdeec1d79..3c757dd425 100644 --- a/docs/references/ic-interface-spec.md +++ b/docs/references/ic-interface-spec.md @@ -2048,7 +2048,7 @@ These system calls return costs in Cycles, represented by 128 bits, which will b - `ic0.cost_create_canister : (dst : I) -> (); `I ∈ {i32, i64}` - The cost of creating a canister on the same subnet as the calling canister via [`create_canister`](#ic-create_canister). Note that canister creation via a call to the CMC can have a different cost if the target subnet has a different replication factor. In order to facilitate conversions, see `ic0.replication_factor`. + The cost of creating a canister on the same subnet as the calling canister via [`create_canister`](#ic-create_canister). Note that canister creation via a call to the CMC can have a different cost if the target subnet has a different replication factor. In order to facilitate conversions, see `ic0.replication_factor`. When converting costs using ratios of subnet sizes, be mindful of rounding issues and consider adding a safety margin. - `ic0.cost_http_request(request_size : i64, max_res_bytes : i64, dst : I) -> (); `I ∈ {i32, i64}` @@ -2059,7 +2059,7 @@ These system calls return costs in Cycles, represented by 128 bits, which will b - body - transform - i.e., the sum of the transform method name length and the length of the transform context - `max_res_bytes` is the maximum response length the caller wishes to accept. + `max_res_bytes` is the maximum response length the caller wishes to accept. Note that this argument is not optional like in the call to the management canister. The cost depends on `max_res_bytes`, so the caller must provide it explicitly. See the [`http_request`](#ic-http_request) call to the management canister API to learn about the current default and maximum values. - `ic0.cost_ecdsa(src : I, size : I, dst : I) -> (); `I ∈ {i32, i64}` @@ -2069,13 +2069,13 @@ These system calls return costs in Cycles, represented by 128 bits, which will b These system calls accept a key name via a textual representation for the specific signing scheme / key of a given size stored in the heap memory starting at offset `src` . See [`sign_with_ecdsa`](#ic-sign_with_ecdsa), [`sign_with_schnorr`](#ic-sign_with_schnorr) and [`vetkd_encrypted_key`](#ic-vetkd_encrypted_key) for more information. - These system calls trap if `src` + `size` do not decode to a valid key name. + These system calls trap if the string represented by `src` + `size` does not correspond to a valid key name, such as `dfx_test_key`, `test_key_1` or `key_1`. - `ic0.replication_factor : (src : I, size : I) -> i32; `I ∈ {i32, i64}` Returns the replication factor (subnet size) of the subnet identified by the `Principal` at `src` + `size`. - This system call traps if `src` + `size` do not decode to a valid `Principal` or the given `Principal` is not a subnet. + This system call traps if `src` + `size` do not represent a valid `Principal` or the given `Principal` is not a subnet. ### Debugging aids From c14e718f4bf3c6dcd4aeb7648449db8f3f21767b Mon Sep 17 00:00:00 2001 From: Michael Weigelt Date: Wed, 29 Jan 2025 08:46:06 +0000 Subject: [PATCH 10/24] semantics --- docs/references/ic-interface-spec.md | 46 ++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/docs/references/ic-interface-spec.md b/docs/references/ic-interface-spec.md index 3c757dd425..369590e39a 100644 --- a/docs/references/ic-interface-spec.md +++ b/docs/references/ic-interface-spec.md @@ -7515,6 +7515,52 @@ ic0.in_replicated_execution() : i32 = then return 1 else return 0 +I ∈ {i32, i64} +ic0.cost_call(method_name_size: i64, payload_size: i64, dst: I) : () = + copy_cycles_to_canister(dst, arbitrary()) + +I ∈ {i32, i64} +ic0.cost_create_canister(dst: I) : () = + copy_cycles_to_canister(dst, arbitrary()) + +I ∈ {i32, i64} +ic0.cost_cost_http_request(request_size: i64, max_res_bytes: i64, dst: I) : () = + copy_cycles_to_canister(dst, arbitrary()) + +I ∈ {i32, i64} +ic0.cost_ecdsa(src: I, size: I, dst: I) : () = + principal_bytes = copy_from_canister(src, size) + if not principal_bytes encode a principal then + Trap {cycles_used = es.cycles_used;} + if principal_bytes ∉ es.subnets then + Trap {cycles_used = es.cycles_used;} + copy_cycles_to_canister(dst, arbitrary()) + +I ∈ {i32, i64} +ic0.cost_schnorr(src: I, size: I, dst: I) : () = + principal_bytes = copy_from_canister(src, size) + if not principal_bytes encode a principal then + Trap {cycles_used = es.cycles_used;} + if principal_bytes ∉ es.subnets then + Trap {cycles_used = es.cycles_used;} + copy_cycles_to_canister(dst, arbitrary()) + +I ∈ {i32, i64} +ic0.cost_vetkey(src: I, size: I, dst: I) : () = + principal_bytes = copy_from_canister(src, size) + if not principal_bytes encode a principal then + Trap {cycles_used = es.cycles_used;} + if principal_bytes ∉ es.subnets then + Trap {cycles_used = es.cycles_used;} + copy_cycles_to_canister(dst, arbitrary()) + +I ∈ {i32, i64} +ic0.replication_factor(src: I, size: I, dst: I) : i32 = + principal_bytes = copy_from_canister(src, size) + if not principal_bytes encode a principal then + Trap {cycles_used = es.cycles_used;} + return S.canister_subnet[principal_bytes].subnet_size + I ∈ {i32, i64} ic0.debug_print(src : I, size : I) = return From 364a80f00e3855720366cdc1f03856b9da0ac996 Mon Sep 17 00:00:00 2001 From: Michael Weigelt Date: Wed, 29 Jan 2025 08:48:09 +0000 Subject: [PATCH 11/24] typo --- docs/references/ic-interface-spec.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/references/ic-interface-spec.md b/docs/references/ic-interface-spec.md index 369590e39a..09a1cfc201 100644 --- a/docs/references/ic-interface-spec.md +++ b/docs/references/ic-interface-spec.md @@ -7555,7 +7555,7 @@ ic0.cost_vetkey(src: I, size: I, dst: I) : () = copy_cycles_to_canister(dst, arbitrary()) I ∈ {i32, i64} -ic0.replication_factor(src: I, size: I, dst: I) : i32 = +ic0.replication_factor(src: I, size: I) : i32 = principal_bytes = copy_from_canister(src, size) if not principal_bytes encode a principal then Trap {cycles_used = es.cycles_used;} From 1a9c592e88fa2fb5bdc4f24c5a0366cc3ba72f2e Mon Sep 17 00:00:00 2001 From: Michael Weigelt Date: Wed, 29 Jan 2025 08:49:34 +0000 Subject: [PATCH 12/24] semantics fix --- docs/references/ic-interface-spec.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/references/ic-interface-spec.md b/docs/references/ic-interface-spec.md index 09a1cfc201..3e3e32d7fc 100644 --- a/docs/references/ic-interface-spec.md +++ b/docs/references/ic-interface-spec.md @@ -7559,6 +7559,8 @@ ic0.replication_factor(src: I, size: I) : i32 = principal_bytes = copy_from_canister(src, size) if not principal_bytes encode a principal then Trap {cycles_used = es.cycles_used;} + if principal_bytes ∉ es.subnets then + Trap {cycles_used = es.cycles_used;} return S.canister_subnet[principal_bytes].subnet_size I ∈ {i32, i64} From ea6a75dc33b7fab638aff234175e685073d6f3d6 Mon Sep 17 00:00:00 2001 From: Michael Weigelt Date: Wed, 29 Jan 2025 12:39:46 +0000 Subject: [PATCH 13/24] arbitrary --- docs/references/ic-interface-spec.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/references/ic-interface-spec.md b/docs/references/ic-interface-spec.md index 3e3e32d7fc..12803cf5fd 100644 --- a/docs/references/ic-interface-spec.md +++ b/docs/references/ic-interface-spec.md @@ -7561,7 +7561,7 @@ ic0.replication_factor(src: I, size: I) : i32 = Trap {cycles_used = es.cycles_used;} if principal_bytes ∉ es.subnets then Trap {cycles_used = es.cycles_used;} - return S.canister_subnet[principal_bytes].subnet_size + return arbitrary() I ∈ {i32, i64} ic0.debug_print(src : I, size : I) = From 8bfa142a9eb4ff7093e6c54540dd457a80e2389c Mon Sep 17 00:00:00 2001 From: Michael Weigelt Date: Wed, 29 Jan 2025 13:36:33 +0000 Subject: [PATCH 14/24] quotes --- docs/references/ic-interface-spec.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/references/ic-interface-spec.md b/docs/references/ic-interface-spec.md index 12803cf5fd..516d687ab2 100644 --- a/docs/references/ic-interface-spec.md +++ b/docs/references/ic-interface-spec.md @@ -2046,11 +2046,11 @@ These system calls return costs in Cycles, represented by 128 bits, which will b The cost of an inter-canister call. `method_name_size` is the byte length of the method name, and `payload_size` is the byte length of the argument to the method. -- `ic0.cost_create_canister : (dst : I) -> (); `I ∈ {i32, i64}` +- `ic0.cost_create_canister : (dst : I) -> ()`; `I ∈ {i32, i64}` The cost of creating a canister on the same subnet as the calling canister via [`create_canister`](#ic-create_canister). Note that canister creation via a call to the CMC can have a different cost if the target subnet has a different replication factor. In order to facilitate conversions, see `ic0.replication_factor`. When converting costs using ratios of subnet sizes, be mindful of rounding issues and consider adding a safety margin. -- `ic0.cost_http_request(request_size : i64, max_res_bytes : i64, dst : I) -> (); `I ∈ {i32, i64}` +- `ic0.cost_http_request(request_size : i64, max_res_bytes : i64, dst : I) -> ()`; `I ∈ {i32, i64}` The cost of a canister http outcall via [`http_request`](#ic-http_request). `request_size` is the sum of the byte lengths of the following components of an http request: - url @@ -2061,17 +2061,17 @@ These system calls return costs in Cycles, represented by 128 bits, which will b `max_res_bytes` is the maximum response length the caller wishes to accept. Note that this argument is not optional like in the call to the management canister. The cost depends on `max_res_bytes`, so the caller must provide it explicitly. See the [`http_request`](#ic-http_request) call to the management canister API to learn about the current default and maximum values. -- `ic0.cost_ecdsa(src : I, size : I, dst : I) -> (); `I ∈ {i32, i64}` +- `ic0.cost_ecdsa(src : I, size : I, dst : I) -> ()`; `I ∈ {i32, i64}` -- `ic0.cost_schnorr(src : I, size : I, dst : I) -> (); `I ∈ {i32, i64}` +- `ic0.cost_schnorr(src : I, size : I, dst : I) -> ()`; `I ∈ {i32, i64}` -- `ic0.cost_vetkey(src : I, size : I, dst : I) -> (); `I ∈ {i32, i64}` +- `ic0.cost_vetkey(src : I, size : I, dst : I) -> ()`; `I ∈ {i32, i64}` These system calls accept a key name via a textual representation for the specific signing scheme / key of a given size stored in the heap memory starting at offset `src` . See [`sign_with_ecdsa`](#ic-sign_with_ecdsa), [`sign_with_schnorr`](#ic-sign_with_schnorr) and [`vetkd_encrypted_key`](#ic-vetkd_encrypted_key) for more information. These system calls trap if the string represented by `src` + `size` does not correspond to a valid key name, such as `dfx_test_key`, `test_key_1` or `key_1`. -- `ic0.replication_factor : (src : I, size : I) -> i32; `I ∈ {i32, i64}` +- `ic0.replication_factor : (src : I, size : I) -> i32`; `I ∈ {i32, i64}` Returns the replication factor (subnet size) of the subnet identified by the `Principal` at `src` + `size`. From 6f97a6892c63d8e6f7cfc38a25d9205cb9eb83c0 Mon Sep 17 00:00:00 2001 From: Michael Weigelt Date: Mon, 3 Feb 2025 13:24:07 +0000 Subject: [PATCH 15/24] renaming, adding curve arg --- docs/references/ic-interface-spec.md | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/docs/references/ic-interface-spec.md b/docs/references/ic-interface-spec.md index 516d687ab2..618e80c46b 100644 --- a/docs/references/ic-interface-spec.md +++ b/docs/references/ic-interface-spec.md @@ -1493,9 +1493,9 @@ defaulting to `I = i32` if the canister declares no memory. ic0.cost_call : (method_name_size: i64, payload_size : i64, dst : I) -> (); // * s ic0.cost_create_canister : (dst : I) -> (); // * s ic0.cost_http_request(request_size : i64, max_res_bytes : i64, dst : I) -> (); // * s - ic0.cost_ecdsa(src : I, size : I, dst : I) -> (); // * s - ic0.cost_schnorr(src : I, size : I, dst : I) -> (); // * s - ic0.cost_vetkey(src : I, size : I, dst : I) -> (); // * s + ic0.cost_sign_with_ecdsa(src : I, size : I, ecdsa_curve: i32, dst : I) -> (); // * s + ic0.cost_sign_with_schnorr(src : I, size : I, algorithm: i32, dst : I) -> (); // * s + ic0.cost_vetkd_derive_encrypted_key(src : I, size : I, vetkd_curve: i32, dst : I) -> (); // * s ic0.replication_factor : (src : I, size : I) -> i32; // * s ic0.debug_print : (src : I, size : I) -> (); // * s @@ -2061,15 +2061,20 @@ These system calls return costs in Cycles, represented by 128 bits, which will b `max_res_bytes` is the maximum response length the caller wishes to accept. Note that this argument is not optional like in the call to the management canister. The cost depends on `max_res_bytes`, so the caller must provide it explicitly. See the [`http_request`](#ic-http_request) call to the management canister API to learn about the current default and maximum values. -- `ic0.cost_ecdsa(src : I, size : I, dst : I) -> ()`; `I ∈ {i32, i64}` +- `ic0.cost_sign_with_ecdsa(src : I, size : I, ecdsa_curve: i32, dst : I) -> ()`; `I ∈ {i32, i64}` -- `ic0.cost_schnorr(src : I, size : I, dst : I) -> ()`; `I ∈ {i32, i64}` +- `ic0.cost_sign_with_schnorr(src : I, size : I, algorithm: i32, dst : I) -> ()`; `I ∈ {i32, i64}` -- `ic0.cost_vetkey(src : I, size : I, dst : I) -> ()`; `I ∈ {i32, i64}` +- `ic0.cost_vetkd_derive_encrypted_key(src : I, vetkd_curve: i32, size : I, dst : I) -> ()`; `I ∈ {i32, i64}` - These system calls accept a key name via a textual representation for the specific signing scheme / key of a given size stored in the heap memory starting at offset `src` . See [`sign_with_ecdsa`](#ic-sign_with_ecdsa), [`sign_with_schnorr`](#ic-sign_with_schnorr) and [`vetkd_encrypted_key`](#ic-vetkd_encrypted_key) for more information. + These system calls accept a key name via a textual representation for the specific signing scheme / key of a given size stored in the heap memory starting at offset `src`. They also accept an `i32` with the following interpretations: + - `ecdsa_curve: 0 → secp256k1` + - `schnorr_algorithm: 0 → bip340secp256k1, 1 → ed25519` + - `vetkd_curve: 0 → bls12_381` - These system calls trap if the string represented by `src` + `size` does not correspond to a valid key name, such as `dfx_test_key`, `test_key_1` or `key_1`. + See [`sign_with_ecdsa`](#ic-sign_with_ecdsa), [`sign_with_schnorr`](#ic-sign_with_schnorr) and [`vetkd_encrypted_key`](#ic-vetkd_encrypted_key) for more information. + + These system calls trap if the string represented by `src` + `size` does not correspond to a valid key name, such as `dfx_test_key`, `test_key_1` or `key_1`, or if the provided curve enum is an unspecified variant. - `ic0.replication_factor : (src : I, size : I) -> i32`; `I ∈ {i32, i64}` @@ -7528,7 +7533,7 @@ ic0.cost_cost_http_request(request_size: i64, max_res_bytes: i64, dst: I) : copy_cycles_to_canister(dst, arbitrary()) I ∈ {i32, i64} -ic0.cost_ecdsa(src: I, size: I, dst: I) : () = +ic0.cost_sign_with_ecdsa(src: I, size: I, ecdsa_curve: i32, dst: I) : () = principal_bytes = copy_from_canister(src, size) if not principal_bytes encode a principal then Trap {cycles_used = es.cycles_used;} @@ -7537,7 +7542,7 @@ ic0.cost_ecdsa(src: I, size: I, dst: I) : () = copy_cycles_to_canister(dst, arbitrary()) I ∈ {i32, i64} -ic0.cost_schnorr(src: I, size: I, dst: I) : () = +ic0.cost_sign_with_schnorr(src: I, size: I, algorithm: i32, dst: I) : () = principal_bytes = copy_from_canister(src, size) if not principal_bytes encode a principal then Trap {cycles_used = es.cycles_used;} @@ -7546,7 +7551,7 @@ ic0.cost_schnorr(src: I, size: I, dst: I) : () = copy_cycles_to_canister(dst, arbitrary()) I ∈ {i32, i64} -ic0.cost_vetkey(src: I, size: I, dst: I) : () = +ic0.cost_vetkd_derive_encrypted_key(src: I, size: I, vetkd_curve: i32, dst: I) : () = principal_bytes = copy_from_canister(src, size) if not principal_bytes encode a principal then Trap {cycles_used = es.cycles_used;} From 2158afa52dbfe4eff0cf0fb44a780e969a69fd25 Mon Sep 17 00:00:00 2001 From: michael-weigelt <122277901+michael-weigelt@users.noreply.github.com> Date: Tue, 4 Feb 2025 17:51:29 +0100 Subject: [PATCH 16/24] Update docs/references/ic-interface-spec.md --- docs/references/ic-interface-spec.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/references/ic-interface-spec.md b/docs/references/ic-interface-spec.md index 618e80c46b..dd33099668 100644 --- a/docs/references/ic-interface-spec.md +++ b/docs/references/ic-interface-spec.md @@ -1492,10 +1492,10 @@ defaulting to `I = i32` if the canister declares no memory. ic0.cost_call : (method_name_size: i64, payload_size : i64, dst : I) -> (); // * s ic0.cost_create_canister : (dst : I) -> (); // * s - ic0.cost_http_request(request_size : i64, max_res_bytes : i64, dst : I) -> (); // * s - ic0.cost_sign_with_ecdsa(src : I, size : I, ecdsa_curve: i32, dst : I) -> (); // * s - ic0.cost_sign_with_schnorr(src : I, size : I, algorithm: i32, dst : I) -> (); // * s - ic0.cost_vetkd_derive_encrypted_key(src : I, size : I, vetkd_curve: i32, dst : I) -> (); // * s + ic0.cost_http_request : (request_size : i64, max_res_bytes : i64, dst : I) -> (); // * s + ic0.cost_sign_with_ecdsa : (src : I, size : I, ecdsa_curve: i32, dst : I) -> (); // * s + ic0.cost_sign_with_schnorr : (src : I, size : I, algorithm: i32, dst : I) -> (); // * s + ic0.cost_vetkd_derive_encrypted_key : (src : I, size : I, vetkd_curve: i32, dst : I) -> (); // * s ic0.replication_factor : (src : I, size : I) -> i32; // * s ic0.debug_print : (src : I, size : I) -> (); // * s From e8bca2b54ffd586a865bc00b600af1183f3c1a8a Mon Sep 17 00:00:00 2001 From: Michael Weigelt Date: Mon, 10 Feb 2025 10:38:47 +0000 Subject: [PATCH 17/24] comments --- docs/references/ic-interface-spec.md | 59 +++++++--------------------- 1 file changed, 15 insertions(+), 44 deletions(-) diff --git a/docs/references/ic-interface-spec.md b/docs/references/ic-interface-spec.md index dd33099668..33a3e42106 100644 --- a/docs/references/ic-interface-spec.md +++ b/docs/references/ic-interface-spec.md @@ -1493,10 +1493,9 @@ defaulting to `I = i32` if the canister declares no memory. ic0.cost_call : (method_name_size: i64, payload_size : i64, dst : I) -> (); // * s ic0.cost_create_canister : (dst : I) -> (); // * s ic0.cost_http_request : (request_size : i64, max_res_bytes : i64, dst : I) -> (); // * s - ic0.cost_sign_with_ecdsa : (src : I, size : I, ecdsa_curve: i32, dst : I) -> (); // * s - ic0.cost_sign_with_schnorr : (src : I, size : I, algorithm: i32, dst : I) -> (); // * s - ic0.cost_vetkd_derive_encrypted_key : (src : I, size : I, vetkd_curve: i32, dst : I) -> (); // * s - ic0.replication_factor : (src : I, size : I) -> i32; // * s + ic0.cost_sign_with_ecdsa : (src : I, size : I, ecdsa_curve: i32, dst : I) -> i32; // * s + ic0.cost_sign_with_schnorr : (src : I, size : I, algorithm: i32, dst : I) -> i32; // * s + ic0.cost_vetkd_derive_encrypted_key : (src : I, size : I, vetkd_curve: i32, dst : I) -> i32; // * s ic0.debug_print : (src : I, size : I) -> (); // * s ic0.trap : (src : I, size : I) -> (); // * s @@ -2048,24 +2047,23 @@ These system calls return costs in Cycles, represented by 128 bits, which will b - `ic0.cost_create_canister : (dst : I) -> ()`; `I ∈ {i32, i64}` - The cost of creating a canister on the same subnet as the calling canister via [`create_canister`](#ic-create_canister). Note that canister creation via a call to the CMC can have a different cost if the target subnet has a different replication factor. In order to facilitate conversions, see `ic0.replication_factor`. When converting costs using ratios of subnet sizes, be mindful of rounding issues and consider adding a safety margin. + The cost of creating a canister on the same subnet as the calling canister via [`create_canister`](#ic-create_canister). Note that canister creation via a call to the CMC can have a different cost if the target subnet has a different replication factor. - `ic0.cost_http_request(request_size : i64, max_res_bytes : i64, dst : I) -> ()`; `I ∈ {i32, i64}` The cost of a canister http outcall via [`http_request`](#ic-http_request). `request_size` is the sum of the byte lengths of the following components of an http request: - url - - method - headers - i.e., the sum of the lengths of all keys and values - body - transform - i.e., the sum of the transform method name length and the length of the transform context - `max_res_bytes` is the maximum response length the caller wishes to accept. Note that this argument is not optional like in the call to the management canister. The cost depends on `max_res_bytes`, so the caller must provide it explicitly. See the [`http_request`](#ic-http_request) call to the management canister API to learn about the current default and maximum values. + `max_res_bytes` is the maximum response length the caller wishes to accept (the caller should provide the default value of `2,000,000` if no maximum response length is provided in the actual request to the management canister). -- `ic0.cost_sign_with_ecdsa(src : I, size : I, ecdsa_curve: i32, dst : I) -> ()`; `I ∈ {i32, i64}` +- `ic0.cost_sign_with_ecdsa(src : I, size : I, ecdsa_curve: i32, dst : I) -> i32`; `I ∈ {i32, i64}` -- `ic0.cost_sign_with_schnorr(src : I, size : I, algorithm: i32, dst : I) -> ()`; `I ∈ {i32, i64}` +- `ic0.cost_sign_with_schnorr(src : I, size : I, algorithm: i32, dst : I) -> i32`; `I ∈ {i32, i64}` -- `ic0.cost_vetkd_derive_encrypted_key(src : I, vetkd_curve: i32, size : I, dst : I) -> ()`; `I ∈ {i32, i64}` +- `ic0.cost_vetkd_derive_encrypted_key(src : I, size : I, vetkd_curve: i32, dst : I) -> i32`; `I ∈ {i32, i64}` These system calls accept a key name via a textual representation for the specific signing scheme / key of a given size stored in the heap memory starting at offset `src`. They also accept an `i32` with the following interpretations: - `ecdsa_curve: 0 → secp256k1` @@ -2074,13 +2072,10 @@ These system calls return costs in Cycles, represented by 128 bits, which will b See [`sign_with_ecdsa`](#ic-sign_with_ecdsa), [`sign_with_schnorr`](#ic-sign_with_schnorr) and [`vetkd_encrypted_key`](#ic-vetkd_encrypted_key) for more information. - These system calls trap if the string represented by `src` + `size` does not correspond to a valid key name, such as `dfx_test_key`, `test_key_1` or `key_1`, or if the provided curve enum is an unspecified variant. - -- `ic0.replication_factor : (src : I, size : I) -> i32`; `I ∈ {i32, i64}` - - Returns the replication factor (subnet size) of the subnet identified by the `Principal` at `src` + `size`. - - This system call traps if `src` + `size` do not represent a valid `Principal` or the given `Principal` is not a subnet. + These system calls trap if `src` + `size` exceeds the size of the WebAssembly memory. Otherwise, they return an `i32` with the following meaning: + - `0 (00)`: Success. The result can be found at the memory address `dst`. + - `1 (01)`: Invalid curve or algorithm. Memory at `dst` is left unchanged. + - `2 (10)`: Invalid key name for the given scheme/curve. Memory at `dst` is left unchanged. ### Debugging aids @@ -7533,41 +7528,17 @@ ic0.cost_cost_http_request(request_size: i64, max_res_bytes: i64, dst: I) : copy_cycles_to_canister(dst, arbitrary()) I ∈ {i32, i64} -ic0.cost_sign_with_ecdsa(src: I, size: I, ecdsa_curve: i32, dst: I) : () = - principal_bytes = copy_from_canister(src, size) - if not principal_bytes encode a principal then - Trap {cycles_used = es.cycles_used;} - if principal_bytes ∉ es.subnets then - Trap {cycles_used = es.cycles_used;} +ic0.cost_sign_with_ecdsa(src: I, size: I, ecdsa_curve: i32, dst: I) : i32 = copy_cycles_to_canister(dst, arbitrary()) I ∈ {i32, i64} -ic0.cost_sign_with_schnorr(src: I, size: I, algorithm: i32, dst: I) : () = - principal_bytes = copy_from_canister(src, size) - if not principal_bytes encode a principal then - Trap {cycles_used = es.cycles_used;} - if principal_bytes ∉ es.subnets then - Trap {cycles_used = es.cycles_used;} +ic0.cost_sign_with_schnorr(src: I, size: I, algorithm: i32, dst: I) : i32 = copy_cycles_to_canister(dst, arbitrary()) I ∈ {i32, i64} -ic0.cost_vetkd_derive_encrypted_key(src: I, size: I, vetkd_curve: i32, dst: I) : () = - principal_bytes = copy_from_canister(src, size) - if not principal_bytes encode a principal then - Trap {cycles_used = es.cycles_used;} - if principal_bytes ∉ es.subnets then - Trap {cycles_used = es.cycles_used;} +ic0.cost_vetkd_derive_encrypted_key(src: I, size: I, vetkd_curve: i32, dst: I) : i32 = copy_cycles_to_canister(dst, arbitrary()) -I ∈ {i32, i64} -ic0.replication_factor(src: I, size: I) : i32 = - principal_bytes = copy_from_canister(src, size) - if not principal_bytes encode a principal then - Trap {cycles_used = es.cycles_used;} - if principal_bytes ∉ es.subnets then - Trap {cycles_used = es.cycles_used;} - return arbitrary() - I ∈ {i32, i64} ic0.debug_print(src : I, size : I) = return From c277baefe62196d2c8f53dafb78d594e2944e1ec Mon Sep 17 00:00:00 2001 From: Michael Weigelt Date: Mon, 10 Feb 2025 14:10:52 +0000 Subject: [PATCH 18/24] semantics --- docs/references/ic-interface-spec.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/docs/references/ic-interface-spec.md b/docs/references/ic-interface-spec.md index 33a3e42106..6ed8f6db45 100644 --- a/docs/references/ic-interface-spec.md +++ b/docs/references/ic-interface-spec.md @@ -7529,15 +7529,33 @@ ic0.cost_cost_http_request(request_size: i64, max_res_bytes: i64, dst: I) : I ∈ {i32, i64} ic0.cost_sign_with_ecdsa(src: I, size: I, ecdsa_curve: i32, dst: I) : i32 = + key_name = copy_from_canister(src, size) + if ecdsa_curve ∉ known_curves then + return 1 + if key_name ∉ known_keys then + return 2 copy_cycles_to_canister(dst, arbitrary()) + return 0 I ∈ {i32, i64} ic0.cost_sign_with_schnorr(src: I, size: I, algorithm: i32, dst: I) : i32 = + key_name = copy_from_canister(src, size) + if algorithm ∉ known_algorithms then + return 1 + if key_name ∉ known_keys then + return 2 copy_cycles_to_canister(dst, arbitrary()) + return 0 I ∈ {i32, i64} ic0.cost_vetkd_derive_encrypted_key(src: I, size: I, vetkd_curve: i32, dst: I) : i32 = + key_name = copy_from_canister(src, size) + if vetkd_curve ∉ known_curves then + return 1 + if key_name ∉ known_keys then + return 2 copy_cycles_to_canister(dst, arbitrary()) + return 0 I ∈ {i32, i64} ic0.debug_print(src : I, size : I) = From c359747537f9c92ded419d048d30b1abcb12ca3c Mon Sep 17 00:00:00 2001 From: Michael Weigelt Date: Wed, 12 Feb 2025 10:31:20 +0000 Subject: [PATCH 19/24] clarify cost_call --- docs/references/ic-interface-spec.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/references/ic-interface-spec.md b/docs/references/ic-interface-spec.md index 1ac74dbfb7..a204b53c1d 100644 --- a/docs/references/ic-interface-spec.md +++ b/docs/references/ic-interface-spec.md @@ -2052,7 +2052,8 @@ These system calls return costs in Cycles, represented by 128 bits, which will b - `ic0.cost_call : (method_name_size: i64, payload_size : i64, dst : I) -> ()`; `I ∈ {i32, i64}` - The cost of an inter-canister call. `method_name_size` is the byte length of the method name, and `payload_size` is the byte length of the argument to the method. + This system call returns the amount of cycles that a canister needs to be above the freezing threshold in order to successfully make an inter-canister call. This includes the base cost for an inter-canister call, the cost for each byte transmitted in the request, the cost for the transmission of the largest possible response, and the cost for executing the largest possible response callback. The last two are cost _reservations_, which must be possible for a call to succeed, but they will be partially refunded if the real response and callback are smaller. So the cost of the actual inter-canister call may be less than this system call predicts, but it cannot be more. + `method_name_size` is the byte length of the method name, and `payload_size` is the byte length of the argument to the method. - `ic0.cost_create_canister : (dst : I) -> ()`; `I ∈ {i32, i64}` From 2b05f70e8df417a818e9f609a1e1a386252f4c36 Mon Sep 17 00:00:00 2001 From: Michael Weigelt Date: Tue, 18 Feb 2025 10:30:19 +0000 Subject: [PATCH 20/24] comments --- docs/references/ic-interface-spec.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/docs/references/ic-interface-spec.md b/docs/references/ic-interface-spec.md index a204b53c1d..01e6d669ab 100644 --- a/docs/references/ic-interface-spec.md +++ b/docs/references/ic-interface-spec.md @@ -2082,7 +2082,7 @@ These system calls return costs in Cycles, represented by 128 bits, which will b See [`sign_with_ecdsa`](#ic-sign_with_ecdsa), [`sign_with_schnorr`](#ic-sign_with_schnorr) and [`vetkd_encrypted_key`](#ic-vetkd_encrypted_key) for more information. - These system calls trap if `src` + `size` exceeds the size of the WebAssembly memory. Otherwise, they return an `i32` with the following meaning: + These system calls trap if `src` + `size` or `dst` + 16 exceed the size of the WebAssembly memory. Otherwise, they return an `i32` with the following meaning: - `0 (00)`: Success. The result can be found at the memory address `dst`. - `1 (01)`: Invalid curve or algorithm. Memory at `dst` is left unchanged. - `2 (10)`: Invalid key name for the given scheme/curve. Memory at `dst` is left unchanged. @@ -7555,6 +7555,8 @@ ic0.cost_cost_http_request(request_size: i64, max_res_bytes: i64, dst: I) : I ∈ {i32, i64} ic0.cost_sign_with_ecdsa(src: I, size: I, ecdsa_curve: i32, dst: I) : i32 = + known_keys = arbitrary() + known_curves = arbitrary() key_name = copy_from_canister(src, size) if ecdsa_curve ∉ known_curves then return 1 @@ -7565,6 +7567,8 @@ ic0.cost_sign_with_ecdsa(src: I, size: I, ecdsa_curve: i32, dst: I) : i32 = I ∈ {i32, i64} ic0.cost_sign_with_schnorr(src: I, size: I, algorithm: i32, dst: I) : i32 = + known_keys = arbitrary() + known_curves = arbitrary() key_name = copy_from_canister(src, size) if algorithm ∉ known_algorithms then return 1 @@ -7575,6 +7579,8 @@ ic0.cost_sign_with_schnorr(src: I, size: I, algorithm: i32, dst: I) : i32 = I ∈ {i32, i64} ic0.cost_vetkd_derive_encrypted_key(src: I, size: I, vetkd_curve: i32, dst: I) : i32 = + known_keys = arbitrary() + known_curves = arbitrary() key_name = copy_from_canister(src, size) if vetkd_curve ∉ known_curves then return 1 From 2ea843eb29f6c83141bb1fdaea084aff209976dc Mon Sep 17 00:00:00 2001 From: michael-weigelt <122277901+michael-weigelt@users.noreply.github.com> Date: Tue, 18 Feb 2025 14:31:52 +0100 Subject: [PATCH 21/24] Update docs/references/ic-interface-spec.md Co-authored-by: mraszyk <31483726+mraszyk@users.noreply.github.com> --- docs/references/ic-interface-spec.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/references/ic-interface-spec.md b/docs/references/ic-interface-spec.md index 01e6d669ab..9310edce65 100644 --- a/docs/references/ic-interface-spec.md +++ b/docs/references/ic-interface-spec.md @@ -7550,7 +7550,7 @@ ic0.cost_create_canister(dst: I) : () = copy_cycles_to_canister(dst, arbitrary()) I ∈ {i32, i64} -ic0.cost_cost_http_request(request_size: i64, max_res_bytes: i64, dst: I) : () = +ic0.cost_http_request(request_size: i64, max_res_bytes: i64, dst: I) : () = copy_cycles_to_canister(dst, arbitrary()) I ∈ {i32, i64} From 4494d94e48e7f10ddac5853cfdebbc6ab67c7c77 Mon Sep 17 00:00:00 2001 From: michael-weigelt <122277901+michael-weigelt@users.noreply.github.com> Date: Tue, 18 Feb 2025 14:32:08 +0100 Subject: [PATCH 22/24] Update docs/references/ic-interface-spec.md Co-authored-by: mraszyk <31483726+mraszyk@users.noreply.github.com> --- docs/references/ic-interface-spec.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/references/ic-interface-spec.md b/docs/references/ic-interface-spec.md index 9310edce65..845d226b40 100644 --- a/docs/references/ic-interface-spec.md +++ b/docs/references/ic-interface-spec.md @@ -2077,7 +2077,7 @@ These system calls return costs in Cycles, represented by 128 bits, which will b These system calls accept a key name via a textual representation for the specific signing scheme / key of a given size stored in the heap memory starting at offset `src`. They also accept an `i32` with the following interpretations: - `ecdsa_curve: 0 → secp256k1` - - `schnorr_algorithm: 0 → bip340secp256k1, 1 → ed25519` + - `algorithm: 0 → bip340secp256k1, 1 → ed25519` - `vetkd_curve: 0 → bls12_381` See [`sign_with_ecdsa`](#ic-sign_with_ecdsa), [`sign_with_schnorr`](#ic-sign_with_schnorr) and [`vetkd_encrypted_key`](#ic-vetkd_encrypted_key) for more information. From 7ca24c61a1271673e8abf41a7d0dd82a3af8bbf9 Mon Sep 17 00:00:00 2001 From: michael-weigelt <122277901+michael-weigelt@users.noreply.github.com> Date: Tue, 18 Feb 2025 14:34:25 +0100 Subject: [PATCH 23/24] Update docs/references/ic-interface-spec.md Co-authored-by: mraszyk <31483726+mraszyk@users.noreply.github.com> --- docs/references/ic-interface-spec.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/references/ic-interface-spec.md b/docs/references/ic-interface-spec.md index 845d226b40..ccf5a22174 100644 --- a/docs/references/ic-interface-spec.md +++ b/docs/references/ic-interface-spec.md @@ -7568,7 +7568,7 @@ ic0.cost_sign_with_ecdsa(src: I, size: I, ecdsa_curve: i32, dst: I) : i32 = I ∈ {i32, i64} ic0.cost_sign_with_schnorr(src: I, size: I, algorithm: i32, dst: I) : i32 = known_keys = arbitrary() - known_curves = arbitrary() + known_algorithms = arbitrary() key_name = copy_from_canister(src, size) if algorithm ∉ known_algorithms then return 1 From b2744cd01d307dd64abb56ec005a2cea9bc12797 Mon Sep 17 00:00:00 2001 From: Michael Weigelt Date: Tue, 18 Feb 2025 13:34:50 +0000 Subject: [PATCH 24/24] comment --- docs/references/ic-interface-spec.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/references/ic-interface-spec.md b/docs/references/ic-interface-spec.md index 01e6d669ab..9261d27fda 100644 --- a/docs/references/ic-interface-spec.md +++ b/docs/references/ic-interface-spec.md @@ -2085,7 +2085,7 @@ These system calls return costs in Cycles, represented by 128 bits, which will b These system calls trap if `src` + `size` or `dst` + 16 exceed the size of the WebAssembly memory. Otherwise, they return an `i32` with the following meaning: - `0 (00)`: Success. The result can be found at the memory address `dst`. - `1 (01)`: Invalid curve or algorithm. Memory at `dst` is left unchanged. - - `2 (10)`: Invalid key name for the given scheme/curve. Memory at `dst` is left unchanged. + - `2 (10)`: Invalid key name for the given combination of signing scheme and curve/algorithm. Memory at `dst` is left unchanged. ### Debugging aids