mirror of
https://github.com/logos-storage/plonky2.git
synced 2026-01-09 01:03:08 +00:00
alt api for testing
This commit is contained in:
parent
76d50f336c
commit
a6f72ee315
@ -137,4 +137,3 @@ R_data:
|
||||
BYTES 04, 20, 32, 28
|
||||
BYTES 24, 08, 52, 56
|
||||
BYTES 00, 12, 36, 44
|
||||
|
||||
@ -30,7 +30,25 @@ store_size:
|
||||
store_padding:
|
||||
// stack: i (init 63)
|
||||
%store_zeros(136, store_padding)
|
||||
%jump(store_input)
|
||||
%jump(store_input_alt)
|
||||
|
||||
|
||||
store_input_alt:
|
||||
// stack: rem, length, REM_INP
|
||||
%stack (rem, length, head) -> (length, rem, 136, head, rem, length)
|
||||
SUB
|
||||
ADD
|
||||
// stack: offset, byte, rem, length, REM_INP
|
||||
%mstore_ripemd
|
||||
// stack: rem, length, REM_INP
|
||||
%sub_const(1)
|
||||
DUP1
|
||||
// stack: rem - 1, rem - 1, length, REM_INP
|
||||
%jumpi(store_input_alt)
|
||||
// stack: 0, length
|
||||
POP
|
||||
%jump(ripemd_init)
|
||||
|
||||
|
||||
store_input:
|
||||
// stack: ADDR , rem , length
|
||||
|
||||
@ -12,9 +12,19 @@
|
||||
/// stack: STATE, count, length, virt
|
||||
/// where virt is the virtual address of the bytes argument
|
||||
|
||||
global ripemd_alt:
|
||||
// stack: length, INPUT
|
||||
%stack (length) -> (64, length, 0x80, 63, length, length)
|
||||
// stack: 64, length, 0x80, 63, length, length, INPUT
|
||||
%jump(ripemd_storage) // stores the following into memory
|
||||
// init _buffer at virt 0 [consumes 64]
|
||||
// store _size at virt 64 [consumes length]
|
||||
// store _padding at virt 72 [consumes 0x80, 63]
|
||||
// store _input at virt 136 [consumes length]
|
||||
|
||||
global ripemd:
|
||||
// stack: ADDR, length
|
||||
$stack (a, b, c, length) -> (64, length, 0x80, 63, a, b, c, length, length)
|
||||
%stack (a, b, c, length) -> (64, length, 0x80, 63, a, b, c, length, length)
|
||||
// stack: 64, length, 0x80, 63, a, b, c, length, length
|
||||
%jump(ripemd_storage) // stores the following into memory
|
||||
// init _buffer at virt 0 [consumes 64]
|
||||
|
||||
@ -3,6 +3,7 @@ mod curve_ops;
|
||||
mod ecrecover;
|
||||
mod exp;
|
||||
mod packing;
|
||||
mod ripemd;
|
||||
mod rlp;
|
||||
mod transaction_parsing;
|
||||
|
||||
|
||||
@ -1,9 +1,4 @@
|
||||
use std::str::FromStr;
|
||||
|
||||
use anyhow::Result;
|
||||
use ethereum_types::U256;
|
||||
use rand::{thread_rng, Rng};
|
||||
use sha2::{Digest, Sha256};
|
||||
|
||||
use crate::cpu::kernel::aggregator::combined_kernel;
|
||||
use crate::cpu::kernel::interpreter::run;
|
||||
@ -11,17 +6,24 @@ use crate::cpu::kernel::interpreter::run;
|
||||
#[test]
|
||||
fn test_ripemd() -> Result<()> {
|
||||
let kernel = combined_kernel();
|
||||
let ripemd = kernel.global_labels["ripemd"];
|
||||
let ripemd = kernel.global_labels["ripemd_alt"];
|
||||
|
||||
let mut initial_stack = vec![U256::from(num_bytes)];
|
||||
initial_stack.extend(bytes);
|
||||
let initial_stack = vec![
|
||||
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 after_ripemd = run(&kernel.code, ripemd, initial_stack, &kernel.prover_inputs)?;
|
||||
let result = after_ripemd.stack()[1];
|
||||
let hashed = run(&kernel.code, ripemd, initial_stack, &kernel.prover_inputs)?;
|
||||
let result = hashed.stack()[1];
|
||||
let actual = format!("{:X}", result);
|
||||
|
||||
EXPECTED = "0xf71c27109c692c1b56bbdceb5b9d2865b3708dbc"
|
||||
assert_eq!(EXPECTED, actual);
|
||||
let expected = "0xf71c27109c692c1b56bbdceb5b9d2865b3708dbc";
|
||||
assert_eq!(expected, actual);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user