mirror of
https://github.com/logos-storage/plonky2.git
synced 2026-01-04 23:03:08 +00:00
Add test (won't work for a while, but to illustrate)
This commit is contained in:
parent
c389abc140
commit
5d74a19ad6
@ -18,8 +18,12 @@ pest_derive = "2.1.0"
|
||||
rayon = "1.5.1"
|
||||
rand = "0.8.5"
|
||||
rand_chacha = "0.3.1"
|
||||
rlp = "0.5.1"
|
||||
keccak-rust = { git = "https://github.com/npwardberkeley/keccak-rust" }
|
||||
|
||||
[dev-dependencies]
|
||||
hex-literal = "0.3.4"
|
||||
|
||||
[features]
|
||||
asmtools = ["hex"]
|
||||
|
||||
|
||||
@ -23,6 +23,18 @@ pub struct AllStark<F: RichField + Extendable<D>, const D: usize> {
|
||||
pub cross_table_lookups: Vec<CrossTableLookup<F>>,
|
||||
}
|
||||
|
||||
impl<F: RichField + Extendable<D>, const D: usize> Default for AllStark<F, D> {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
cpu_stark: CpuStark::default(),
|
||||
keccak_stark: KeccakStark::default(),
|
||||
logic_stark: LogicStark::default(),
|
||||
memory_stark: MemoryStark::default(),
|
||||
cross_table_lookups: all_cross_table_lookups(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<F: RichField + Extendable<D>, const D: usize> AllStark<F, D> {
|
||||
pub(crate) fn nums_permutation_zs(&self, config: &StarkConfig) -> Vec<usize> {
|
||||
let ans = vec![
|
||||
@ -128,7 +140,7 @@ mod tests {
|
||||
use plonky2::util::timing::TimingTree;
|
||||
use rand::{thread_rng, Rng};
|
||||
|
||||
use crate::all_stark::{all_cross_table_lookups, AllStark};
|
||||
use crate::all_stark::AllStark;
|
||||
use crate::config::StarkConfig;
|
||||
use crate::cpu::cpu_stark::CpuStark;
|
||||
use crate::keccak::keccak_stark::{KeccakStark, NUM_INPUTS, NUM_ROUNDS};
|
||||
@ -313,48 +325,27 @@ mod tests {
|
||||
}
|
||||
|
||||
fn get_proof(config: &StarkConfig) -> Result<(AllStark<F, D>, AllProof<F, C, D>)> {
|
||||
let cpu_stark = CpuStark::<F, D> {
|
||||
f: Default::default(),
|
||||
};
|
||||
let all_stark = AllStark::default();
|
||||
|
||||
let keccak_stark = KeccakStark::<F, D> {
|
||||
f: Default::default(),
|
||||
};
|
||||
|
||||
let logic_stark = LogicStark::<F, D> {
|
||||
f: Default::default(),
|
||||
};
|
||||
let num_logic_rows = 62;
|
||||
|
||||
let memory_stark = MemoryStark::<F, D> {
|
||||
f: Default::default(),
|
||||
};
|
||||
let num_memory_ops = 1 << 5;
|
||||
|
||||
let mut rng = thread_rng();
|
||||
let num_keccak_perms = 2;
|
||||
|
||||
let keccak_trace = make_keccak_trace(num_keccak_perms, &keccak_stark, &mut rng);
|
||||
let logic_trace = make_logic_trace(num_logic_rows, &logic_stark, &mut rng);
|
||||
let mut memory_trace = make_memory_trace(num_memory_ops, &memory_stark, &mut rng);
|
||||
let keccak_trace = make_keccak_trace(num_keccak_perms, &all_stark.keccak_stark, &mut rng);
|
||||
let logic_trace = make_logic_trace(num_logic_rows, &all_stark.logic_stark, &mut rng);
|
||||
let mut memory_trace = make_memory_trace(num_memory_ops, &all_stark.memory_stark, &mut rng);
|
||||
let cpu_trace = make_cpu_trace(
|
||||
num_keccak_perms,
|
||||
num_logic_rows,
|
||||
num_memory_ops,
|
||||
&cpu_stark,
|
||||
&all_stark.cpu_stark,
|
||||
&keccak_trace,
|
||||
&logic_trace,
|
||||
&mut memory_trace,
|
||||
);
|
||||
|
||||
let all_stark = AllStark {
|
||||
cpu_stark,
|
||||
keccak_stark,
|
||||
logic_stark,
|
||||
memory_stark,
|
||||
cross_table_lookups: all_cross_table_lookups(),
|
||||
};
|
||||
|
||||
let proof = prove::<F, C, D>(
|
||||
&all_stark,
|
||||
config,
|
||||
|
||||
@ -55,7 +55,7 @@ pub fn ctl_filter_memory<F: Field>(channel: usize) -> Column<F> {
|
||||
Column::single(COL_MAP.mem_channel_used[channel])
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
#[derive(Copy, Clone, Default)]
|
||||
pub struct CpuStark<F, const D: usize> {
|
||||
pub f: PhantomData<F>,
|
||||
}
|
||||
|
||||
@ -16,14 +16,14 @@ pub type RlpMerkleProof = Vec<Vec<u8>>;
|
||||
|
||||
#[allow(unused)] // TODO: Should be used soon.
|
||||
pub struct TransactionData {
|
||||
pub(crate) payload: Vec<u8>,
|
||||
pub(crate) signature: Vec<u8>,
|
||||
pub signed_txn: Vec<u8>,
|
||||
|
||||
/// A Merkle proof for each interaction with the state trie, ordered chronologically.
|
||||
pub(crate) trie_proofs: Vec<RlpMerkleProof>,
|
||||
pub trie_proofs: Vec<RlpMerkleProof>,
|
||||
}
|
||||
|
||||
#[allow(unused)] // TODO: Should be used soon.
|
||||
fn generate_traces<F: RichField + Extendable<D>, const D: usize>(
|
||||
pub fn generate_traces<F: RichField + Extendable<D>, const D: usize>(
|
||||
all_stark: &AllStark<F, D>,
|
||||
txns: &[TransactionData],
|
||||
) -> Vec<Vec<PolynomialValues<F>>> {
|
||||
|
||||
@ -44,7 +44,7 @@ pub fn ctl_filter<F: Field>() -> Column<F> {
|
||||
Column::single(reg_step(NUM_ROUNDS - 1))
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
#[derive(Copy, Clone, Default)]
|
||||
pub struct KeccakStark<F, const D: usize> {
|
||||
pub(crate) f: PhantomData<F>,
|
||||
}
|
||||
|
||||
@ -63,7 +63,7 @@ pub fn ctl_filter<F: Field>() -> Column<F> {
|
||||
Column::sum([columns::IS_AND, columns::IS_OR, columns::IS_XOR])
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
#[derive(Copy, Clone, Default)]
|
||||
pub struct LogicStark<F, const D: usize> {
|
||||
pub f: PhantomData<F>,
|
||||
}
|
||||
|
||||
@ -40,7 +40,7 @@ pub fn ctl_filter<F: Field>(channel: usize) -> Column<F> {
|
||||
Column::single(is_channel(channel))
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
#[derive(Copy, Clone, Default)]
|
||||
pub struct MemoryStark<F, const D: usize> {
|
||||
pub(crate) f: PhantomData<F>,
|
||||
}
|
||||
|
||||
46
evm/tests/transfer_to_new_addr.rs
Normal file
46
evm/tests/transfer_to_new_addr.rs
Normal file
@ -0,0 +1,46 @@
|
||||
use hex_literal::hex;
|
||||
use plonky2::field::goldilocks_field::GoldilocksField;
|
||||
use plonky2::plonk::config::PoseidonGoldilocksConfig;
|
||||
use plonky2::util::timing::TimingTree;
|
||||
use plonky2_evm::all_stark::AllStark;
|
||||
use plonky2_evm::config::StarkConfig;
|
||||
use plonky2_evm::generation::{generate_traces, TransactionData};
|
||||
use plonky2_evm::prover::prove;
|
||||
use plonky2_evm::verifier::verify_proof;
|
||||
|
||||
type F = GoldilocksField;
|
||||
const D: usize = 2;
|
||||
type C = PoseidonGoldilocksConfig;
|
||||
|
||||
/// Test a simple token transfer to a new address.
|
||||
#[test]
|
||||
#[ignore] // TODO: Won't work until txn parsing, storage, etc. are implemented.
|
||||
fn test_simple_transfer() -> anyhow::Result<()> {
|
||||
let all_stark = AllStark::<F, D>::default();
|
||||
|
||||
let txn = TransactionData {
|
||||
signed_txn: hex!("f85f050a82520894000000000000000000000000000000000000000064801ca0fa56df5d988638fad8798e5ef75a1e1125dc7fb55d2ac4bce25776a63f0c2967a02cb47a5579eb5f83a1cabe4662501c0059f1b58e60ef839a1b0da67af6b9fb38").to_vec(),
|
||||
trie_proofs: vec![
|
||||
vec![
|
||||
hex!("f874a1202f93d0dfb1562c03c825a33eec4438e468c17fff649ae844c004065985ae2945b850f84e058a152d02c7e14af6800000a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a0c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470").to_vec(),
|
||||
],
|
||||
vec![
|
||||
hex!("f8518080a0d36b8b6b60021940d5553689fb33e5d45e649dd8f4f211d26566238a83169da58080a0c62aa627943b70321f89a8b2fea274ecd47116e62042077dcdc0bdca7c1f66738080808080808080808080").to_vec(),
|
||||
hex!("f873a03f93d0dfb1562c03c825a33eec4438e468c17fff649ae844c004065985ae2945b850f84e068a152d02c7e14af67ccb4ca056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a0c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470").to_vec(),
|
||||
],
|
||||
]
|
||||
};
|
||||
|
||||
let traces = generate_traces(&all_stark, &[txn]);
|
||||
|
||||
let config = StarkConfig::standard_fast_config();
|
||||
let proof = prove::<F, C, D>(
|
||||
&all_stark,
|
||||
&config,
|
||||
traces,
|
||||
vec![vec![]; 4],
|
||||
&mut TimingTree::default(),
|
||||
)?;
|
||||
|
||||
verify_proof(all_stark, proof, &config)
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user