diff --git a/evm/src/cpu/kernel/asm/ripemd/memory.asm b/evm/src/cpu/kernel/asm/ripemd/memory.asm index e3d3141a..c5188b16 100644 --- a/evm/src/cpu/kernel/asm/ripemd/memory.asm +++ b/evm/src/cpu/kernel/asm/ripemd/memory.asm @@ -30,7 +30,7 @@ store_size: store_padding: // stack: i (init 63) %store_zeros(136, store_padding) - %jumpi(store_input_alt) + %jump(store_input_alt) %jump(ripemd_init) store_input_alt: diff --git a/evm/src/cpu/kernel/asm/ripemd/ripemd.asm b/evm/src/cpu/kernel/asm/ripemd/ripemd.asm index d0afb6d0..6c3c0397 100644 --- a/evm/src/cpu/kernel/asm/ripemd/ripemd.asm +++ b/evm/src/cpu/kernel/asm/ripemd/ripemd.asm @@ -36,8 +36,8 @@ global ripemd_init: // stack: length %stack (length) -> ( 0, length, 136, ripemd_1, ripemd_2, process) // stack: count = 0, length, virt = 136, ripemd_1, ripemd_2, process - %stack (ARGS: 3, LABELS: 3) -> (0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476, 0xC3D2E1F0, ARGS, LABELS) - // stack: 0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476, 0xC3D2E1F0, count, length, virt, LABELS + %stack () -> (0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476, 0xC3D2E1F0) + // stack: 0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476, 0xC3D2E1F0, count, length, virt, LABELS %jump(ripemd_update) ripemd_1: // stack: STATE, count, length , virt , LABELS diff --git a/evm/src/cpu/kernel/asm/ripemd/update.asm b/evm/src/cpu/kernel/asm/ripemd/update.asm index a5132d7c..03d1c5c5 100644 --- a/evm/src/cpu/kernel/asm/ripemd/update.asm +++ b/evm/src/cpu/kernel/asm/ripemd/update.asm @@ -91,19 +91,19 @@ update_1a: /// cond -= 64 update_2: - // stack: STATE, shift, need, have, count, length, virt, retdest + // stack: STATE, shift, need, have, count, length, virt, retdest %stack (STATE: 5, shift, need, have, count, length) -> (length, shift, STATE, shift, need, have, count, length) SUB %ge_const(64) - // stack: cond, STATE, shift, need, have, count, length, virt, retdest + // stack: cond, STATE, shift, need, have, count, length, virt, retdest DUP12 DUP8 ADD - // stack: offset, cond, STATE, shift, need, have, count, length, virt, retdest + // stack: offset, cond, STATE, shift, need, have, count, length, virt, retdest %stack (offset, cond, STATE: 5) -> (cond, STATE, offset, compression_loop) // stack: cond, STATE, offset, compression_loop, shift, need, have, count, length, virt, retdest %jumpi(compress) - %stack (STATE:5, offset, compression_loop) -> (STATE, offset) + %stack (STATE: 5, offset, compression_loop) -> (STATE, offset) %jump(final_update) compression_loop: // stack: STATE, offset , cond , shift, need, have, count, length, virt, retdest diff --git a/evm/src/cpu/kernel/tests/ripemd.rs b/evm/src/cpu/kernel/tests/ripemd.rs index bdd2b4af..5a70b8ba 100644 --- a/evm/src/cpu/kernel/tests/ripemd.rs +++ b/evm/src/cpu/kernel/tests/ripemd.rs @@ -13,14 +13,23 @@ fn make_input(word: &str) -> Vec { #[test] fn test_ripemd() -> Result<()> { - let input: Vec = make_input(""); - let expected = U256::from("0x9c1185a5c5e9fc54612808977ee8f548b2258d31"); + // let input: Vec = make_input("12345678901234567890123456789012345678901234567890123456789012345678901234567890"); + // let expected = U256::from("0x9b752e45573d4b39f4dbd3323cab82bf63326bfb"); + + let input: Vec = make_input("abcdefghijklmnopqrstuvwxyz"); + let expected = U256::from("0xf71c27109c692c1b56bbdceb5b9d2865b3708dbc"); + let kernel = combined_kernel(); let label = kernel.global_labels["ripemd_alt"]; let stack_input: Vec = input.iter().map(|&x| U256::from(x as u8)).rev().collect(); - let output: U256 = run_with_kernel(&kernel, label, stack_input)?.stack()[0]; - assert_eq!(output, expected); + let stack_output: Vec = run_with_kernel(&kernel, label, stack_input)?.stack().to_vec(); + + let read_out: Vec = stack_output.iter().map(|x| format!("{:x}", x)).rev().collect(); + println!("{:x?}", read_out); + + let actual = stack_output[0]; + assert_eq!(actual, expected); Ok(()) }