From a564d7350cffe0eb3a43b4f210413948eafcfb1f Mon Sep 17 00:00:00 2001 From: Nicholas Ward Date: Mon, 12 Dec 2022 17:29:56 -0800 Subject: [PATCH] fixes and addressed comments --- .../kernel/asm/hash/blake2b/compression.asm | 16 +++++----- .../kernel/asm/hash/blake2b/permutations.asm | 14 ++++---- evm/src/cpu/kernel/asm/util/basic_macros.asm | 32 ------------------- 3 files changed, 15 insertions(+), 47 deletions(-) diff --git a/evm/src/cpu/kernel/asm/hash/blake2b/compression.asm b/evm/src/cpu/kernel/asm/hash/blake2b/compression.asm index e7b81072..3c700eb3 100644 --- a/evm/src/cpu/kernel/asm/hash/blake2b/compression.asm +++ b/evm/src/cpu/kernel/asm/hash/blake2b/compression.asm @@ -235,35 +235,35 @@ compression_end: // stack: h_0', h_1', h_2', h_3', h_4', h_5', h_6', h_7', cur_block + 1, retdest // Invert the bytes of each hash value. - %reverse_bytes_u64_blake + %reverse_bytes_u64 // stack: h_0'', h_1', h_2', h_3', h_4', h_5', h_6', h_7', cur_block + 1, retdest SWAP1 // stack: h_1', h_0'', h_2', h_3', h_4', h_5', h_6', h_7', cur_block + 1, retdest - %reverse_bytes_u64_blake + %reverse_bytes_u64 // stack: h_1'', h_0'', h_2', h_3', h_4', h_5', h_6', h_7', cur_block + 1, retdest SWAP2 // stack: h_2', h_0'', h_1'', h_3', h_4', h_5', h_6', h_7', cur_block + 1, retdest - %reverse_bytes_u64_blake + %reverse_bytes_u64 // stack: h_2'', h_0'', h_1'', h_3', h_4', h_5', h_6', h_7', cur_block + 1, retdest SWAP3 // stack: h_3', h_0'', h_1'', h_2'', h_4', h_5', h_6', h_7', cur_block + 1, retdest - %reverse_bytes_u64_blake + %reverse_bytes_u64 // stack: h_3'', h_0'', h_1'', h_2'', h_4', h_5', h_6', h_7', cur_block + 1, retdest SWAP4 // stack: h_4', h_0'', h_1'', h_2'', h_3'', h_5', h_6', h_7', cur_block + 1, retdest - %reverse_bytes_u64_blake + %reverse_bytes_u64 // stack: h_4'', h_0'', h_1'', h_2'', h_3'', h_5', h_6', h_7', cur_block + 1, retdest SWAP5 // stack: h_5', h_0'', h_1'', h_2'', h_3'', h_4'', h_6', h_7', cur_block + 1, retdest - %reverse_bytes_u64_blake + %reverse_bytes_u64 // stack: h_5'', h_0'', h_1'', h_2'', h_3'', h_4'', h_6', h_7', cur_block + 1, retdest SWAP6 // stack: h_6', h_0'', h_1'', h_2'', h_3'', h_4'', h_5'', h_7', cur_block + 1, retdest - %reverse_bytes_u64_blake + %reverse_bytes_u64 // stack: h_6'', h_0'', h_1'', h_2'', h_3'', h_4'', h_5'', h_7', cur_block + 1, retdest SWAP7 // stack: h_7', h_0'', h_1'', h_2'', h_3'', h_4'', h_5'', h_6'', cur_block + 1, retdest - %reverse_bytes_u64_blake + %reverse_bytes_u64 // stack: h_7'', h_0'', h_1'', h_2'', h_3'', h_4'', h_5'', h_6'', cur_block + 1, retdest %stack (h_7, h_s: 7) -> (h_s, h_7) // stack: h_0'', h_1'', h_2'', h_3'', h_4'', h_5'', h_6'', h_7'', cur_block + 1, retdest diff --git a/evm/src/cpu/kernel/asm/hash/blake2b/permutations.asm b/evm/src/cpu/kernel/asm/hash/blake2b/permutations.asm index d3d2b0e4..5277e611 100644 --- a/evm/src/cpu/kernel/asm/hash/blake2b/permutations.asm +++ b/evm/src/cpu/kernel/asm/hash/blake2b/permutations.asm @@ -13,12 +13,12 @@ global permutation_1_constants: global permutation_2_constants: BYTES 11, 8, 12, 0 BYTES 5, 2, 15, 13 - BYTES 10, 4, 3, 6 + BYTES 10, 14, 3, 6 BYTES 7, 1, 9, 4 global permutation_3_constants: BYTES 7, 9, 3, 1 - BYTES 13, 2, 11, 14 + BYTES 13, 12, 11, 14 BYTES 2, 6, 5, 10 BYTES 4, 0, 15, 8 @@ -29,14 +29,14 @@ global permutation_4_constants: BYTES 6, 8, 3, 13 global permutation_5_constants: - BYTES 2, 2, 6, 10 - BYTES 0, 1, 8, 3 - BYTES 4, 3, 7, 5 - BYTES 15, 4, 1, 9 + BYTES 2, 12, 6, 10 + BYTES 0, 11, 8, 3 + BYTES 4, 13, 7, 5 + BYTES 15, 14, 1, 9 global permutation_6_constants: BYTES 12, 5, 1, 15 - BYTES 14, 3, 4, 10 + BYTES 14, 13, 4, 10 BYTES 0, 7, 6, 3 BYTES 9, 2, 8, 11 diff --git a/evm/src/cpu/kernel/asm/util/basic_macros.asm b/evm/src/cpu/kernel/asm/util/basic_macros.asm index aa6b908e..2a7473fd 100644 --- a/evm/src/cpu/kernel/asm/util/basic_macros.asm +++ b/evm/src/cpu/kernel/asm/util/basic_macros.asm @@ -335,35 +335,3 @@ OR // stack: word_inverted %endmacro - - -// Invert the order of the four bytes in a word. -%macro invert_four_byte_word - // stack: word - %mul_const(0x1000000010000000100) - %and_const(0xff0000ff00ff00000000ff0000) - %mod_const(0xffffffffffff) - // stack: word_inverted -%endmacro - -// Invert the order of the eight bytes in a Blake word. -%macro reverse_bytes_u64_blake - // stack: word - DUP1 - // stack: word, word - %and_const(0xffffffff) - // stack: word_lo, word - SWAP1 - // stack: word, word_lo - %shr_const(32) - // stack: word_hi, word_lo - %invert_four_byte_word - // stack: word_hi_inverted, word_lo - SWAP1 - // stack: word_lo, word_hi_inverted - %invert_four_byte_word - // stack: word_lo_inverted, word_hi_inverted - %shl_const(32) - OR - // stack: word_inverted -%endmacro \ No newline at end of file