mirror of
https://github.com/logos-storage/plonky2.git
synced 2026-01-10 17:53:06 +00:00
majorly simplify update2
This commit is contained in:
parent
9b59d02dad
commit
29b2552fac
@ -85,43 +85,28 @@ update_1a:
|
||||
%jump(compress)
|
||||
|
||||
/// def update_2():
|
||||
/// while length - shift >= 64:
|
||||
/// state = compress(state, bytestring[shift:])
|
||||
/// while length >= shift + 64:
|
||||
/// shift += 64
|
||||
/// cond -= 64
|
||||
/// state = compress(state, bytestring[shift-64:])
|
||||
|
||||
update_2:
|
||||
// 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
|
||||
DUP12
|
||||
DUP8
|
||||
// stack: STATE, shift, need, have, count, length, virt, retdest
|
||||
%stack (STATE: 5, shift, need, have, count, length) -> (64, shift, length, STATE, shift, need, have, count, length)
|
||||
ADD
|
||||
// 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)
|
||||
%jump(final_update)
|
||||
compression_loop:
|
||||
// stack: STATE, offset , cond , shift, need, have, count, length, virt, retdest
|
||||
GT
|
||||
// stack: cond, STATE, shift, need, have, count, length, virt, retdest
|
||||
%jumpi(final_update)
|
||||
SWAP5
|
||||
%add_const(64)
|
||||
SWAP5
|
||||
SWAP6
|
||||
%sub_const(64)
|
||||
SWAP6
|
||||
SWAP7
|
||||
%add_const(64)
|
||||
SWAP7
|
||||
// stack: STATE, offset+64, cond-64, shift+64, need, have, count, length, virt, retdest
|
||||
%stack (STATE: 5, offset, cond, shift) -> (cond, 0, STATE, offset, compression_loop, cond, shift)
|
||||
%jumpi(compress)
|
||||
// stack: STATE, offset , label, cond , shift , need, have, count, length, virt, retdest
|
||||
%stack (STATE: 5, offset, label, cond, shift, need, have, count, length, virt, retdest) -> (shift, need, have, STATE, count, length, virt, retdest)
|
||||
%jump(final_update)
|
||||
SWAP5
|
||||
%stack (STATE: 5, shift) -> (shift, 64, STATE)
|
||||
DUP14
|
||||
ADD
|
||||
SUB
|
||||
// stack: offset, STATE, shift, need, have, count, length, virt, retdest
|
||||
%stack (offset, STATE: 5) -> (STATE, offset, update_2)
|
||||
// stack: STATE, offset, update_2, shift, need, have, count, length, virt, retdest
|
||||
%jump(compress)
|
||||
|
||||
|
||||
/// def buffer_update(get, set, times):
|
||||
|
||||
@ -12,8 +12,6 @@ fn make_input(word: &str) -> Vec<u8> {
|
||||
|
||||
#[test]
|
||||
fn test_ripemd() -> Result<()> {
|
||||
// let input: Vec<u8> = make_input("12345678901234567890123456789012345678901234567890123456789012345678901234567890");
|
||||
// let expected = U256::from("0x9b752e45573d4b39f4dbd3323cab82bf63326bfb");
|
||||
let reference = vec![
|
||||
("", "0x9c1185a5c5e9fc54612808977ee8f548b2258d31"),
|
||||
("a", "0x0bdc9d2d256b3ee9daae347be6f4dc835a467ffe"),
|
||||
@ -34,6 +32,10 @@ fn test_ripemd() -> Result<()> {
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
|
||||
"0xb0e20b6e3116640286ed3a87a5713079b21f5189",
|
||||
),
|
||||
// (
|
||||
// "12345678901234567890123456789012345678901234567890123456789012345678901234567890",
|
||||
// "0x9b752e45573d4b39f4dbd3323cab82bf63326bfb",
|
||||
// )
|
||||
];
|
||||
|
||||
for (x, y) in reference {
|
||||
@ -41,21 +43,18 @@ fn test_ripemd() -> Result<()> {
|
||||
let expected = U256::from(y);
|
||||
|
||||
let kernel = combined_kernel();
|
||||
let label = kernel.global_labels["ripemd_alt"];
|
||||
let stack_input: Vec<U256> = input.iter().map(|&x| U256::from(x as u8)).rev().collect();
|
||||
let stack_output: Vec<U256> = run_with_kernel(&kernel, label, stack_input)?
|
||||
let initial_offset = kernel.global_labels["ripemd_alt"];
|
||||
let initial_stack: Vec<U256> = input.iter().map(|&x| U256::from(x as u8)).rev().collect();
|
||||
let final_stack: Vec<U256> = run_with_kernel(&kernel, initial_offset, initial_stack)?
|
||||
.stack()
|
||||
.to_vec();
|
||||
|
||||
let actual = stack_output[0];
|
||||
let actual = final_stack[0];
|
||||
|
||||
let read_out: Vec<String> = final_stack.iter().map(|x| format!("{:x}", x)).rev().collect();
|
||||
println!("{:x?}", read_out);
|
||||
|
||||
assert_eq!(actual, expected);
|
||||
}
|
||||
Ok(())
|
||||
|
||||
// let input: Vec<u8> = make_input("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789");
|
||||
// let expected = U256::from("0xb0e20b6e3116640286ed3a87a5713079b21f5189");
|
||||
// let input: Vec<u8> = make_input("");
|
||||
// let expected = U256::from("0x9c1185a5c5e9fc54612808977ee8f548b2258d31");
|
||||
// let read_out: Vec<String> = stack_output.iter().map(|x| format!("{:x}", x)).rev().collect();
|
||||
// println!("{:x?}", read_out);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user