git.delta.rocks / unique-network / refs/commits / e8fdadb89923

difftreelog

source

pallets/contracts/fixtures/crypto_hashes.wat3.0 KiBsourcehistory
1(module2	(import "seal0" "seal_input" (func $seal_input (param i32 i32)))3	(import "seal0" "seal_return" (func $seal_return (param i32 i32 i32)))45	(import "seal0" "seal_hash_sha2_256" (func $seal_hash_sha2_256 (param i32 i32 i32)))6	(import "seal0" "seal_hash_keccak_256" (func $seal_hash_keccak_256 (param i32 i32 i32)))7	(import "seal0" "seal_hash_blake2_256" (func $seal_hash_blake2_256 (param i32 i32 i32)))8	(import "seal0" "seal_hash_blake2_128" (func $seal_hash_blake2_128 (param i32 i32 i32)))910	(import "env" "memory" (memory 1 1))1112	(type $hash_fn_sig (func (param i32 i32 i32)))13	(table 8 funcref)14	(elem (i32.const 1)15		$seal_hash_sha2_25616		$seal_hash_keccak_25617		$seal_hash_blake2_25618		$seal_hash_blake2_12819	)20	(data (i32.const 1) "20202010201008") ;; Output sizes of the hashes in order in hex.2122	;; Not in use by the tests besides instantiating the contract.23	(func (export "deploy"))2425	;; Called by the tests.26	;;27	;; The `call` function expects data in a certain format in the input buffer.28	;;29	;; 1. The first byte encodes an identifier for the crypto hash function30	;;    under test. (*)31	;; 2. The rest encodes the input data that is directly fed into the32	;;    crypto hash function chosen in 1.33	;;34	;; The `deploy` function then computes the chosen crypto hash function35	;; given the input and puts the result into the output buffer.36	;; After contract execution the test driver then asserts that the returned37	;; values are equal to the expected bytes for the input and chosen hash38	;; function.39	;;40	;; (*) The possible value for the crypto hash identifiers can be found below:41	;;42	;; | value | Algorithm | Bit Width |43	;; |-------|-----------|-----------|44	;; |     0 |      SHA2 |       256 |45	;; |     1 |    KECCAK |       256 |46	;; |     2 |    BLAKE2 |       256 |47	;; |     3 |    BLAKE2 |       128 |48	;; ---------------------------------49	(func (export "call")50		(local $chosen_hash_fn i32)51		(local $input_len_ptr i32)52		(local $input_ptr i32)53		(local $input_len i32)54		(local $output_ptr i32)55		(local $output_len i32)56		(local.set $input_len_ptr (i32.const 256))57		(local.set $input_ptr (i32.const 10))58		(i32.store (local.get $input_len_ptr) (i32.const 246))59		(call $seal_input (local.get $input_ptr) (local.get $input_len_ptr))60		(local.set $chosen_hash_fn (i32.load8_u (local.get $input_ptr)))61		(if (i32.gt_u (local.get $chosen_hash_fn) (i32.const 7))62			;; We check that the chosen hash fn  identifier is within bounds: [0,7]63			(unreachable)64		)65		(local.set $input_ptr (i32.add (local.get $input_ptr) (i32.const 1)))66		(local.set $input_len (i32.sub (i32.load (local.get $input_len_ptr)) (i32.const 1)))67		(local.set $output_len (i32.load8_u (local.get $chosen_hash_fn)))68		(call_indirect (type $hash_fn_sig)69			(local.get $input_ptr)70			(local.get $input_len)71			(local.get $input_ptr)72			(local.get $chosen_hash_fn) ;; Which crypto hash function to execute.73		)74		(call $seal_return75			(i32.const 0)76			(local.get $input_ptr) ;; Linear memory location of the output buffer.77			(local.get $output_len) ;; Number of output buffer bytes.78		)79		(unreachable)80	)81)