mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-31 00:31:02 +00:00
contracts: add sr25519_verify (#13724)
* wip * fix * wip * fix lint * rm fixture fix * missing comment * fix lint * add comment to the wsm file * fix comment * Apply suggestions from code review Co-authored-by: Sasha Gryaznov <hi@agryaznov.com> * wip * wip weights * wip weights * PR comment: test with return code * wip * PR review add mock test * remove * lint * Update frame/contracts/fixtures/sr25519_verify.wat * fix comments * Update frame/contracts/src/benchmarking/mod.rs * Update frame/contracts/src/wasm/runtime.rs * Update frame/contracts/fixtures/sr25519_verify.wat * Update frame/contracts/src/benchmarking/mod.rs * fix lint * ".git/.scripts/commands/bench/bench.sh" pallet dev pallet_contracts * Update frame/contracts/src/wasm/runtime.rs Co-authored-by: Alexander Theißen <alex.theissen@me.com> * PR: review use unstable + remove arbitrary index 4 * Add benchmark for calculating overhead of calling sr25519_verify * fix message length encoding * fix weights * ".git/.scripts/commands/bench/bench.sh" pallet dev pallet_contracts * Apply suggestions from code review * Update frame/contracts/src/wasm/runtime.rs * Update frame/contracts/src/wasm/runtime.rs * Update frame/contracts/src/benchmarking/mod.rs * Update frame/contracts/src/benchmarking/mod.rs * Update frame/contracts/src/schedule.rs Co-authored-by: Sasha Gryaznov <hi@agryaznov.com> * Update frame/contracts/src/schedule.rs Co-authored-by: Sasha Gryaznov <hi@agryaznov.com> * Update frame/contracts/src/wasm/runtime.rs * Update frame/contracts/src/wasm/runtime.rs Co-authored-by: Sasha Gryaznov <hi@agryaznov.com> * PR review --------- Co-authored-by: Sasha Gryaznov <hi@agryaznov.com> Co-authored-by: command-bot <> Co-authored-by: Alexander Theißen <alex.theissen@me.com>
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
;; This contract:
|
||||
;; 1) Reads signature, message and public key from the input
|
||||
;; 2) Calls and return the result of sr25519_verify
|
||||
|
||||
(module
|
||||
;; import the host functions from the seal0 module
|
||||
(import "seal0" "sr25519_verify" (func $sr25519_verify (param i32 i32 i32 i32) (result i32)))
|
||||
(import "seal0" "seal_input" (func $seal_input (param i32 i32)))
|
||||
(import "seal0" "seal_return" (func $seal_return (param i32 i32 i32)))
|
||||
|
||||
;; give the program 1 page of memory
|
||||
(import "env" "memory" (memory 1 1))
|
||||
|
||||
;; [0, 4) length of signature + message + public key - 64 + 11 + 32 = 107 bytes
|
||||
;; write the length of the input (6b = 107) bytes at offset 0
|
||||
(data (i32.const 0) "\6b")
|
||||
|
||||
(func (export "deploy"))
|
||||
|
||||
(func (export "call")
|
||||
;; define local variables
|
||||
(local $signature_ptr i32)
|
||||
(local $pub_key_ptr i32)
|
||||
(local $message_len i32)
|
||||
(local $message_ptr i32)
|
||||
|
||||
;; set the pointers to the memory locations
|
||||
;; Memory layout during `call`
|
||||
;; [10, 74) signature
|
||||
;; [74, 106) public key
|
||||
;; [106, 117) message (11 bytes)
|
||||
(local.set $signature_ptr (i32.const 10))
|
||||
(local.set $pub_key_ptr (i32.const 74))
|
||||
(local.set $message_ptr (i32.const 106))
|
||||
|
||||
;; store the input into the memory, starting at the signature and
|
||||
;; up to 107 bytes stored at offset 0
|
||||
(call $seal_input (local.get $signature_ptr) (i32.const 0))
|
||||
|
||||
;; call sr25519_verify and store the return code
|
||||
(i32.store
|
||||
(i32.const 0)
|
||||
(call $sr25519_verify
|
||||
(local.get $signature_ptr)
|
||||
(local.get $pub_key_ptr)
|
||||
(i32.const 11)
|
||||
(local.get $message_ptr)
|
||||
)
|
||||
)
|
||||
|
||||
;; exit with success and take transfer return code to the output buffer
|
||||
(call $seal_return (i32.const 0) (i32.const 0) (i32.const 4))
|
||||
)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user