mirror of
https://github.com/logos-storage/plonky2.git
synced 2026-01-04 23:03:08 +00:00
Remove GenerationOutputs (#1408)
This commit is contained in:
parent
46b6aa108d
commit
47e24306b7
@ -20,7 +20,6 @@ use crate::config::StarkConfig;
|
||||
use crate::cpu::columns::CpuColumnsView;
|
||||
use crate::cpu::kernel::aggregator::KERNEL;
|
||||
use crate::cpu::kernel::constants::global_metadata::GlobalMetadata;
|
||||
use crate::generation::outputs::{get_outputs, GenerationOutputs};
|
||||
use crate::generation::state::GenerationState;
|
||||
use crate::memory::segments::Segment;
|
||||
use crate::proof::{BlockHashes, BlockMetadata, ExtraBlockData, PublicValues, TrieRoots};
|
||||
@ -29,7 +28,6 @@ use crate::witness::memory::{MemoryAddress, MemoryChannel};
|
||||
use crate::witness::transition::transition;
|
||||
|
||||
pub mod mpt;
|
||||
pub mod outputs;
|
||||
pub(crate) mod prover_input;
|
||||
pub(crate) mod rlp;
|
||||
pub(crate) mod state;
|
||||
@ -61,13 +59,6 @@ pub struct GenerationInputs {
|
||||
pub block_metadata: BlockMetadata,
|
||||
|
||||
pub block_hashes: BlockHashes,
|
||||
|
||||
/// A list of known addresses in the input state trie (which itself doesn't hold addresses,
|
||||
/// only state keys). This is only useful for debugging, so that we can return addresses in the
|
||||
/// post-state rather than state keys. (See `GenerationOutputs`, and in particular
|
||||
/// `AddressOrStateKey`.) If the caller is not interested in the post-state, this can be left
|
||||
/// empty.
|
||||
pub addresses: Vec<Address>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Serialize, Default)]
|
||||
@ -196,11 +187,7 @@ pub fn generate_traces<F: RichField + Extendable<D>, const D: usize>(
|
||||
inputs: GenerationInputs,
|
||||
config: &StarkConfig,
|
||||
timing: &mut TimingTree,
|
||||
) -> anyhow::Result<(
|
||||
[Vec<PolynomialValues<F>>; NUM_TABLES],
|
||||
PublicValues,
|
||||
GenerationOutputs,
|
||||
)> {
|
||||
) -> anyhow::Result<([Vec<PolynomialValues<F>>; NUM_TABLES], PublicValues)> {
|
||||
let mut state = GenerationState::<F>::new(inputs.clone(), &KERNEL.code)
|
||||
.map_err(|err| anyhow!("Failed to parse all the initial prover inputs: {:?}", err))?;
|
||||
|
||||
@ -218,9 +205,6 @@ pub fn generate_traces<F: RichField + Extendable<D>, const D: usize>(
|
||||
state.traces.get_lengths()
|
||||
);
|
||||
|
||||
let outputs = get_outputs(&mut state)
|
||||
.map_err(|err| anyhow!("Failed to generate post-state info: {:?}", err))?;
|
||||
|
||||
let read_metadata = |field| state.memory.read_global_metadata(field);
|
||||
let trie_roots_before = TrieRoots {
|
||||
state_root: H256::from_uint(&read_metadata(StateTrieRootDigestBefore)),
|
||||
@ -257,7 +241,7 @@ pub fn generate_traces<F: RichField + Extendable<D>, const D: usize>(
|
||||
"convert trace data to tables",
|
||||
state.traces.into_tables(all_stark, config, timing)
|
||||
);
|
||||
Ok((tables, public_values, outputs))
|
||||
Ok((tables, public_values))
|
||||
}
|
||||
|
||||
fn simulate_cpu<F: RichField + Extendable<D>, const D: usize>(
|
||||
|
||||
@ -1,109 +0,0 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use ethereum_types::{Address, BigEndianHash, H256, U256};
|
||||
use plonky2::field::types::Field;
|
||||
|
||||
use crate::cpu::kernel::constants::global_metadata::GlobalMetadata::StateTrieRoot;
|
||||
use crate::generation::state::GenerationState;
|
||||
use crate::generation::trie_extractor::{
|
||||
read_state_trie_value, read_storage_trie_value, read_trie, AccountTrieRecord,
|
||||
};
|
||||
use crate::util::u256_to_usize;
|
||||
use crate::witness::errors::ProgramError;
|
||||
|
||||
/// The post-state after trace generation; intended for debugging.
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct GenerationOutputs {
|
||||
pub accounts: HashMap<AddressOrStateKey, AccountOutput>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Eq, PartialEq, Hash, Debug)]
|
||||
pub enum AddressOrStateKey {
|
||||
Address(Address),
|
||||
StateKey(H256),
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct AccountOutput {
|
||||
pub balance: U256,
|
||||
pub nonce: u64,
|
||||
pub code: Vec<u8>,
|
||||
pub storage: HashMap<U256, U256>,
|
||||
}
|
||||
|
||||
pub(crate) fn get_outputs<F: Field>(
|
||||
state: &mut GenerationState<F>,
|
||||
) -> Result<GenerationOutputs, ProgramError> {
|
||||
// First observe all addresses passed in by caller.
|
||||
for address in state.inputs.addresses.clone() {
|
||||
state.observe_address(address);
|
||||
}
|
||||
|
||||
let ptr = u256_to_usize(state.memory.read_global_metadata(StateTrieRoot))?;
|
||||
let account_map = read_trie::<AccountTrieRecord>(&state.memory, ptr, read_state_trie_value)?;
|
||||
|
||||
let mut accounts = HashMap::with_capacity(account_map.len());
|
||||
|
||||
for (state_key_nibbles, account) in account_map.into_iter() {
|
||||
if state_key_nibbles.count != 64 {
|
||||
return Err(ProgramError::IntegerTooLarge);
|
||||
}
|
||||
let state_key_h256 = H256::from_uint(&state_key_nibbles.try_into_u256().unwrap());
|
||||
|
||||
let addr_or_state_key =
|
||||
if let Some(address) = state.state_key_to_address.get(&state_key_h256) {
|
||||
AddressOrStateKey::Address(*address)
|
||||
} else {
|
||||
AddressOrStateKey::StateKey(state_key_h256)
|
||||
};
|
||||
|
||||
let account_output = account_trie_record_to_output(state, account)?;
|
||||
accounts.insert(addr_or_state_key, account_output);
|
||||
}
|
||||
|
||||
Ok(GenerationOutputs { accounts })
|
||||
}
|
||||
|
||||
fn account_trie_record_to_output<F: Field>(
|
||||
state: &GenerationState<F>,
|
||||
account: AccountTrieRecord,
|
||||
) -> Result<AccountOutput, ProgramError> {
|
||||
let storage = get_storage(state, account.storage_ptr)?;
|
||||
|
||||
// TODO: This won't work if the account was created during the txn.
|
||||
// Need to track changes to code, similar to how we track addresses
|
||||
// with observe_new_address.
|
||||
let code = state
|
||||
.inputs
|
||||
.contract_code
|
||||
.get(&account.code_hash)
|
||||
.ok_or(ProgramError::UnknownContractCode)?
|
||||
.clone();
|
||||
|
||||
Ok(AccountOutput {
|
||||
balance: account.balance,
|
||||
nonce: account.nonce,
|
||||
storage,
|
||||
code,
|
||||
})
|
||||
}
|
||||
|
||||
/// Get an account's storage trie, given a pointer to its root.
|
||||
fn get_storage<F: Field>(
|
||||
state: &GenerationState<F>,
|
||||
storage_ptr: usize,
|
||||
) -> Result<HashMap<U256, U256>, ProgramError> {
|
||||
let storage_trie = read_trie::<U256>(&state.memory, storage_ptr, |x| {
|
||||
Ok(read_storage_trie_value(x))
|
||||
})?;
|
||||
|
||||
let mut map = HashMap::with_capacity(storage_trie.len());
|
||||
for (storage_key_nibbles, value) in storage_trie.into_iter() {
|
||||
if storage_key_nibbles.count != 64 {
|
||||
return Err(ProgramError::IntegerTooLarge);
|
||||
};
|
||||
map.insert(storage_key_nibbles.try_into_u256().unwrap(), value);
|
||||
}
|
||||
|
||||
Ok(map)
|
||||
}
|
||||
@ -26,7 +26,6 @@ use crate::cross_table_lookup::{
|
||||
GrandProductChallengeSet,
|
||||
};
|
||||
use crate::evaluation_frame::StarkEvaluationFrame;
|
||||
use crate::generation::outputs::GenerationOutputs;
|
||||
use crate::generation::{generate_traces, GenerationInputs};
|
||||
use crate::get_challenges::observe_public_values;
|
||||
use crate::lookup::{lookup_helper_columns, Lookup, LookupCheckVars};
|
||||
@ -45,34 +44,18 @@ pub fn prove<F, C, const D: usize>(
|
||||
inputs: GenerationInputs,
|
||||
timing: &mut TimingTree,
|
||||
) -> Result<AllProof<F, C, D>>
|
||||
where
|
||||
F: RichField + Extendable<D>,
|
||||
C: GenericConfig<D, F = F>,
|
||||
{
|
||||
let (proof, _outputs) = prove_with_outputs(all_stark, config, inputs, timing)?;
|
||||
Ok(proof)
|
||||
}
|
||||
|
||||
/// Generate traces, then create all STARK proofs. Returns information about the post-state,
|
||||
/// intended for debugging, in addition to the proof.
|
||||
pub fn prove_with_outputs<F, C, const D: usize>(
|
||||
all_stark: &AllStark<F, D>,
|
||||
config: &StarkConfig,
|
||||
inputs: GenerationInputs,
|
||||
timing: &mut TimingTree,
|
||||
) -> Result<(AllProof<F, C, D>, GenerationOutputs)>
|
||||
where
|
||||
F: RichField + Extendable<D>,
|
||||
C: GenericConfig<D, F = F>,
|
||||
{
|
||||
timed!(timing, "build kernel", Lazy::force(&KERNEL));
|
||||
let (traces, public_values, outputs) = timed!(
|
||||
let (traces, public_values) = timed!(
|
||||
timing,
|
||||
"generate all traces",
|
||||
generate_traces(all_stark, inputs, config, timing)?
|
||||
);
|
||||
let proof = prove_with_traces(all_stark, config, traces, public_values, timing)?;
|
||||
Ok((proof, outputs))
|
||||
Ok(proof)
|
||||
}
|
||||
|
||||
/// Compute all STARK proofs.
|
||||
|
||||
@ -165,7 +165,6 @@ fn add11_yml() -> anyhow::Result<()> {
|
||||
prev_hashes: vec![H256::default(); 256],
|
||||
cur_hash: H256::default(),
|
||||
},
|
||||
addresses: vec![],
|
||||
};
|
||||
|
||||
let mut timing = TimingTree::new("prove", log::Level::Debug);
|
||||
|
||||
@ -197,7 +197,6 @@ fn test_basic_smart_contract() -> anyhow::Result<()> {
|
||||
prev_hashes: vec![H256::default(); 256],
|
||||
cur_hash: H256::default(),
|
||||
},
|
||||
addresses: vec![],
|
||||
};
|
||||
|
||||
let mut timing = TimingTree::new("prove", log::Level::Debug);
|
||||
|
||||
@ -72,7 +72,6 @@ fn test_empty_txn_list() -> anyhow::Result<()> {
|
||||
prev_hashes: initial_block_hashes,
|
||||
cur_hash: H256::default(),
|
||||
},
|
||||
addresses: vec![],
|
||||
};
|
||||
|
||||
// Initialize the preprocessed circuits for the zkEVM.
|
||||
|
||||
@ -173,7 +173,6 @@ fn test_erc20() -> anyhow::Result<()> {
|
||||
prev_hashes: vec![H256::default(); 256],
|
||||
cur_hash: H256::default(),
|
||||
},
|
||||
addresses: vec![],
|
||||
};
|
||||
|
||||
let mut timing = TimingTree::new("prove", log::Level::Debug);
|
||||
|
||||
@ -231,7 +231,6 @@ fn test_log_opcodes() -> anyhow::Result<()> {
|
||||
prev_hashes: vec![H256::default(); 256],
|
||||
cur_hash: H256::default(),
|
||||
},
|
||||
addresses: vec![],
|
||||
};
|
||||
|
||||
let mut timing = TimingTree::new("prove", log::Level::Debug);
|
||||
@ -436,7 +435,6 @@ fn test_log_with_aggreg() -> anyhow::Result<()> {
|
||||
prev_hashes: vec![H256::default(); 256],
|
||||
cur_hash: H256::default(),
|
||||
},
|
||||
addresses: vec![],
|
||||
};
|
||||
|
||||
// Preprocess all circuits.
|
||||
@ -562,7 +560,6 @@ fn test_log_with_aggreg() -> anyhow::Result<()> {
|
||||
prev_hashes: vec![H256::default(); 256],
|
||||
cur_hash: H256::default(),
|
||||
},
|
||||
addresses: vec![],
|
||||
};
|
||||
|
||||
let mut timing = TimingTree::new("prove root second", log::Level::Info);
|
||||
|
||||
@ -184,7 +184,6 @@ fn self_balance_gas_cost() -> anyhow::Result<()> {
|
||||
prev_hashes: vec![H256::default(); 256],
|
||||
cur_hash: H256::default(),
|
||||
},
|
||||
addresses: vec![],
|
||||
};
|
||||
|
||||
let mut timing = TimingTree::new("prove", log::Level::Debug);
|
||||
|
||||
@ -136,7 +136,6 @@ fn test_selfdestruct() -> anyhow::Result<()> {
|
||||
prev_hashes: vec![H256::default(); 256],
|
||||
cur_hash: H256::default(),
|
||||
},
|
||||
addresses: vec![],
|
||||
};
|
||||
|
||||
let mut timing = TimingTree::new("prove", log::Level::Debug);
|
||||
|
||||
@ -152,7 +152,6 @@ fn test_simple_transfer() -> anyhow::Result<()> {
|
||||
prev_hashes: vec![H256::default(); 256],
|
||||
cur_hash: H256::default(),
|
||||
},
|
||||
addresses: vec![],
|
||||
};
|
||||
|
||||
let mut timing = TimingTree::new("prove", log::Level::Debug);
|
||||
|
||||
@ -82,7 +82,6 @@ fn test_withdrawals() -> anyhow::Result<()> {
|
||||
prev_hashes: vec![H256::default(); 256],
|
||||
cur_hash: H256::default(),
|
||||
},
|
||||
addresses: vec![],
|
||||
};
|
||||
|
||||
let mut timing = TimingTree::new("prove", log::Level::Debug);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user