hash_native.adl
1 /* 2 namespace: Compile 3 expectation: Pass 4 */ 5 6 program test.alpha { 7 // Test native hash functions that return bit arrays 8 transition main(input: u64) -> ( 9 bool, bool, bool, bool, // Keccak256 native samples 10 bool, bool, // Keccak384 native samples 11 bool, bool, // Keccak512 native samples 12 bool, bool, // SHA3-256 native samples 13 bool, bool, // SHA3-384 native samples 14 bool, bool, // SHA3-512 native samples 15 bool, bool // Comparison flags 16 ) { 17 // Keccak256 hash_to_bits - returns [bool; 256] 18 let keccak256_bits: [bool; 256] = Keccak256::hash_to_bits(input); 19 let keccak256_0: bool = keccak256_bits[0u8]; 20 let keccak256_100: bool = keccak256_bits[100u8]; 21 let keccak256_200: bool = keccak256_bits[200u8]; 22 let keccak256_255: bool = keccak256_bits[255u8]; 23 24 // Keccak384 hash_to_bits - returns [bool; 384] 25 let keccak384_bits: [bool; 384] = Keccak384::hash_to_bits(input); 26 let keccak384_0: bool = keccak384_bits[0u16]; 27 let keccak384_383: bool = keccak384_bits[383u16]; 28 29 // Keccak512 hash_to_bits - returns [bool; 512] 30 let keccak512_bits: [bool; 512] = Keccak512::hash_to_bits(input); 31 let keccak512_0: bool = keccak512_bits[0u16]; 32 let keccak512_511: bool = keccak512_bits[511u16]; 33 34 // SHA3-256 hash_to_bits - returns [bool; 256] 35 let sha3_256_bits: [bool; 256] = SHA3_256::hash_to_bits(input); 36 let sha3_256_0: bool = sha3_256_bits[0u8]; 37 let sha3_256_255: bool = sha3_256_bits[255u8]; 38 39 // SHA3-384 hash_to_bits - returns [bool; 384] 40 let sha3_384_bits: [bool; 384] = SHA3_384::hash_to_bits(input); 41 let sha3_384_0: bool = sha3_384_bits[0u16]; 42 let sha3_384_383: bool = sha3_384_bits[383u16]; 43 44 // SHA3-512 hash_to_bits - returns [bool; 512] 45 let sha3_512_bits: [bool; 512] = SHA3_512::hash_to_bits(input); 46 let sha3_512_0: bool = sha3_512_bits[0u16]; 47 let sha3_512_511: bool = sha3_512_bits[511u16]; 48 49 // Test that native and native_raw produce different results 50 let keccak256_bits_raw: [bool; 256] = Keccak256::hash_to_bits_raw(input); 51 let sha3_256_bits_raw: [bool; 256] = SHA3_256::hash_to_bits_raw(input); 52 53 return ( 54 keccak256_0, keccak256_100, keccak256_200, keccak256_255, 55 keccak384_0, keccak384_383, 56 keccak512_0, keccak512_511, 57 sha3_256_0, sha3_256_255, 58 sha3_384_0, sha3_384_383, 59 sha3_512_0, sha3_512_511, 60 keccak256_bits[0u8] != keccak256_bits_raw[0u8], 61 sha3_256_bits[0u8] != sha3_256_bits_raw[0u8] 62 ); 63 } 64 }