test compress

This commit is contained in:
Dmitry Vagner 2022-09-22 10:34:32 -07:00
parent f45d6593f9
commit 7342b96583
3 changed files with 42 additions and 22 deletions

View File

@ -177,31 +177,31 @@ box:
// stack: F, b, c, d, pre_rol, a, b, c, d, e, F, K, boxes, rounds, sides, virt
JUMP
pre_rol:
// stack: F(b, c, d), a, b, c, d, e, F, K, boxes, rounds, sides, virt
// stack: F(b, c, d), a, b, c, d, e, F, K, boxes, rounds, sides, virt
ADD
// stack: a, b, c, d, e, F, K, boxes, rounds, sides, virt
// stack: a, b, c, d, e, F, K, boxes, rounds, sides, virt
%get_box
// stack: box, a, b, c, d, e, F, K, boxes, rounds, sides, virt
// stack: box, a, b, c, d, e, F, K, boxes, rounds, sides, virt
DUP1
%mload_kernel_code_label(R_data)
DUP13
ADD
// stack: virt + r, box, a, b, c, d, e, F, K, boxes, rounds, sides, virt
%load_u32_from_block
// stack: x, box, a, b, c, d, e, F, K, boxes, rounds, sides, virt
%mload_kernel_code_label_u32(Input_Block) // %load_u32_from_block
// stack: x, box, a, b, c, d, e, F, K, boxes, rounds, sides, virt
SWAP1
SWAP2
// stack: a, x, box, b, c, d, e, F, K, boxes, rounds, sides, virt
// stack: a, x, box, b, c, d, e, F, K, boxes, rounds, sides, virt
ADD
DUP8
ADD
%u32
// stack: a, box, b, c, d, e, F, K, boxes, rounds, sides, virt
// stack: a, box, b, c, d, e, F, K, boxes, rounds, sides, virt
PUSH mid_rol
SWAP2
// stack: box, a, mid_rol, b, c, d, e, F, K, boxes, rounds, sides, virt
// stack: box, a, mid_rol, b, c, d, e, F, K, boxes, rounds, sides, virt
%mload_kernel_code_label(S_data)
// stack: s, a, mid_rol, b, c, d, e, F, K, boxes, rounds, sides, virt
// stack: s, a, mid_rol, b, c, d, e, F, K, boxes, rounds, sides, virt
%jump(rol)
mid_rol:
// stack: a, b, c, d, e, F, K, boxes, rounds, sides, virt

View File

@ -118,3 +118,22 @@ global R_data:
BYTES 04, 20, 32, 28
BYTES 24, 08, 52, 56
BYTES 00, 12, 36, 44
global Input_Block:
BYTES 0x61, 0x62, 0x63, 0x64
BYTES 0x65, 0x66, 0x67, 0x68
BYTES 0x69, 0x6a, 0x6b, 0x6c
BYTES 0x6d, 0x6e, 0x6f, 0x70
BYTES 0x71, 0x72, 0x73, 0x74
BYTES 0x75, 0x76, 0x77, 0x78
BYTES 0x79, 0x7a, 0x80, 0x00
BYTES 0x00, 0x00, 0x00, 0x00
BYTES 0x00, 0x00, 0x00, 0x00
BYTES 0x00, 0x00, 0x00, 0x00
BYTES 0x00, 0x00, 0x00, 0x00
BYTES 0x00, 0x00, 0x00, 0x00
BYTES 0x00, 0x00, 0x00, 0x00
BYTES 0x00, 0x00, 0x00, 0x00
BYTES 0xd0, 0x00, 0x00, 0x00
BYTES 0x00, 0x00, 0x00, 0x00

View File

@ -4,23 +4,24 @@ use ethereum_types::U256;
use crate::cpu::kernel::aggregator::combined_kernel;
use crate::cpu::kernel::interpreter::run_with_kernel;
#[test]
fn test_ripemd() -> Result<()> {
let expected = "0xf71c27109c692c1b56bbdceb5b9d2865b3708dbc";
println!("{}", expected);
// let expected = "0xf71c27109c692c1b56bbdceb5b9d2865b3708dbc";
let expected: Vec<&str> = vec!["10271CF7", "1B2C699C", "EBDCBB56", "65289D5B", "BC8D70B3"];
println!("{:#?}", expected);
let input: Vec<u32> = vec![0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0, 0, 0xdeadbeef];
// let input: Vec<u32> = vec![
// 0x1a, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e,
// 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a,
// ];
let kernel = combined_kernel();
let input: Vec<u32> = vec![
0x1a, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e,
0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a,
];
let stack_init: Vec<U256> = input.iter().map(|&x| U256::from(x as u32)).rev().collect();
let stack_result = run_with_kernel(&kernel, kernel.global_labels["ripemd_alt"], stack_init)?;
let result = stack_result.stack()[0];
let actual = format!("{:X}", result);
println!("{}", actual);
let stack_input: Vec<U256> = input.iter().map(|&x| U256::from(x as u32)).rev().collect();
let stack_output = run_with_kernel(&kernel, kernel.global_labels["compress"], stack_input)?;
let actual: Vec<String> = stack_output.stack().iter().map(|&x| format!("{:#?}", x)).collect();
println!("{:#?}", actual);
assert_eq!(expected, actual);
Ok(())