Skip to content

Commit

Permalink
feat: sponge instructions change stack size
Browse files Browse the repository at this point in the history
That is:
- instruction `sponge_absorb` removes absorbed elements from stack
- instruction `sponge_squeeze` puts squeezed elements onto stack
  • Loading branch information
jan-ferdinand committed Nov 4, 2023
1 parent f465f75 commit 0fac3fc
Show file tree
Hide file tree
Showing 4 changed files with 170 additions and 148 deletions.
28 changes: 14 additions & 14 deletions triton-vm/src/instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,12 +174,12 @@ impl<Dest: PartialEq + Default> AnInstruction<Dest> {
DivineSibling => 40,
AssertVector => 48,
SpongeInit => 56,
SpongeAbsorb => 64,
SpongeSqueeze => 72,
Add => 34,
Mul => 42,
Invert => 80,
Eq => 50,
SpongeAbsorb => 34,
SpongeSqueeze => 64,
Add => 42,
Mul => 50,
Invert => 72,
Eq => 58,
Split => 4,
Lt => 6,
And => 14,
Expand All @@ -188,12 +188,12 @@ impl<Dest: PartialEq + Default> AnInstruction<Dest> {
Pow => 30,
DivMod => 20,
PopCount => 28,
XxAdd => 88,
XxMul => 96,
XInvert => 104,
XbMul => 58,
ReadIo => 112,
WriteIo => 66,
XxAdd => 80,
XxMul => 88,
XInvert => 96,
XbMul => 66,
ReadIo => 104,
WriteIo => 74,
}
}

Expand Down Expand Up @@ -341,8 +341,8 @@ impl<Dest: PartialEq + Default> AnInstruction<Dest> {
DivineSibling => 5,
AssertVector => 0,
SpongeInit => 0,
SpongeAbsorb => 0,
SpongeSqueeze => 0,
SpongeAbsorb => -10,
SpongeSqueeze => 10,
Add => -1,
Mul => -1,
Invert => 0,
Expand Down
15 changes: 11 additions & 4 deletions triton-vm/src/table/hash_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1970,16 +1970,23 @@ pub(crate) mod tests {

#[test]
fn terminal_constraints_hold_for_sponge_init_edge_case() {
let many_useless_absorbs = (0..7_991)
.flat_map(|_| triton_asm![sponge_init sponge_absorb])
let many_sponge_inits = triton_asm![sponge_init; 23_631];
let many_squeeze_absorbs = (0..2_100)
.flat_map(|_| triton_asm!(sponge_squeeze sponge_absorb))
.collect_vec();
let program = triton_program! {
sponge_init sponge_init sponge_init sponge_init
{&many_useless_absorbs}
{&many_sponge_inits}
{&many_squeeze_absorbs}
sponge_init
halt
};

let (aet, _) = program.trace_execution([].into(), [].into()).unwrap();
dbg!(aet.padded_height());
dbg!(aet.hash_table_length());
dbg!(aet.op_stack_table_length());
dbg!(aet.cascade_table_length());

let (_, _, master_base_table, master_ext_table, challenges) =
master_tables_for_low_security_level(&program, [].into(), [].into());

Expand Down
Loading

0 comments on commit 0fac3fc

Please sign in to comment.