Skip to content

Commit

Permalink
fix: bincode for txenvelope
Browse files Browse the repository at this point in the history
  • Loading branch information
rkdud007 committed Oct 10, 2024
1 parent 8378079 commit a4e0cb5
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 8 deletions.
Binary file modified elf/riscv32im-succinct-zkvm-elf
Binary file not shown.
4 changes: 2 additions & 2 deletions program/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ pub fn main() {
let mut memorizer = sp1_zkvm::io::read::<Memorizer>();
} else {
println!("Hello, world! from non zkvm");
let rpc_url: String = env::var("RPC_URL").expect("RPC_URL not set");
let mut memorizer = Memorizer::new(Some(Url::from_str(&rpc_url).unwrap()));
// let rpc_url: String = env::var("RPC_URL").expect("RPC_URL not set");
let mut memorizer = Memorizer::new(Some(Url::from_str("https://sepolia.ethereum.iosis.tech/").unwrap()));
}
}

Expand Down
14 changes: 12 additions & 2 deletions program/src/memorizer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ impl Memorizer {

#[cfg(test)]
mod tests {
use alloy_primitives::B256;
use alloy_primitives::{Bytes, B256};
use std::fs;
use tempdir::TempDir;
use values::HeaderMemorizerValue;
use values::{HeaderMemorizerValue, TransactionMemorizerValue};

use super::*;

Expand All @@ -58,6 +58,16 @@ mod tests {
B256::ZERO,
MemorizerValue::Header(HeaderMemorizerValue::default()),
);
let raw_tx = alloy_primitives::hex::decode("02f86f0102843b9aca0085029e7822d68298f094d9e1459a7a482635700cbc20bbaf52d495ab9c9680841b55ba3ac080a0c199674fcb29f353693dd779c017823b954b3c69dffa3cd6b2a6ff7888798039a028ca912de909e7e6cdef9cdcaf24c54dd8c1032946dfa1d85c206b32a9064fe8").unwrap();
// let res = TxEnvelope::decode(&mut raw_tx.as_slice()).unwrap();
original_mem.map.insert(
B256::ZERO,
MemorizerValue::Transaction(TransactionMemorizerValue {
transaction_encoded: Bytes::from(raw_tx),
tx_index: 0,
proof: Default::default(),
}),
);

fs::write(&path, original_mem.as_bytes().unwrap()).unwrap();

Expand Down
5 changes: 4 additions & 1 deletion program/src/memorizer/transaction/online.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use alloy_consensus::TxEnvelope;
use alloy_rlp::Encodable;
use hdp_lib::transaction::{TransactionClient, TransactionResponse};
use tokio::runtime::Runtime;

Expand All @@ -22,11 +23,13 @@ impl TransactionMemorizer for Memorizer {
});

let tx = transaction.tx.0;
let mut out = Vec::new();
tx.encode(&mut out);

self.map.insert(
key.into(),
crate::memorizer::values::MemorizerValue::Transaction(TransactionMemorizerValue {
transaction: tx.clone(),
transaction_encoded: out.into(),
tx_index: transaction.tx_index,
proof: transaction.proof,
}),
Expand Down
4 changes: 3 additions & 1 deletion program/src/memorizer/transaction/zkvm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use crate::memorizer::{
keys::HeaderKey, keys::MemorizerKey, keys::TransactionKey, values::MemorizerValue, Memorizer,
};
use alloy_consensus::TxEnvelope;
use alloy_rlp::Decodable;
use hdp_lib::mpt::Mpt;
use std::error::Error;

Expand All @@ -23,7 +24,8 @@ impl TransactionMemorizer for Memorizer {
println!("cycle-tracker-start: mpt");
mpt.verify(tx_value.tx_index, tx_value.proof.clone());
println!("cycle-tracker-end: mpt");
Ok(tx_value.transaction.clone())
let tx_encoded = tx_value.transaction_encoded.clone();
Ok(TxEnvelope::decode(&mut tx_encoded.as_ref()).unwrap())
} else {
Err("Transaction not found".into())
}
Expand Down
4 changes: 2 additions & 2 deletions program/src/memorizer/values.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use alloy_consensus::{serde_bincode_compat, TxEnvelope};
use alloy_consensus::serde_bincode_compat;
use alloy_consensus::{Account, Header};
use alloy_primitives::{Bytes, B256, U256};
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -30,7 +30,7 @@ pub struct StorageMemorizerValue {

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct TransactionMemorizerValue {
pub transaction: TxEnvelope,
pub transaction_encoded: Bytes,
pub tx_index: u64,
pub proof: Vec<Bytes>,
}
Expand Down

0 comments on commit a4e0cb5

Please sign in to comment.