forked from paritytech/substrate
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
contracts: add sr25519_verify (paritytech#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 <[email protected]> * 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 <[email protected]> * 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 <[email protected]> * Update frame/contracts/src/schedule.rs Co-authored-by: Sasha Gryaznov <[email protected]> * Update frame/contracts/src/wasm/runtime.rs * Update frame/contracts/src/wasm/runtime.rs Co-authored-by: Sasha Gryaznov <[email protected]> * PR review --------- Co-authored-by: Sasha Gryaznov <[email protected]> Co-authored-by: command-bot <> Co-authored-by: Alexander Theißen <[email protected]>
- Loading branch information
1 parent
ec04256
commit 0898f2a
Showing
8 changed files
with
1,332 additions
and
894 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)) | ||
) | ||
) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.