Skip to content

Commit 0bf8910

Browse files
author
Daniel Kuehr
committed
transaction fuzzer: fixes after rebase
1 parent b739b89 commit 0bf8910

File tree

13 files changed

+191
-190
lines changed

13 files changed

+191
-190
lines changed

Cargo.lock

Lines changed: 15 additions & 57 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ members = [
2727
"tools/hash-tool",
2828
"tools/ledger-tool",
2929
"tools/salsa-simple",
30-
#cfg(unstable),
3130
"tools/fuzzing",
3231
"producer-dashboard",
3332

ledger/src/ffi/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ mod database;
33
mod mask;
44
mod ondisk;
55
// mod transaction_fuzzer;
6-
mod util;
6+
//mod util;
77

88
use database::*;

ledger/src/scan_state/conv.rs

Lines changed: 78 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -1830,24 +1830,27 @@ impl From<&zkapp_command::ZkAppCommand> for MinaBaseZkappCommandTStableV1WireSta
18301830
}
18311831
}
18321832

1833-
impl From<&MinaTransactionLogicTransactionAppliedVaryingStableV2> for transaction_applied::Varying {
1834-
fn from(value: &MinaTransactionLogicTransactionAppliedVaryingStableV2) -> Self {
1833+
impl TryFrom<&MinaTransactionLogicTransactionAppliedVaryingStableV2>
1834+
for transaction_applied::Varying
1835+
{
1836+
type Error = InvalidBigInt;
1837+
1838+
fn try_from(
1839+
value: &MinaTransactionLogicTransactionAppliedVaryingStableV2,
1840+
) -> Result<Self, Self::Error> {
18351841
use mina_p2p_messages::v2::MinaTransactionLogicTransactionAppliedVaryingStableV2::*;
18361842
use mina_p2p_messages::v2::MinaTransactionLogicTransactionAppliedCommandAppliedStableV2::*;
18371843
use mina_p2p_messages::v2::MinaTransactionLogicTransactionAppliedSignedCommandAppliedBodyStableV2::*;
1838-
// use mina_p2p_messages::v2::TransactionSnarkPendingCoinbaseStackStateInitStackStableV1::{Base, Merge};
1839-
use mina_p2p_messages::v2::MinaStateSnarkedLedgerStatePendingCoinbaseStackStateInitStackStableV1::{Base, Merge};
1840-
use crate::scan_state::scan_state::transaction_snark::InitStack;
18411844
use transaction_applied::signed_command_applied;
18421845

1843-
match value {
1846+
let result = match value {
18441847
Command(cmd) => match cmd {
18451848
SignedCommand(cmd) => transaction_applied::Varying::Command(
18461849
transaction_applied::CommandApplied::SignedCommand(Box::new(
18471850
transaction_applied::SignedCommandApplied {
18481851
common: transaction_applied::signed_command_applied::Common {
18491852
user_command: WithStatus {
1850-
data: (&cmd.common.user_command.data).into(),
1853+
data: (&cmd.common.user_command.data).try_into()?,
18511854
status: (&cmd.common.user_command.status).into(),
18521855
},
18531856
},
@@ -1857,15 +1860,16 @@ impl From<&MinaTransactionLogicTransactionAppliedVaryingStableV2> for transactio
18571860
new_accounts: new_accounts
18581861
.iter()
18591862
.cloned()
1860-
.map(Into::into)
1861-
.collect(),
1863+
.map(TryInto::try_into)
1864+
.collect::<Result<_, _>>()?,
18621865
}
18631866
}
18641867
StakeDelegation { previous_delegate } => {
18651868
signed_command_applied::Body::StakeDelegation {
1866-
previous_delegate: previous_delegate
1867-
.as_ref()
1868-
.map(|d| d.into()),
1869+
previous_delegate: match previous_delegate.as_ref() {
1870+
Some(prev) => Some(prev.try_into()?),
1871+
None => None,
1872+
},
18691873
}
18701874
}
18711875
Failed => signed_command_applied::Body::Failed,
@@ -1880,104 +1884,89 @@ impl From<&MinaTransactionLogicTransactionAppliedVaryingStableV2> for transactio
18801884
.accounts
18811885
.iter()
18821886
.map(|(id, account_opt)| {
1883-
let id: AccountId = id.into();
1884-
let account: Option<Account> = account_opt.as_ref().map(Into::into);
1887+
let id: AccountId = id.try_into()?;
1888+
let account: Option<Account> = match account_opt.as_ref() {
1889+
Some(account) => Some(account.try_into()?),
1890+
None => None,
1891+
};
18851892
let account = account.map(Box::new);
18861893

1887-
Ok((id, account))
1888-
})
1889-
.collect::<Result<_, _>>()?,
1890-
command: WithStatus {
1891-
data: (&cmd.command.data).try_into()?,
1892-
status: (&cmd.command.status).into(),
1893-
},
1894-
new_accounts: cmd.new_accounts.iter().map(TryInto::try_into).collect::<Result<_, _>>()?,
1895-
},
1896-
)),
1897-
),
1898-
},
1899-
FeeTransfer(ft) => transaction_applied::Varying::FeeTransfer(
1900-
transaction_applied::FeeTransferApplied {
1901-
fee_transfer: WithStatus {
1902-
data: (&ft.fee_transfer.data).try_into()?,
1903-
status: (&ft.fee_transfer.status).into(),
1904-
},
1905-
new_accounts: ft.new_accounts.iter().map(TryInto::try_into).collect::<Result<_, _>>()?,
1906-
burned_tokens: ft.burned_tokens.clone().into(),
1907-
},
1908-
),
1909-
Coinbase(cb) => transaction_applied::Varying::Coinbase(transaction_applied::CoinbaseApplied {
1910-
coinbase: WithStatus {
1911-
data: crate::scan_state::transaction_logic::Coinbase {
1912-
receiver: (&cb.coinbase.data.receiver).try_into()?,
1913-
amount: cb.coinbase.data.amount.clone().into(),
1914-
fee_transfer: match cb.coinbase.data.fee_transfer.as_ref() {
1915-
Some(ft) => Some(crate::scan_state::transaction_logic::CoinbaseFeeTransfer {
1916-
receiver_pk: (&ft.receiver_pk).try_into()?,
1917-
fee: Fee::from_u64(ft.fee.as_u64()),
1918-
}),
1919-
None => None,
1920-
}
1921-
},
1922-
status: (&cb.coinbase.status).into(),
1923-
},
1924-
new_accounts: cb.new_accounts.iter().map(TryInto::try_into).collect::<Result<_, _>>()?,
1925-
burned_tokens: cb.burned_tokens.clone().into(),
1926-
}),
1927-
},
1928-
(id, account)
1894+
Ok((id, account))
19291895
})
1930-
.collect(),
1896+
.collect::<Result<_, _>>()?,
19311897
command: WithStatus {
1932-
data: (&cmd.command.data).into(),
1898+
data: (&cmd.command.data).try_into()?,
19331899
status: (&cmd.command.status).into(),
19341900
},
1935-
new_accounts: cmd.new_accounts.iter().map(Into::into).collect(),
1901+
new_accounts: cmd
1902+
.new_accounts
1903+
.iter()
1904+
.map(TryInto::try_into)
1905+
.collect::<Result<_, _>>()?,
19361906
},
19371907
)),
19381908
),
19391909
},
1940-
FeeTransfer(ft) => transaction_applied::Varying::FeeTransfer(
1941-
transaction_applied::FeeTransferApplied {
1910+
FeeTransfer(ft) => {
1911+
transaction_applied::Varying::FeeTransfer(transaction_applied::FeeTransferApplied {
19421912
fee_transfer: WithStatus {
1943-
data: (&ft.fee_transfer.data).into(),
1913+
data: (&ft.fee_transfer.data).try_into()?,
19441914
status: (&ft.fee_transfer.status).into(),
19451915
},
1946-
new_accounts: ft.new_accounts.iter().map(Into::into).collect(),
1916+
new_accounts: ft
1917+
.new_accounts
1918+
.iter()
1919+
.map(TryInto::try_into)
1920+
.collect::<Result<_, _>>()?,
19471921
burned_tokens: ft.burned_tokens.clone().into(),
1948-
},
1949-
),
1950-
Coinbase(cb) => transaction_applied::Varying::Coinbase(transaction_applied::CoinbaseApplied {
1951-
coinbase: WithStatus {
1952-
data: crate::scan_state::transaction_logic::Coinbase {
1953-
receiver: (&cb.coinbase.data.receiver).into(),
1954-
amount: cb.coinbase.data.amount.clone().into(),
1955-
fee_transfer: cb.coinbase.data.fee_transfer.as_ref().map(|ft| {
1956-
crate::scan_state::transaction_logic::CoinbaseFeeTransfer {
1957-
receiver_pk: (&ft.receiver_pk).into(),
1958-
fee: Fee::from_u64(ft.fee.as_u64()),
1959-
}
1960-
}),
1922+
})
1923+
}
1924+
Coinbase(cb) => {
1925+
transaction_applied::Varying::Coinbase(transaction_applied::CoinbaseApplied {
1926+
coinbase: WithStatus {
1927+
data: crate::scan_state::transaction_logic::Coinbase {
1928+
receiver: (&cb.coinbase.data.receiver).try_into()?,
1929+
amount: cb.coinbase.data.amount.clone().into(),
1930+
fee_transfer: match cb.coinbase.data.fee_transfer.as_ref() {
1931+
Some(ft) => Some(
1932+
crate::scan_state::transaction_logic::CoinbaseFeeTransfer {
1933+
receiver_pk: (&ft.receiver_pk).try_into()?,
1934+
fee: Fee::from_u64(ft.fee.as_u64()),
1935+
},
1936+
),
1937+
None => None,
1938+
},
1939+
},
1940+
status: (&cb.coinbase.status).into(),
19611941
},
1962-
status: (&cb.coinbase.status).into(),
1963-
},
1964-
new_accounts: cb.new_accounts.iter().map(Into::into).collect(),
1965-
burned_tokens: cb.burned_tokens.clone().into(),
1966-
})
1967-
}
1942+
new_accounts: cb
1943+
.new_accounts
1944+
.iter()
1945+
.map(TryInto::try_into)
1946+
.collect::<Result<_, _>>()?,
1947+
burned_tokens: cb.burned_tokens.clone().into(),
1948+
})
1949+
}
1950+
};
1951+
1952+
Ok(result)
19681953
}
19691954
}
19701955

1971-
impl From<&TransactionSnarkScanStateTransactionWithWitnessStableV2> for TransactionWithWitness {
1972-
fn from(value: &TransactionSnarkScanStateTransactionWithWitnessStableV2) -> Self {
1956+
impl TryFrom<&TransactionSnarkScanStateTransactionWithWitnessStableV2> for TransactionWithWitness {
1957+
type Error = InvalidBigInt;
1958+
1959+
fn try_from(
1960+
value: &TransactionSnarkScanStateTransactionWithWitnessStableV2,
1961+
) -> Result<Self, Self::Error> {
19731962
// use mina_p2p_messages::v2::TransactionSnarkPendingCoinbaseStackStateInitStackStableV1::{Base, Merge};
19741963
use mina_p2p_messages::v2::MinaStateSnarkedLedgerStatePendingCoinbaseStackStateInitStackStableV1::{Base, Merge};
19751964
use crate::scan_state::scan_state::transaction_snark::InitStack;
1976-
1977-
Self {
1965+
1966+
Ok(Self {
19781967
transaction_with_info: TransactionApplied {
1979-
previous_hash: value.transaction_with_info.previous_hash.to_field(),
1980-
varying: (&value.transaction_with_info.varying).into(),
1968+
previous_hash: value.transaction_with_info.previous_hash.to_field()?,
1969+
varying: (&value.transaction_with_info.varying).try_into()?,
19811970
},
19821971
state_hash: {
19831972
let (state, body) = &value.state_hash;
@@ -1997,7 +1986,7 @@ impl From<&TransactionSnarkScanStateTransactionWithWitnessStableV2> for Transact
19971986
first_pass_ledger_witness: (&value.first_pass_ledger_witness).try_into()?,
19981987
second_pass_ledger_witness: (&value.second_pass_ledger_witness).try_into()?,
19991988
block_global_slot: Slot::from_u32(value.block_global_slot.as_u32()),
2000-
}
1989+
})
20011990
}
20021991
}
20031992

ledger/src/staged_ledger/staged_ledger.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ impl StagedLedger {
125125
pub fn ledger_mut(&mut self) -> &mut Mask {
126126
&mut self.ledger
127127
}
128-
128+
129129
pub fn proof_txns_with_state_hashes(
130130
&self,
131131
) -> Option<Vec<TransactionsOrdered<(WithStatus<Transaction>, Fp, Slot)>>> {

tools/fuzzing/Cargo.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@ rsprocmaps = "0.3.2"
2323
leb128 = "0.2.1"
2424
rand = { version = "0.8.5", features = ["small_rng"] }
2525
ring_buffer = "2.0.2"
26-
ark-ff = { git = "https://github.com/openmina/algebra", branch = "openmina", features = [ "parallel", "asm", "std" ] }
27-
ark-ec = { git = "https://github.com/openmina/algebra", branch = "openmina", features = [ "std" ] }
26+
ark-ff = { version = "0.3.0", features = [ "parallel", "asm", "std" ] }
27+
ark-ec = { version = "0.3.0", features = [ "std" ] }
28+
#ark-ff = { git = "https://github.com/openmina/algebra", branch = "openmina", features = [ "parallel", "asm", "std" ] }
29+
#ark-ec = { git = "https://github.com/openmina/algebra", branch = "openmina", features = [ "std" ] }
2830
once_cell = "1.18.0"
2931
text-diff = "0.4.0"
3032
num-bigint = "0.4.0"

tools/fuzzing/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# FIXME: not working :(
12
FROM debian:bullseye
23

34
RUN apt -y update && \

0 commit comments

Comments
 (0)