Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: poseidon2 input pack (byte-input-padding-only) #1352

Open
wants to merge 90 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
90 commits
Select commit Hold shift + click to select a range
9ef4635
comments ...
reshmem Mar 6, 2024
c04d848
comments ...
reshmem Mar 7, 2024
fc0101b
comments
reshmem Mar 7, 2024
28ce14c
comments
reshmem Mar 7, 2024
451ade7
WIP
reshmem Mar 10, 2024
fede12c
WIP
reshmem Mar 17, 2024
b704a0e
WIP
reshmem Mar 17, 2024
1e58ec8
WIP - reduce_with_powers does not work
reshmem Mar 18, 2024
558bf34
WIP - fix
reshmem Mar 18, 2024
767f8b9
fix tests
reshmem Mar 18, 2024
553d5d7
pack to 7 - max for 64-b field + clippy
reshmem Mar 18, 2024
2cb1d44
cleanups
reshmem Mar 18, 2024
d762387
refactor...
reshmem Mar 18, 2024
89bf4d2
refactor...
reshmem Mar 18, 2024
99f416d
fix
reshmem Mar 18, 2024
7202f0d
refactor...
reshmem Mar 19, 2024
f953edc
fix - bit-padded-input
reshmem Mar 19, 2024
a4cbd2e
fix input_addr_padding constraint
reshmem Mar 19, 2024
fe41a7f
Merge branch 'main' into roman/poseidon-input-pack
reshmem Mar 19, 2024
9ebd02d
after merge from main
reshmem Mar 19, 2024
1885a88
clippy...
reshmem Mar 19, 2024
8501dfb
Merge branch 'main' into roman/poseidon-input-pack
reshmem Mar 28, 2024
2966a7d
fix after merge from main
reshmem Mar 28, 2024
5fc696d
Merge branch 'main' into roman/poseidon-input-pack
reshmem Apr 1, 2024
bf3682d
unpack logic in its own place
reshmem Apr 1, 2024
528e59f
fixes...
reshmem Apr 1, 2024
54c001c
fixes...
reshmem Apr 1, 2024
0fd0ab8
fixes...
reshmem Apr 1, 2024
7d9ce7e
Merge branch 'main' into roman/poseidon-input-pack
reshmem Apr 1, 2024
448d33b
add LE encoding
reshmem Apr 1, 2024
404a5c5
cleanup
reshmem Apr 1, 2024
d81382b
Merge branch 'main' into roman/poseidon-input-pack
reshmem Apr 2, 2024
8258863
fixes after review
reshmem Apr 2, 2024
28fcfcf
Merge branch 'main' into roman/poseidon-input-pack
reshmem Apr 2, 2024
3831081
Merge branch 'main' into roman/poseidon-input-pack
reshmem Apr 2, 2024
700582b
Update runner/src/poseidon2.rs
reshmem Apr 2, 2024
6b41395
fix
reshmem Apr 3, 2024
374e2c3
Merge branch 'main' into roman/poseidon-input-pack
reshmem Apr 3, 2024
72b4422
Merge branch 'main' into roman/poseidon-input-pack
reshmem Apr 7, 2024
63c2123
Clippy
matthiasgoergens Apr 12, 2024
eb225d8
Better conditional compilation
matthiasgoergens Apr 12, 2024
45f8a63
pad_trace_with_default
matthiasgoergens Apr 12, 2024
e3e565e
Remove useless trace
matthiasgoergens Apr 12, 2024
9ed5ac2
Clean up
matthiasgoergens Apr 12, 2024
e73298f
Fix typo
matthiasgoergens Apr 12, 2024
eaaa138
CLean up
matthiasgoergens Apr 12, 2024
a705624
Clean up
matthiasgoergens Apr 12, 2024
c0e5f13
Rename
matthiasgoergens Apr 12, 2024
5701875
Further cleanup
matthiasgoergens Apr 12, 2024
c41654d
Clean up
matthiasgoergens Apr 12, 2024
93f5e56
Simpler
matthiasgoergens Apr 12, 2024
cc10dda
Cleaner
matthiasgoergens Apr 12, 2024
cd61733
Remove counter-productive 'debug' option
matthiasgoergens Apr 13, 2024
f823c8b
Merge branch 'matthias/remove-useless-debug' into roman/poseidon-inpu…
matthiasgoergens Apr 13, 2024
3932df1
Remove poseidon2-feature
matthiasgoergens Apr 13, 2024
aec4160
Debug helpers
matthiasgoergens Apr 13, 2024
aaa7346
Merge branch 'matthias/enable-poseidon-always-remove-feature' into ro…
matthiasgoergens Apr 13, 2024
9f04532
Minimise diff
matthiasgoergens Apr 13, 2024
9aa4ac0
Minimise diff
matthiasgoergens Apr 13, 2024
a29c569
Rename
matthiasgoergens Apr 13, 2024
35eb2ce
Clean up
matthiasgoergens Apr 13, 2024
9b7aeb7
Revert "Simpler"
matthiasgoergens Apr 13, 2024
354c567
Revert "Clean up"
matthiasgoergens Apr 13, 2024
bc26da4
Reverted
matthiasgoergens Apr 13, 2024
5f2f78f
Clean up
matthiasgoergens Apr 13, 2024
712a8ed
refactor
matthiasgoergens Apr 13, 2024
f4de7be
Restore
matthiasgoergens Apr 13, 2024
253183d
Fixed!
matthiasgoergens Apr 13, 2024
5fab346
Clean up
matthiasgoergens Apr 13, 2024
de40025
Clean up
matthiasgoergens Apr 13, 2024
4317767
Clippy
matthiasgoergens Apr 13, 2024
0c37937
Keep length in the type system
matthiasgoergens Apr 13, 2024
c53434c
Merge remote-tracking branch 'origin/main' into roman/poseidon-input-…
matthiasgoergens Apr 13, 2024
d9aa994
Merge branch 'main' into roman/poseidon-input-pack
reshmem Apr 14, 2024
2c07fb9
fix: issue with under-constraint byte-address
reshmem Apr 14, 2024
0ab95e3
fix: after review
reshmem Apr 14, 2024
ec39911
fix: comment ..
reshmem Apr 14, 2024
41c3e77
fix: failed example, refactored cyclic dep
reshmem Apr 15, 2024
72ec4af
taplo
reshmem Apr 15, 2024
6617711
Merge branch 'main' into roman/poseidon-input-pack
reshmem Apr 15, 2024
5680070
fix...
reshmem Apr 15, 2024
aacb641
Cargo.lock
reshmem Apr 16, 2024
f853513
Merge branch 'main' into roman/poseidon-input-pack
reshmem Apr 16, 2024
662b827
examples/Cargo.lock
reshmem Apr 16, 2024
2793151
sdk/Cargo.lock
reshmem Apr 16, 2024
c0d9671
clippy
reshmem Apr 16, 2024
09c8a56
Merge branch 'main' into roman/poseidon-input-pack
reshmem Apr 16, 2024
8f1cbfb
Merge branch 'main' into roman/poseidon-input-pack
reshmem Apr 18, 2024
0cf3377
fix after merge
reshmem Apr 18, 2024
ae3403a
taplo
reshmem Apr 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix after merge from main
  • Loading branch information
reshmem committed Mar 28, 2024
commit 2966a7df44e5d5e872dc58e89137f5010482cfe8
56 changes: 34 additions & 22 deletions circuits/src/poseidon2_preimage_pack/columns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ use plonky2::hash::hash_types::RichField;

use crate::columns_view::{columns_view_impl, make_col_map, NumberOfColumns};
use crate::linear_combination::Column;
use crate::linear_combination_typed::ColumnWithTypedInput;
use crate::memory::columns::MemoryCtl;
use crate::poseidon2::columns::STATE_SIZE;
use crate::poseidon2_sponge::columns::Poseidon2Sponge;
use crate::stark::mozak_stark::{Poseidon2PreimagePackTable, Table};
use crate::stark::mozak_stark::{Poseidon2PreimagePackTable, TableWithTypedOutput};

#[repr(C)]
#[derive(Clone, Copy, Eq, PartialEq, Debug, Default)]
Expand Down Expand Up @@ -77,42 +79,52 @@ impl<F: RichField> From<&Poseidon2Sponge<F>> for Vec<Poseidon2PreimagePack<F>> {
}
}

columns_view_impl!(Poseidon2SpongePreimagePackCtl);
#[repr(C)]
#[derive(Clone, Copy, Eq, PartialEq, Debug, Default)]
pub struct Poseidon2SpongePreimagePackCtl<T> {
pub clk: T,
pub value: T,
pub fe_addr: T,
}
#[must_use]
pub fn lookup_for_poseidon2_sponge() -> Table {
let data = col_map().map(Column::from);
pub fn lookup_for_poseidon2_sponge() -> TableWithTypedOutput<Poseidon2SpongePreimagePackCtl<Column>>
{
let data = COL_MAP;
Poseidon2PreimagePackTable::new(
vec![
data.clk,
Column::reduce_with_powers(
Poseidon2SpongePreimagePackCtl {
clk: data.clk,
value: ColumnWithTypedInput::reduce_with_powers(
// FIXME: Check why does not work just reduce_with_power on &data.bytes
{
let mut r = data.bytes.clone();
let mut r = data.bytes;
r.reverse();
&r.clone()
r
},
1 << 8,
i64::from(1 << 8),
),
data.fe_addr,
],
col_map().map(Column::from).is_executed,
fe_addr: data.fe_addr,
},
COL_MAP.is_executed,
)
}

#[must_use]
pub fn lookup_for_input_memory(index: u8) -> Table {
pub fn lookup_for_input_memory(index: u8) -> TableWithTypedOutput<MemoryCtl<Column>> {
assert!(
usize::from(index) < MozakPoseidon2::DATA_CAPACITY_PER_FIELD_ELEMENT,
"poseidon2-preimage data_for_input_memory: index can be 0..{:?}",
MozakPoseidon2::DATA_CAPACITY_PER_FIELD_ELEMENT
);
let data = col_map().map(Column::from);
let data = COL_MAP;
Poseidon2PreimagePackTable::new(
vec![
data.clk,
Column::constant(0), // is_store
Column::constant(1), // is_load
data.bytes[index as usize].clone(), // value
data.byte_addr + i64::from(index), // address
],
col_map().map(Column::from).is_executed,
MemoryCtl {
clk: data.clk,
is_store: ColumnWithTypedInput::constant(0), // is_store
is_load: ColumnWithTypedInput::constant(1), // is_load
value: data.bytes[index as usize], // value
addr: data.byte_addr + i64::from(index), // address
},
COL_MAP.is_executed,
)
}
17 changes: 10 additions & 7 deletions circuits/src/poseidon2_sponge/columns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use crate::memory::columns::MemoryCtl;
use crate::poseidon2::columns::Poseidon2StateCtl;
#[cfg(feature = "enable_poseidon_starks")]
use crate::poseidon2_output_bytes::columns::Poseidon2OutputBytesCtl;
use crate::poseidon2_preimage_pack::columns::Poseidon2SpongePreimagePackCtl;
#[cfg(feature = "enable_poseidon_starks")]
use crate::stark::mozak_stark::{Poseidon2SpongeTable, TableWithTypedOutput};

Expand Down Expand Up @@ -118,15 +119,17 @@ pub fn lookup_for_input_memory(limb_index: u8) -> TableWithTypedOutput<MemoryCtl
}

#[must_use]
pub fn lookup_for_preimage_pack(limb_index: u8) -> Table {
pub fn lookup_for_preimage_pack(
limb_index: u8,
) -> TableWithTypedOutput<Poseidon2SpongePreimagePackCtl<Column>> {
assert!(limb_index < 8, "limb_index can be 0..7");
let sponge = col_map().map(Column::from);
let sponge = COL_MAP;
Poseidon2SpongeTable::new(
vec![
sponge.clk,
sponge.preimage[limb_index as usize].clone(), // value
sponge.input_addr + i64::from(limb_index), // address
],
Poseidon2SpongePreimagePackCtl {
clk: sponge.clk,
value: sponge.preimage[limb_index as usize], // value
fe_addr: sponge.input_addr + i64::from(limb_index), // address
},
sponge.ops.is_init_permute + sponge.ops.is_permute,
)
}
24 changes: 15 additions & 9 deletions circuits/src/stark/mozak_stark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,16 @@ use crate::poseidon2_output_bytes::columns::Poseidon2OutputBytes;
#[cfg(feature = "enable_poseidon_starks")]
use crate::poseidon2_output_bytes::columns::Poseidon2OutputBytesCtl;
use crate::poseidon2_output_bytes::stark::Poseidon2OutputBytesStark;
use crate::poseidon2_preimage_pack::columns::{
Poseidon2PreimagePack, Poseidon2SpongePreimagePackCtl,
};
#[cfg(feature = "enable_poseidon_starks")]
use crate::poseidon2_preimage_pack::stark::Poseidon2PreimagePackStark;
#[cfg(feature = "enable_poseidon_starks")]
use crate::poseidon2_sponge;
use crate::poseidon2_sponge::columns::Poseidon2Sponge;
#[cfg(feature = "enable_poseidon_starks")]
use crate::poseidon2_sponge::columns::Poseidon2SpongeCtl;
use crate::poseidon2_sponge::stark::Poseidon2SpongeStark;
#[cfg(feature = "enable_poseidon_starks")]
use crate::poseidon2_preimage_pack::stark::Poseidon2PreimagePackStark;
use crate::program::columns::{InstructionRow, ProgramRom};
use crate::program::stark::ProgramStark;
use crate::rangecheck::columns::{rangecheck_looking, RangeCheckColumnsView, RangeCheckCtl};
Expand Down Expand Up @@ -568,8 +570,11 @@ table_impl!(
Poseidon2OutputBytes
);
#[cfg(feature = "enable_poseidon_starks")]
table_impl!(Poseidon2PreimagePackTable, TableKind::Poseidon2PreimagePack);

table_impl!(
Poseidon2PreimagePackTable,
TableKind::Poseidon2PreimagePack,
Poseidon2PreimagePack
);

pub trait Lookups {
type Row: IntoIterator<Item = Column>;
Expand Down Expand Up @@ -821,12 +826,13 @@ impl Lookups for Poseidon2OutputBytesPoseidon2SpongeTable {
pub struct Poseidon2Sponge2Poseidon2PreimagePackTable;
#[cfg(feature = "enable_poseidon_starks")]
impl Lookups for Poseidon2Sponge2Poseidon2PreimagePackTable {
fn lookups() -> CrossTableLookup {
type Row = Poseidon2SpongePreimagePackCtl<Column>;

fn lookups_with_typed_output() -> CrossTableLookupWithTypedOutput<Self::Row> {
let mut tables = vec![];
tables.extend((0..8).map(crate::poseidon2_sponge::columns::lookup_for_preimage_pack));
CrossTableLookup::new(
tables,
CrossTableLookupWithTypedOutput::new(tables, vec![
poseidon2_preimage_pack::columns::lookup_for_poseidon2_sponge(),
)
])
}
}
Loading