casper_contract/ext_ffi.rs
1//! Contains low-level bindings for host-side ("external") functions.
2//!
3//! Generally should not be used directly. See the [`contract_api`](crate::contract_api) for
4//! high-level bindings suitable for writing smart contracts.
5
6#[cfg(doc)]
7use alloc::collections::BTreeMap;
8
9extern "C" {
10 /// The bytes in the span of wasm memory from `key_ptr` to `key_ptr + key_size` must correspond
11 /// to a valid global state key, otherwise the function will fail. If the key is de-serialized
12 /// successfully, then the result of the read is serialized and buffered in the runtime. This
13 /// result can be obtained via the [`casper_read_host_buffer`] function. Returns standard error
14 /// code.
15 ///
16 /// # Arguments
17 ///
18 /// * `key_ptr` - pointer (offset in wasm linear memory) to serialized form of the key to read
19 /// * `key_size` - size of the serialized key (in bytes)
20 /// * `output_size` - pointer to a value where host will write size of bytes read from given key
21 pub fn casper_read_value(key_ptr: *const u8, key_size: usize, output_size: *mut usize) -> i32;
22 /// This function writes the provided value (read via de-serializing the bytes
23 /// in wasm memory from offset `value_ptr` to `value_ptr + value_size`) under
24 /// the provided key (read via de-serializing the bytes in wasm memory from
25 /// offset `key_ptr` to `key_ptr + key_size`) in the global state. This
26 /// function will cause a `Trap` if the key or value fail to de-serialize or
27 /// if writing to that key is not permitted.
28 ///
29 /// # Arguments
30 ///
31 /// * `key_ptr` - pointer to bytes representing the key to write to
32 /// * `key_size` - size of the key (in bytes)
33 /// * `value_ptr` - pointer to bytes representing the value to write at the key
34 /// * `value_size` - size of the value (in bytes)
35 pub fn casper_write(
36 key_ptr: *const u8,
37 key_size: usize,
38 value_ptr: *const u8,
39 value_size: usize,
40 );
41 /// This function adds the provided value (read via de-serializing the bytes
42 /// in wasm memory from offset `value_ptr` to `value_ptr + value_size`) to the
43 /// current value under the provided key (read via de-serializing the bytes in
44 /// wasm memory from offset `key_ptr` to `key_ptr + key_size`) in the global
45 /// state. This function will cause a `Trap` if the key or value fail to
46 /// de-serialize or if adding to that key is not permitted, or no value
47 /// presently exists at that key.
48 ///
49 /// # Arguments
50 ///
51 /// * `key_ptr` - pointer to bytes representing the key to write to
52 /// * `key_size` - size of the key (in bytes)
53 /// * `value_ptr` - pointer to bytes representing the value to write at the key
54 /// * `value_size` - size of the value (in bytes)
55 pub fn casper_add(key_ptr: *const u8, key_size: usize, value_ptr: *const u8, value_size: usize);
56 /// This function causes the runtime to generate a new `URef`, with
57 /// the provided value stored under it in the global state. The new
58 /// `URef` is written (in serialized form) to the wasm linear
59 /// memory starting from the `key_ptr` offset. Note that data corruption is possible if not
60 /// enough memory is allocated for the `URef` at `key_ptr`. This
61 /// function will cause a `Trap` if the bytes in wasm memory from offset `value_ptr` to
62 /// `value_ptr + value_size` cannot be de-serialized into a `Value`.
63 ///
64 /// # Arguments
65 ///
66 /// * `key_ptr` - pointer to the offset in wasm memory where the new `URef` will be written
67 /// * `value_ptr` - pointer to bytes representing the value to write under the new `URef`
68 /// * `value_size` - size of the value (in bytes)
69 pub fn casper_new_uref(uref_ptr: *mut u8, value_ptr: *const u8, value_size: usize);
70 /// This function loads a set of authorized keys used to sign this deploy from the host.
71 /// The data will be available through the host buffer and can be copied to Wasm memory through
72 /// [`casper_read_host_buffer`].
73 ///
74 /// # Arguments
75 ///
76 /// * `total_keys`: number of authorization keys used to sign this deploy
77 /// * `result_size`: size of the data loaded in the host
78 pub fn casper_load_authorization_keys(total_keys: *mut usize, result_size: *mut usize) -> i32;
79 /// This function loads a set of named keys from the host. The data will be available through
80 /// the host buffer and can be copied to Wasm memory through [`casper_read_host_buffer`].
81 pub fn casper_load_named_keys(total_keys: *mut usize, result_size: *mut usize) -> i32;
82 /// This function causes a `Trap`, terminating the currently running module,
83 /// but first copies the bytes from `value_ptr` to `value_ptr + value_size` to
84 /// a buffer which is returned to the calling module (if this module was
85 /// invoked by [`casper_call_contract`] or [`casper_call_versioned_contract`]). Additionally,
86 /// the known `URef`s of the calling context are augmented with the
87 /// `URef`s de-serialized from wasm memory offset
88 /// `extra_urefs_ptr` to `extra_urefs_ptr + extra_urefs_size`. This function will cause a
89 /// `Trap` if the bytes at `extra_urefs_ptr` cannot be de-serialized as type `Vec<URef>`, or
90 /// if any of the extra `URef`s are invalid in the current
91 /// context.
92 ///
93 /// # Arguments
94 ///
95 /// * `value_ptr`: pointer to bytes representing the value to return to the caller
96 /// * `value_size`: size of the value (in bytes)
97 pub fn casper_ret(value_ptr: *const u8, value_size: usize) -> !;
98 /// Retrieves a key from the named keys by name and writes it to the output buffer.
99 pub fn casper_get_key(
100 name_ptr: *const u8,
101 name_size: usize,
102 output_ptr: *mut u8,
103 output_size: usize,
104 bytes_written_ptr: *mut usize,
105 ) -> i32;
106 /// This function checks if the key with the given name is present in the named keys.
107 pub fn casper_has_key(name_ptr: *const u8, name_size: usize) -> i32;
108 /// This function stores a key under the given name in the named keys.
109 pub fn casper_put_key(
110 name_ptr: *const u8,
111 name_size: usize,
112 key_ptr: *const u8,
113 key_size: usize,
114 );
115 /// This function removes a key with the given name from the named keys.
116 pub fn casper_remove_key(name_ptr: *const u8, name_size: usize);
117 /// This function causes a `Trap` which terminates the currently running
118 /// module. Additionally, it signals that the current entire phase of
119 /// execution of the deploy should be terminated as well, and that the effects
120 /// of the execution up to this point should be reverted. The error code
121 /// provided to this function will be included in the error message of the
122 /// deploy in the block in which it is included.
123 ///
124 /// # Arguments
125 ///
126 /// * `status` - error code of the revert
127 pub fn casper_revert(status: u32) -> !;
128 /// This function checks if all the keys contained in the given `Value` are
129 /// valid in the current context (i.e. the `Value` does not contain any forged
130 /// `URef`s). This function causes a `Trap` if the bytes in wasm
131 /// memory from offset `value_ptr` to `value_ptr + value_size` cannot be de-serialized as
132 /// type `Value`.
133 pub fn casper_is_valid_uref(uref_ptr: *const u8, uref_size: usize) -> i32;
134 /// This function attempts to add the given public key as an associated key to
135 /// the current account. Presently only 32-byte keys are supported; it is up
136 /// to the caller to ensure that the 32-bytes starting from offset
137 /// `public_key` represent the key they wish to add. Weights are internally
138 /// represented by a `u8`, this function will cause a `Trap` if the weight is
139 /// not between 0 and 255 inclusively. The result returned is a status code
140 /// for adding the key where 0 represents success, 1 means no more keys can be
141 /// added to this account (only 10 keys can be added), 2 means the key is
142 /// already associated (if you wish to change the weight of an associated key
143 /// then used [`casper_update_associated_key`]), and 3 means permission denied (this
144 /// could be because the function was called outside of session code or
145 /// because the key management threshold was not met by the keys authorizing
146 /// the deploy).
147 ///
148 /// Returns status code for adding the key, where 0 represents success and non-zero represents
149 /// failure.
150 ///
151 /// # Arguments
152 ///
153 /// * `public_key` - pointer to the bytes in wasm memory representing the public key to add,
154 /// presently only 32-byte public keys are supported.
155 /// * `weight` - the weight to assign to this public key
156 pub fn casper_add_associated_key(
157 account_hash_ptr: *const u8,
158 account_hash_size: usize,
159 weight: i32,
160 ) -> i32;
161 /// This function attempts to remove the given public key from the associated
162 /// keys of the current account. Presently only 32-byte keys are supported; it
163 /// is up to the caller to ensure that the 32-bytes starting from offset
164 /// `public_key` represent the key they wish to remove. The result returned is
165 /// a status code for adding the key where 0 represents success, 1 means the
166 /// key was not associated to begin with, 2 means means permission denied
167 /// (this could be because the function was called outside of session code or
168 /// because the key management threshold was not met by the keys authorizing
169 /// the deploy), and 3 means this key cannot be removed because otherwise it
170 /// would be impossible to meet either the deploy or key management
171 /// thresholds.
172 ///
173 /// Returns status code for adding the key, where 0 represents success and non-zero represents
174 /// failure.
175 ///
176 /// # Arguments
177 ///
178 /// * `public_key` - pointer to the bytes in wasm memory representing the public key to update,
179 /// presently only 32-byte public keys are supported.
180 /// * `weight` - the weight to assign to this public key
181 pub fn casper_remove_associated_key(
182 account_hash_ptr: *const u8,
183 account_hash_size: usize,
184 ) -> i32;
185 /// This function attempts to update the given public key as an associated key
186 /// to the current account. Presently only 32-byte keys are supported; it is
187 /// up to the caller to ensure that the 32-bytes starting from offset
188 /// `public_key` represent the key they wish to add. Weights are internally
189 /// represented by a `u8`, this function will cause a `Trap` if the weight is
190 /// not between 0 and 255 inclusively. The result returned is a status code
191 /// for adding the key where 0 represents success, 1 means the key was not
192 /// associated to the account (to add a new key use `add_associated_key`), 2
193 /// means means permission denied (this could be because the function was
194 /// called outside of session code or because the key management threshold was
195 /// not met by the keys authorizing the deploy), and 3 means this key cannot
196 /// be changed to the specified weight because then it would be impossible to
197 /// meet either the deploy or key management thresholds (you may wish to try
198 /// again with a higher weight or after lowering the action thresholds).
199 ///
200 /// # Arguments
201 ///
202 /// * `public_key` - pointer to the bytes in wasm memory representing the public key to update,
203 /// presently only 32-byte public keys are supported.
204 /// * `weight` - the weight to assign to this public key
205 pub fn casper_update_associated_key(
206 account_hash_ptr: *const u8,
207 account_hash_size: usize,
208 weight: i32,
209 ) -> i32;
210 /// This function changes the threshold to perform the specified action. The
211 /// action index is interpreted as follows: 0 means deployment and 1 means key
212 /// management. Thresholds are represented internally as a `u8`, this function
213 /// will cause a `Trap` if the new threshold is not between 0 and 255
214 /// inclusively. The return value is a status code where 0 means success, 1
215 /// means the key management threshold cannot be set lower than the deploy
216 /// threshold, 2 means the deployment threshold cannot be set higher than the
217 /// key management threshold, 3 means permission denied (this could be because
218 /// the function was called outside of session code or because the key
219 /// management threshold was not met by the keys authorizing the deploy), and
220 /// 4 means the threshold would be set higher than the total weight of
221 /// associated keys (and therefore would be impossible to meet).
222 ///
223 /// # Arguments
224 ///
225 /// * `action` - index representing the action threshold to set
226 /// * `threshold` - new value of the threshold for performing this action
227 pub fn casper_set_action_threshold(permission_level: u32, threshold: u32) -> i32;
228 /// Returns the caller of the current context, i.e. the [`casper_types::account::AccountHash`]
229 /// of the account which made the transaction request. The value stored in the host
230 /// buffer is always 32-bytes in length.
231 ///
232 /// # Arguments
233 ///
234 /// * `output_size_ptr` - pointer to a value where the size of the account hash will be set.
235 pub fn casper_get_caller(output_size_ptr: *mut usize) -> i32;
236 /// This function gets the timestamp which will be in the block this deploy is
237 /// included in. The return value is always a 64-bit unsigned integer,
238 /// representing the number of milliseconds since the Unix epoch. It is up to
239 /// the caller to ensure there are 8 bytes allocated at `dest_ptr`, otherwise
240 /// data corruption in the wasm memory may occur.
241 ///
242 /// # Arguments
243 ///
244 /// * `dest_ptr` - pointer in wasm memory where to write the result
245 pub fn casper_get_blocktime(dest_ptr: *const u8);
246 /// This function uses the mint contract to create a new, empty purse. If the
247 /// call is successful then the `URef` (in serialized form) is written
248 /// to the indicated place in wasm memory. It is up to the caller to ensure at
249 /// least `purse_size` bytes are allocated at `purse_ptr`, otherwise
250 /// data corruption may occur. This function causes a `Trap` if
251 /// `purse_size` is not equal to 38.
252 ///
253 /// # Arguments
254 ///
255 /// * `purse_ptr` - pointer to position in wasm memory where to write the created `URef`
256 /// * `purse_size` - allocated size for the `URef`
257 pub fn casper_create_purse(purse_ptr: *const u8, purse_size: usize) -> i32;
258 /// This function uses the mint contract’s transfer function to transfer
259 /// tokens from the current account’s main purse to the main purse of the
260 /// target account. If the target account does not exist then it is
261 /// automatically created, and the tokens are transferred to the main purse of
262 /// the new account. The target is a serialized `PublicKey` (i.e. 36 bytes
263 /// where the first 4 bytes are the number `32` in little endian encoding, and
264 /// the remaining 32-bytes are the public key). The amount must be a
265 /// serialized 512-bit unsigned integer. This function causes a `Trap` if the
266 /// target cannot be de-serialized as a `PublicKey` or the amount cannot be
267 /// de-serialized into a `U512`. The return value indicated what occurred,
268 /// where 0 means a successful transfer to an existing account, 1 means a
269 /// successful transfer to a new account, and 2 means the transfer failed
270 /// (this could be because the current account’s main purse had insufficient
271 /// tokens or because the function was called outside of session code and so
272 /// does not have access to the account’s main purse).
273 ///
274 /// # Arguments
275 ///
276 /// * `target_ptr` - pointer in wasm memory to bytes representing the target account to transfer
277 /// to
278 /// * `target_size` - size of the target (in bytes)
279 /// * `amount_ptr` - pointer in wasm memory to bytes representing the amount to transfer to the
280 /// target account
281 /// * `amount_size` - size of the amount (in bytes)
282 /// * `id_ptr` - pointer in wasm memory to bytes representing the user-defined transaction id
283 /// * `id_size` - size of the id (in bytes)
284 /// * `result_ptr` - pointer in wasm memory to a value where `TransferredTo` value would be set
285 /// on successful transfer.
286 pub fn casper_transfer_to_account(
287 target_ptr: *const u8,
288 target_size: usize,
289 amount_ptr: *const u8,
290 amount_size: usize,
291 id_ptr: *const u8,
292 id_size: usize,
293 result_ptr: *const i32,
294 ) -> i32;
295 /// This function uses the mint contract’s transfer function to transfer
296 /// tokens from the specified purse to the main purse of the target account.
297 /// If the target account does not exist then it is automatically created, and
298 /// the tokens are transferred to the main purse of the new account. The
299 /// source is a serialized `URef`.
300 /// The target is a serialized `PublicKey` (i.e. 36 bytes where the
301 /// first 4 bytes are the number `32` in little endian encoding, and the
302 /// remaining 32-bytes are the public key). The amount must be a serialized
303 /// 512-bit unsigned integer. This function causes a `Trap` if the source
304 /// cannot be de-serialized as a `URef`, or the target cannot be
305 /// de-serialized as a `PublicKey` or the amount cannot be de-serialized into
306 /// a `U512`. The return value indicated what occurred, where 0 means a
307 /// successful transfer to an existing account, 1 means a successful transfer
308 /// to a new account, and 2 means the transfer failed (this could be because
309 /// the source purse had insufficient tokens or because there was not valid
310 /// access to the source purse).
311 ///
312 /// # Arguments
313 ///
314 /// * `source_ptr` - pointer in wasm memory to bytes representing the source `URef` to transfer
315 /// from
316 /// * `source_size` - size of the source `URef` (in bytes)
317 /// * `target_ptr` - pointer in wasm memory to bytes representing the target account to transfer
318 /// to
319 /// * `target_size` - size of the target (in bytes)
320 /// * `amount_ptr` - pointer in wasm memory to bytes representing the amount to transfer to the
321 /// target account
322 /// * `amount_size` - size of the amount (in bytes)
323 /// * `id_ptr` - pointer in wasm memory to bytes representing the user-defined transaction id
324 /// * `id_size` - size of the id (in bytes)
325 /// * `result_ptr` - pointer in wasm memory to a value where `TransferredTo` value would be set
326 /// on successful transfer.
327 pub fn casper_transfer_from_purse_to_account(
328 source_ptr: *const u8,
329 source_size: usize,
330 target_ptr: *const u8,
331 target_size: usize,
332 amount_ptr: *const u8,
333 amount_size: usize,
334 id_ptr: *const u8,
335 id_size: usize,
336 result_ptr: *const i32,
337 ) -> i32;
338 /// This function uses the mint contract’s transfer function to transfer
339 /// tokens from the specified source purse to the specified target purse. If
340 /// the target account does not exist then it is automatically created, and
341 /// the tokens are transferred to the main purse of the new account. The
342 /// source is a serialized `URef`.
343 /// The target is also a serialized `URef`. The amount must be a
344 /// serialized 512-bit unsigned integer. This function causes a `Trap` if the
345 /// source or target cannot be de-serialized as a `URef` or the amount
346 /// cannot be de-serialized into a `U512`. The return value indicated what
347 /// occurred, where 0 means a successful transfer, 1 means the transfer
348 /// failed (this could be because the source purse had insufficient tokens or
349 /// because there was not valid access to the source purse or target purse).
350 ///
351 /// # Arguments
352 ///
353 /// * `source_ptr` - pointer in wasm memory to bytes representing the source `URef` to transfer
354 /// from
355 /// * `source_size` - size of the source `URef` (in bytes)
356 /// * `target_ptr` - pointer in wasm memory to bytes representing the target `URef` to transfer
357 /// to
358 /// * `target_size` - size of the target (in bytes)
359 /// * `amount_ptr` - pointer in wasm memory to bytes representing the amount to transfer to the
360 /// target account
361 /// * `amount_size` - size of the amount (in bytes)
362 /// * `id_ptr` - pointer in wasm memory to bytes representing the user-defined transaction id
363 /// * `id_size` - size of the id (in bytes)
364 pub fn casper_transfer_from_purse_to_purse(
365 source_ptr: *const u8,
366 source_size: usize,
367 target_ptr: *const u8,
368 target_size: usize,
369 amount_ptr: *const u8,
370 amount_size: usize,
371 id_ptr: *const u8,
372 id_size: usize,
373 ) -> i32;
374 /// This function uses the mint contract's balance function to get the balance
375 /// of the specified purse. It causes a `Trap` if the bytes in wasm memory
376 /// from `purse_ptr` to `purse_ptr + purse_size` cannot be
377 /// de-serialized as a `URef`. The return value is the size of the
378 /// result in bytes. The result is copied to the host buffer and thus can be obtained
379 /// by any function which copies the buffer into wasm memory (e.g.
380 /// `get_read`). The result bytes are serialized from type `Option<U512>` and
381 /// should be interpreted as such.
382 ///
383 /// # Arguments
384 ///
385 /// * `purse_ptr` - pointer in wasm memory to the bytes representing the `URef` of the purse to
386 /// get the balance of
387 /// * `purse_size` - size of the `URef` (in bytes)
388 pub fn casper_get_balance(
389 purse_ptr: *const u8,
390 purse_size: usize,
391 result_size: *mut usize,
392 ) -> i32;
393 /// This function writes bytes representing the current phase of the deploy
394 /// execution to the specified pointer. The size of the result is always one
395 /// byte, it is up to the caller to ensure one byte of memory is allocated at
396 /// `dest_ptr`, otherwise data corruption in the wasm memory could occur. The
397 /// one byte is interpreted as follows: 0 means a system phase (should never
398 /// be encountered by user deploys), 1 means the payment phase, 2 means the
399 /// session phase and 3 means the finalization phase (should never be
400 /// encountered by user code).
401 ///
402 /// # Arguments
403 ///
404 /// * `dest_ptr` - pointer to position in wasm memory to write the result
405 pub fn casper_get_phase(dest_ptr: *mut u8);
406 /// Retrieves a system contract by index and writes it to the destination pointer.
407 pub fn casper_get_system_contract(
408 system_contract_index: u32,
409 dest_ptr: *mut u8,
410 dest_size: usize,
411 ) -> i32;
412 /// Retrieves the main purse and writes it to the destination pointer.
413 pub fn casper_get_main_purse(dest_ptr: *mut u8);
414 /// This function copies the contents of the current runtime buffer into the
415 /// wasm memory, beginning at the provided offset. It is intended that this
416 /// function be called after a call to a function that uses host buffer. It is up to the caller
417 /// to ensure that the proper amount of memory is allocated for this write,
418 /// otherwise data corruption in the wasm memory may occur due to this call
419 /// overwriting some bytes unintentionally. The size of the data which will be
420 /// written is stored on the host. The bytes which are written are those corresponding to the
421 /// value returned by the called contract; it is up to the developer to know how to attempt
422 /// to interpret those bytes.
423 ///
424 /// # Arguments
425 ///
426 /// * `dest_ptr` - pointer (offset in wasm memory) to the location where the host buffer should
427 /// be written
428 /// * `dest_size` - size of output buffer
429 /// * `bytes_written` - a pointer to a value where amount of bytes written will be set
430 pub fn casper_read_host_buffer(
431 dest_ptr: *mut u8,
432 dest_size: usize,
433 bytes_written: *mut usize,
434 ) -> i32;
435 /// Creates new contract package at hash. Returns both newly generated
436 /// [`casper_types::PackageHash`] and a [`casper_types::URef`] for further
437 /// modifying access.
438 pub fn casper_create_contract_package_at_hash(
439 hash_addr_ptr: *mut u8,
440 access_addr_ptr: *mut u8,
441 is_locked: bool,
442 );
443 /// Creates new named contract user group under a contract package.
444 ///
445 /// # Arguments
446 ///
447 /// * `contract_package_hash_ptr` - pointer to serialized contract package hash.
448 /// * `contract_package_hash_size` - size of contract package hash in serialized form.
449 /// * `label_ptr` - serialized group label
450 /// * `label_size` - size of serialized group label
451 /// * `num_new_urefs` - amount of new urefs to be provisioned by host
452 /// * `existing_urefs_ptr` - serialized list of existing [`casper_types::URef`]s
453 /// * `existing_urefs_size` - size of serialized list of [`casper_types::URef`]s
454 /// * `output_size_ptr` - pointer to a value where a size of list of [`casper_types::URef`]s
455 /// written to host buffer will be set.
456 pub fn casper_create_contract_user_group(
457 contract_package_hash_ptr: *const u8,
458 contract_package_hash_size: usize,
459 label_ptr: *const u8,
460 label_size: usize,
461 num_new_urefs: u8,
462 existing_urefs_ptr: *const u8,
463 existing_urefs_size: usize,
464 output_size_ptr: *mut usize,
465 ) -> i32;
466 /// Adds new contract version to a contract package without message topics.
467 ///
468 /// # Arguments
469 ///
470 /// * `contract_package_hash_ptr` - pointer to serialized contract package hash.
471 /// * `contract_package_hash_size` - size of contract package hash in serialized form.
472 /// * `version_ptr` - output parameter where new version assigned by host is set
473 /// * `entry_points_ptr` - pointer to serialized [`casper_types::EntryPoints`]
474 /// * `entry_points_size` - size of serialized [`casper_types::EntryPoints`]
475 /// * `named_keys_ptr` - pointer to serialized [`casper_types::NamedKeys`]
476 /// * `named_keys_size` - size of serialized [`casper_types::NamedKeys`]
477 /// * `output_ptr` - pointer to a memory where host assigned contract hash is set to
478 /// * `output_size` - size of memory area that host can write to
479 /// * `bytes_written_ptr` - pointer to a value where host will set a number of bytes written to
480 /// the `output_size` pointer
481 pub fn casper_add_contract_version(
482 contract_package_hash_ptr: *const u8,
483 contract_package_hash_size: usize,
484 version_ptr: *const u32,
485 entry_points_ptr: *const u8,
486 entry_points_size: usize,
487 named_keys_ptr: *const u8,
488 named_keys_size: usize,
489 output_ptr: *mut u8,
490 output_size: usize,
491 bytes_written_ptr: *mut usize,
492 ) -> i32;
493 /// Adds a new version to a contract package with message topics.
494 ///
495 /// # Arguments
496 ///
497 /// * `contract_package_hash_ptr` - pointer to serialized package hash.
498 /// * `contract_package_hash_size` - size of package hash in serialized form.
499 /// * `version_ptr` - output parameter where new version assigned by host is set
500 /// * `entry_points_ptr` - pointer to serialized [`casper_types::EntryPoints`]
501 /// * `entry_points_size` - size of serialized [`casper_types::EntryPoints`]
502 /// * `named_keys_ptr` - pointer to serialized [`casper_types::NamedKeys`]
503 /// * `named_keys_size` - size of serialized [`casper_types::NamedKeys`]
504 /// * `message_topics_ptr` - pointer to serialized BTreeMap<String, MessageTopicOperation>
505 /// containing message topic names and the operation to pe performed on each one.
506 /// * `message_topics_size` - size of serialized BTreeMap<String, MessageTopicOperation>
507 /// * `output_ptr` - pointer to a memory where host assigned contract hash is set to
508 /// * `output_size` - expected width of output (currently 32)
509 pub fn casper_add_contract_version_with_message_topics(
510 contract_package_hash_ptr: *const u8,
511 contract_package_hash_size: usize,
512 version_ptr: *const u32,
513 entry_points_ptr: *const u8,
514 entry_points_size: usize,
515 named_keys_ptr: *const u8,
516 named_keys_size: usize,
517 message_topics_ptr: *const u8,
518 message_topics_size: usize,
519 output_ptr: *mut u8,
520 output_size: usize,
521 ) -> i32;
522 /// Adds a new version to a package.
523 ///
524 /// # Arguments
525 ///
526 /// * `package_hash_ptr` - pointer to serialized package hash.
527 /// * `package_hash_size` - size of package hash in serialized form.
528 /// * `version_ptr` - output parameter where new version assigned by host is set
529 /// * `entry_points_ptr` - pointer to serialized [`casper_types::EntryPoints`]
530 /// * `entry_points_size` - size of serialized [`casper_types::EntryPoints`]
531 /// * `named_keys_ptr` - pointer to serialized [`casper_types::NamedKeys`]
532 /// * `named_keys_size` - size of serialized [`casper_types::NamedKeys`]
533 /// * `message_topics_ptr` - pointer to serialized BTreeMap<String, MessageTopicOperation>
534 /// containing message topic names and the operation to pe performed on each one.
535 /// * `message_topics_size` - size of serialized BTreeMap<String, MessageTopicOperation>
536 /// * `output_ptr` - pointer to a memory where host assigned contract hash is set to
537 /// * `output_size` - expected width of output (currently 32)
538 pub fn casper_add_package_version_with_message_topics(
539 package_hash_ptr: *const u8,
540 package_hash_size: usize,
541 version_ptr: *const u32,
542 entry_points_ptr: *const u8,
543 entry_points_size: usize,
544 named_keys_ptr: *const u8,
545 named_keys_size: usize,
546 message_topics_ptr: *const u8,
547 message_topics_size: usize,
548 output_ptr: *mut u8,
549 output_size: usize,
550 ) -> i32;
551 /// Disables contract in a contract package. Returns non-zero standard error for a failure,
552 /// otherwise a zero indicates success.
553 ///
554 /// # Arguments
555 ///
556 /// * `contract_package_hash_ptr` - pointer to serialized contract package hash.
557 /// * `contract_package_hash_size` - size of contract package hash in serialized form.
558 /// * `contract_hash_ptr` - pointer to serialized contract hash.
559 /// * `contract_hash_size` - size of contract hash in serialized form.
560 pub fn casper_disable_contract_version(
561 contract_package_hash_ptr: *const u8,
562 contract_package_hash_size: usize,
563 contract_hash_ptr: *const u8,
564 contract_hash_size: usize,
565 ) -> i32;
566 /// Calls a contract by its hash. Requires entry point name that has to be present on a
567 /// specified contract, and serialized named arguments. Returns a standard error code in
568 /// case of failure, otherwise a successful execution returns zero. Bytes returned from contract
569 /// execution are set to `result_size` pointer.
570 ///
571 /// # Arguments
572 /// * `contract_package_hash_ptr` - pointer to serialized contract package hash.
573 /// * `contract_package_hash_size` - size of contract package hash in serialized form.
574 /// * `entry_point_name_ptr` - pointer to serialized contract entry point name
575 /// * `entry_point_name_size` - size of serialized contract entry point name
576 /// * `runtime_args_ptr` - pointer to serialized runtime arguments
577 /// * `runtime_args_size` - size of serialized runtime arguments
578 /// * `result_size` - a pointer to a value which will be set to a size of bytes of called
579 /// contract return value
580 pub fn casper_call_contract(
581 contract_hash_ptr: *const u8,
582 contract_hash_size: usize,
583 entry_point_name_ptr: *const u8,
584 entry_point_name_size: usize,
585 runtime_args_ptr: *const u8,
586 runtime_args_size: usize,
587 result_size: *mut usize,
588 ) -> i32;
589 /// Calls a contract by its package hash. Optionally accepts a serialized `Option<u32>` as a
590 /// version that for `None` case would call most recent version for given protocol version,
591 /// otherwise it selects a specific contract version. Requires an entry point name
592 /// registered in a given version of contract. Returns a standard error code in case of
593 /// failure, otherwise a successful execution returns zero. Bytes returned from contract
594 /// execution are set to `result_size` pointer
595 ///
596 /// # Arguments
597 ///
598 /// * `contract_package_hash_ptr` - pointer to serialized contract package hash.
599 /// * `contract_package_hash_size` - size of contract package hash in serialized form.
600 /// * `contract_version_ptr` - Contract package hash in a serialized form
601 /// * `contract_version_size` -
602 /// * `entry_point_name_ptr` -
603 /// * `entry_point_name_size` -
604 /// * `runtime_args_ptr` -
605 /// * `runtime_args_size` -
606 /// * `result_size` -
607 pub fn casper_call_versioned_contract(
608 contract_package_hash_ptr: *const u8,
609 contract_package_hash_size: usize,
610 contract_version_ptr: *const u8,
611 contract_version_size: usize,
612 entry_point_name_ptr: *const u8,
613 entry_point_name_size: usize,
614 runtime_args_ptr: *const u8,
615 runtime_args_size: usize,
616 result_size: *mut usize,
617 ) -> i32;
618 /// This function queries the host side to check for given named argument existence and returns
619 /// a size in bytes of given argument. Returns zero for success or non-zero value for
620 /// failure as described in standard error codes.
621 ///
622 /// # Arguments
623 ///
624 /// * `name_ptr` - pointer (offset in wasm memory) to the location where serialized argument
625 /// name is present
626 /// * `name_size` - size of serialized bytes of argument name
627 /// * `dest_ptr` - pointer to the location where argument bytes will be copied from the host
628 /// side
629 /// * `dest_size` - size of destination pointer
630 pub fn casper_get_named_arg_size(
631 name_ptr: *const u8,
632 name_size: usize,
633 dest_size: *mut usize,
634 ) -> i32;
635 /// This function copies the contents of the current runtime buffer into the
636 /// wasm memory, beginning at the provided offset. It is intended that this
637 /// function be called after a call to `load_arg`. It is up to the caller to
638 /// ensure that the proper amount of memory is allocated for this write,
639 /// otherwise data corruption in the wasm memory may occur due to this call
640 /// overwriting some bytes unintentionally. The size of the data which will be
641 /// written is returned from the `load_arg` call. The bytes which are written
642 /// are the those corresponding to the provided argument; it is up to the
643 /// developer to know how to attempt to interpret those bytes.
644 ///
645 /// # Arguments
646 ///
647 /// * `name_ptr` - pointer (offset in wasm memory) to the location where serialized argument
648 /// name is present
649 /// * `name_size` - size of serialized bytes of argument name
650 /// * `dest_ptr` - pointer to the location where argument bytes will be copied from the host
651 /// side
652 /// * `dest_size` - size of destination pointer
653 pub fn casper_get_named_arg(
654 name_ptr: *const u8,
655 name_size: usize,
656 dest_ptr: *mut u8,
657 dest_size: usize,
658 ) -> i32;
659 /// Removes group from given contract package.
660 ///
661 /// # Arguments
662 ///
663 /// * `contract_package_hash_ptr` - pointer to serialized contract package hash.
664 /// * `contract_package_hash_size` - size of contract package hash in serialized form.
665 /// * `label_ptr` - serialized group label
666 /// * `label_size` - size of serialized group label
667 pub fn casper_remove_contract_user_group(
668 contract_package_hash_ptr: *const u8,
669 contract_package_hash_size: usize,
670 label_ptr: *const u8,
671 label_size: usize,
672 ) -> i32;
673 /// Requests host to provision additional [`casper_types::URef`] to a specified group
674 /// identified by its label. Returns standard error code for non-zero value, otherwise zero
675 /// indicated success.
676 ///
677 /// # Arguments
678 ///
679 /// * `contract_package_hash_ptr` - pointer to serialized contract package hash.
680 /// * `contract_package_hash_size` - size of contract package hash in serialized form.
681 /// * `label_ptr` - serialized group label
682 /// * `label_size` - size of serialized group label
683 /// * `value_size_ptr` - size of data written to a host buffer will be saved here
684 pub fn casper_provision_contract_user_group_uref(
685 contract_package_hash_ptr: *const u8,
686 contract_package_hash_size: usize,
687 label_ptr: *const u8,
688 label_size: usize,
689 value_size_ptr: *const usize,
690 ) -> i32;
691 /// Removes user group urefs. Accepts a contract package hash, label name of a group, and a list
692 /// of urefs that will be removed from the group.
693 ///
694 /// # Arguments
695 ///
696 /// * `contract_package_hash_ptr` - pointer to serialized contract package hash.
697 /// * `contract_package_hash_size` - size of contract package hash in serialized form.
698 /// * `label_ptr` - serialized group label
699 /// * `label_size` - size of serialized group label
700 /// * `urefs_ptr` - pointer to serialized list of urefs
701 /// * `urefs_size` - size of serialized list of urefs
702 pub fn casper_remove_contract_user_group_urefs(
703 contract_package_hash_ptr: *const u8,
704 contract_package_hash_size: usize,
705 label_ptr: *const u8,
706 label_size: usize,
707 urefs_ptr: *const u8,
708 urefs_size: usize,
709 ) -> i32;
710 /// Returns a 32-byte BLAKE2b hash digest from the given input bytes
711 ///
712 /// # Arguments
713 /// * `in_ptr` - pointer to bytes
714 /// * `in_size` - length of bytes
715 /// * `out_ptr` - pointer to the location where argument bytes will be copied from the host side
716 /// * `out_size` - size of output pointer
717 #[deprecated(note = "Superseded by ext_ffi::casper_generic_hash")]
718 pub fn casper_blake2b(
719 in_ptr: *const u8,
720 in_size: usize,
721 out_ptr: *mut u8,
722 out_size: usize,
723 ) -> i32;
724 /// Returns the elements on the call stack tracked by the runtime
725 ///
726 /// # Arguments
727 /// * `call_stack_len_ptr` - pointer to the length of the caller information.
728 /// * `result_size_ptr` - pointer to the size of the serialized caller information.
729 #[deprecated]
730 pub fn casper_load_call_stack(
731 call_stack_len_ptr: *mut usize,
732 result_size_ptr: *mut usize,
733 ) -> i32;
734 /// Prints data directly to standard output on the host.
735 ///
736 /// # Arguments
737 ///
738 /// * `text_ptr` - pointer to serialized text to print
739 /// * `text_size` - size of serialized text to print
740 #[cfg(feature = "test-support")]
741 pub fn casper_print(text_ptr: *const u8, text_size: usize);
742 /// Creates new URef that points to a dictionary partition of global state.
743 ///
744 /// # Arguments
745 ///
746 /// * `output_size` - pointer to a value where host will write size of bytes of created URef.
747 pub fn casper_new_dictionary(output_size_ptr: *mut usize) -> i32;
748 /// The bytes in wasm memory from offset `key_ptr` to `key_ptr + key_size`
749 /// will be used together with the current context’s seed to form a dictionary.
750 /// The value at that dictionary is read from the global state, serialized and
751 /// buffered in the runtime. This result can be obtained via the [`casper_read_host_buffer`]
752 /// function.
753 ///
754 /// # Arguments
755 ///
756 /// * `uref_ptr` - pointer to bytes representing the user-defined key
757 /// * `uref_size` - size of the key (in bytes)
758 /// * `key_bytes_ptr` - pointer to bytes representing the user-defined key
759 /// * `key_bytes_size` - size of the user-defined key
760 /// * `output_size` - pointer to a value where host will write size of bytes read from given key
761 pub fn casper_dictionary_get(
762 uref_ptr: *const u8,
763 uref_size: usize,
764 key_bytes_ptr: *const u8,
765 key_bytes_size: usize,
766 output_size: *mut usize,
767 ) -> i32;
768 /// The bytes in the span of wasm memory from `key_ptr` to `key_ptr + key_size` must correspond
769 /// to a valid global state dictionary key, otherwise the function will fail.
770 /// If the Key::Dictionary is de-serialized successfully, then the result of the read is
771 /// serialized and buffered in the runtime. This result can be obtained via the
772 /// [`casper_read_host_buffer`] function. Returns standard error code.
773 ///
774 /// # Arguments
775 ///
776 /// * `key_ptr` - pointer (offset in wasm linear memory) to serialized form of the
777 /// Key::Dictionary to read
778 /// * `key_size` - size of the serialized Key::Dictionary (in bytes)
779 /// * `output_size` - pointer to a value where host will write size of bytes read from given key
780 pub fn casper_dictionary_read(
781 key_ptr: *const u8,
782 key_size: usize,
783 output_size: *mut usize,
784 ) -> i32;
785 /// The bytes in wasm memory from offset `key_ptr` to `key_ptr + key_size`
786 /// will be used together with the passed URef's seed to form a dictionary.
787 /// This function writes the provided value (read via de-serializing the bytes
788 /// in wasm memory from offset `value_ptr` to `value_ptr + value_size`) under
789 /// that dictionary in the global state. This function will cause a `Trap` if
790 /// the value fails to de-serialize.
791 ///
792 /// # Arguments
793 ///
794 /// * `uref_ptr` - pointer to bytes representing the user-defined key
795 /// * `uref_size` - size of the key (in bytes)
796 /// * `key_ptr` - pointer to bytes representing the user-defined key to write to
797 /// * `key_size` - size of the key (in bytes)
798 /// * `value_ptr` - pointer to bytes representing the value to write at the key
799 /// * `value_size` - size of the value (in bytes)
800 pub fn casper_dictionary_put(
801 uref_ptr: *const u8,
802 uref_size: usize,
803 key_ptr: *const u8,
804 key_size: usize,
805 value_ptr: *const u8,
806 value_size: usize,
807 ) -> i32;
808 /// Returns 32 pseudo random bytes.
809 ///
810 /// # Arguments
811 /// * `out_ptr` - pointer to the location where argument bytes will be copied from the host side
812 /// * `out_size` - size of output pointer
813 pub fn casper_random_bytes(out_ptr: *mut u8, out_size: usize) -> i32;
814 /// Enables contract in a contract package. Returns non-zero standard error for a failure,
815 /// otherwise a zero indicates success.
816 ///
817 /// # Arguments
818 ///
819 /// * `contract_package_hash_ptr` - pointer to serialized contract package hash.
820 /// * `contract_package_hash_size` - size of contract package hash in serialized form.
821 /// * `contract_hash_ptr` - pointer to serialized contract hash.
822 /// * `contract_hash_size` - size of contract hash in serialized form.
823 pub fn casper_enable_contract_version(
824 contract_package_hash_ptr: *const u8,
825 contract_package_hash_size: usize,
826 contract_hash_ptr: *const u8,
827 contract_hash_size: usize,
828 ) -> i32;
829 /// Manages a message topic.
830 ///
831 /// # Arguments
832 ///
833 /// * `topic_name_ptr` - pointer to the topic name UTF-8 string.
834 /// * `topic_name_size` - size of the serialized name string.
835 /// * `operation_ptr` - pointer to the management operation to be performed for the specified
836 /// topic.
837 /// * `operation_ptr_size` - size of the operation.
838 pub fn casper_manage_message_topic(
839 topic_name_ptr: *const u8,
840 topic_name_size: usize,
841 operation_ptr: *const u8,
842 operation_size: usize,
843 ) -> i32;
844 /// Emits a new message on the specified topic.
845 ///
846 /// # Arguments
847 ///
848 /// * `topic_name_ptr` - pointer to the topic name UTF-8 string where the message will be
849 /// emitted.
850 /// * `topic_name_size` - size of the serialized name string.
851 /// * `message_ptr` - pointer to the serialized message payload to be emitted.
852 /// * `message_size` - size of the serialized message payload.
853 pub fn casper_emit_message(
854 topic_name_ptr: *const u8,
855 topic_name_size: usize,
856 message_ptr: *const u8,
857 message_size: usize,
858 ) -> i32;
859
860 /// Returns information about the current call stack tracked by the runtime
861 /// based on an action
862 /// `0` => Initiator of the call chain
863 /// `1` => Immediate caller
864 /// `2` => The entire call stack
865 ///
866 /// # Arguments
867 /// `action`: u8 which encodes the information requested by the caller.
868 /// * `call_stack_len_ptr` - pointer to the length of the caller information.
869 /// * `result_size_ptr` - pointer to the size of the serialized caller information.
870 pub fn casper_load_caller_information(
871 action: u8,
872 call_stack_len_ptr: *mut usize,
873 result_size_ptr: *mut usize,
874 ) -> i32;
875
876 /// This function gets the requested field at `field_idx`. It is up to
877 /// the caller to ensure that the correct number of bytes for the field data
878 /// are allocated at `dest_ptr`, otherwise data corruption in the wasm memory may occur.
879 ///
880 /// # Arguments
881 ///
882 /// * `field_idx` - what info field is requested?
883 /// * 0 => block time (functionally equivalent to earlier get_blocktime ffi)
884 /// * 1 => block height
885 /// * 2 => parent block hash
886 /// * 3 => state hash
887 /// * 4 => current protocol version
888 /// * 5 => is addressable entity enabled
889 /// * `dest_ptr` => pointer in wasm memory where to write the result
890 pub fn casper_get_block_info(field_idx: u8, dest_ptr: *const u8);
891
892 /// Computes digest hash, using provided algorithm type.
893 ///
894 /// # Arguments
895 ///
896 /// * `in_ptr` - pointer to the location where argument bytes will be copied from the host side
897 /// * `in_size` - size of output pointer
898 /// * `hash_algo_type` - integer representation of HashAlgorithm enum variant
899 /// * `out_ptr` - pointer to the location where argument bytes will be copied to the host side
900 /// * `out_size` - size of output pointer
901 pub fn casper_generic_hash(
902 in_ptr: *const u8,
903 in_size: usize,
904 hash_algo_type: u8,
905 out_ptr: *const u8,
906 out_size: usize,
907 ) -> i32;
908
909 /// Recovers a Secp256k1 public key from a signed message
910 /// and a signature used in the process of signing.
911 ///
912 /// # Arguments
913 ///
914 /// * `message_ptr` - pointer to the signed data
915 /// * `message_size` - length of the signed data in bytes
916 /// * `signature_ptr` - pointer to byte-encoded signature
917 /// * `signature_size` - length of the byte-encoded signature
918 /// * `out_ptr` - pointer to a buffer of size PublicKey::SECP256K1_LENGTH which will be
919 /// populated with the recovered key's bytes representation
920 /// * `recovery_id` - an integer value 0, 1, 2, or 3 used to select the correct public key from
921 /// the signature:
922 /// - Low bit (0/1): was the y-coordinate of the affine point resulting from the fixed-base
923 /// multiplication 𝑘×𝑮 odd?
924 /// - Hi bit (3/4): did the affine x-coordinate of 𝑘×𝑮 overflow the order of the scalar field,
925 /// requiring a reduction when computing r?
926 pub fn casper_recover_secp256k1(
927 message_ptr: *const u8,
928 message_size: usize,
929 signature_ptr: *const u8,
930 signature_size: usize,
931 out_ptr: *const u8,
932 recovery_id: u8,
933 ) -> i32;
934
935 /// Verifies the signature of the given message against the given public key.
936 ///
937 /// # Arguments
938 ///
939 /// * `message_ptr` - pointer to the signed data
940 /// * `message_size` - length of the signed data in bytes
941 /// * `signature_ptr` - pointer to byte-encoded signature
942 /// * `signature_size` - length of the byte-encoded signature
943 /// * `public_key_ptr` - pointer to byte-encoded public key
944 /// * `public_key_size` - length of the byte-encoded public key
945 pub fn casper_verify_signature(
946 message_ptr: *const u8,
947 message_size: usize,
948 signature_ptr: *const u8,
949 signature_size: usize,
950 public_key_ptr: *const u8,
951 public_key_size: usize,
952 ) -> i32;
953 /// Calls a contract by its package hash. Requires both a major and contract version. Requires
954 /// an entry point name registered in a given version of contract. Returns a standard error
955 /// code in case of failure, otherwise a successful execution returns zero. Bytes returned
956 /// from contract execution are set to `result_size` pointer
957 ///
958 /// # Arguments
959 ///
960 /// * `contract_package_hash_ptr` - pointer to serialized contract package hash.
961 /// * `contract_package_hash_size` - size of contract package hash in serialized form.
962 /// * `contract_version_ptr` - Contract package hash in a serialized form
963 /// * `contract_version_size` -
964 /// * `entry_point_name_ptr` -
965 /// * `entry_point_name_size` -
966 /// * `runtime_args_ptr` -
967 /// * `runtime_args_size` -
968 /// * `result_size` -
969 pub fn casper_call_package_version(
970 contract_package_hash_ptr: *const u8,
971 contract_package_hash_size: usize,
972 major_version_ptr: *const u8,
973 major_version_size: usize,
974 contract_version_ptr: *const u8,
975 contract_version_size: usize,
976 entry_point_name_ptr: *const u8,
977 entry_point_name_size: usize,
978 runtime_args_ptr: *const u8,
979 runtime_args_size: usize,
980 result_size: *mut usize,
981 ) -> i32;
982}