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

Murisi/restructure tx #1280

Merged
merged 50 commits into from
Jun 5, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
69deef8
Moving inner_tx from WrapperTx to Tx.
murisi Jan 27, 2023
6809564
Recombined Tx and SigningTx.
murisi Jan 27, 2023
e7f1e42
Hash the inner transaction code before placement inside wrapper.
murisi Jan 30, 2023
c4c2730
Added more error handling and streamlined (de)serialization code.
murisi Feb 6, 2023
2481db5
Fixed formatting and clippy.
murisi Feb 6, 2023
00559e9
[ci] wasm checksums update
github-actions[bot] Feb 6, 2023
2ba70d9
Renamed WrapperTxInQueue to TxInQueue to be more accurate.
murisi Feb 13, 2023
fe8bace
Removed inner_tx_code since it is redundant when with inner_tx.
murisi Feb 14, 2023
5a60a9f
[ci] wasm checksums update
github-actions[bot] Feb 14, 2023
bdfabc1
Add an extra data field to Txs that is hashed before signing.
murisi Feb 20, 2023
7c7b2a2
Reduced the size of InitValidator transactions.
murisi Feb 22, 2023
30aec50
Aligned the signing of reveal transactions with that of other transac…
murisi Feb 22, 2023
309335d
Removed encryption from transactions.
Mar 29, 2023
bbe5d06
Gave inner_tx a stronger type.
Mar 29, 2023
c440ab8
Made transaction data optional.
Mar 29, 2023
fd3a54c
Strengthened the typing of the Tx data field with SignedTxData.
Mar 30, 2023
4cff51d
Separated SignedOuterTxData from SignedTxData. This involved reclassi…
Mar 30, 2023
ccaa950
Restricted the contents of the data field of Tx.
Mar 31, 2023
e4cc937
Renamed the fields of outer transaction to avoid confusion.
Mar 31, 2023
6274db8
Now supply Vps and Txs with full transactions.
Apr 1, 2023
fcc691b
Made outer Tx data non-optional.
Apr 3, 2023
d944b9a
Moved out the InnerTx nested in the header.
Apr 4, 2023
1661782
Renamed outer Tx fields in protobuf to avoid ambiguities.
Apr 4, 2023
b132969
Replaced the inner_tx of Tx with InnerTx fields.
Apr 5, 2023
58bba84
Reduced usage of InnerTx.
Apr 5, 2023
27a4a40
Flattened Tx and InnerTx into one structure.
Apr 7, 2023
1f35ef4
Removed redundant InnerTx usages.
Apr 8, 2023
c4a2c5b
Move shielded transactions out of Transfer and into Tx.
Apr 10, 2023
fa045f5
Re-enabled submission of proposal code.
Apr 10, 2023
ccbcf49
Removed unnecessary fields in Tx. Cleaned up Transfer event creation …
Apr 11, 2023
45a2ad0
Removed the Signed structure as its not currently being used.
Apr 11, 2023
4115880
Deduplicatedd encryption code and tailored it for Section structure.
Apr 11, 2023
a3d861a
Added some documentation to the new Tx structure.
Apr 11, 2023
d2c9e45
Make it easier to update transaction headers.
Apr 11, 2023
6bfb0bc
Upgraded the version of the MASP crate that is used.
Apr 13, 2023
7ed4d07
Make proof reading during transaction validation safe.
Apr 14, 2023
19a7a6c
Separated header validation from header extraction.
Apr 15, 2023
b7d4279
Exclude signatures from MaspTx section hash so that references to it …
Apr 15, 2023
578ee00
Created a new Builder section to witness for Transaction sections.
Apr 15, 2023
b4bd77c
Now attach a Builder instance to Txs.
Apr 16, 2023
6c67c29
Allow the transaction code section to be contracted.
Apr 17, 2023
bd41e39
Added CLI flag to disable checks during transaction construction.
Mar 12, 2023
5b795da
Added function to convert Namada transaction to Ledger vector.
Apr 17, 2023
03a8b80
Simplified hashing so that its mostly based on Borsh.
Apr 17, 2023
81f31e8
Added code to save transactions if NAMADA_LEDGER_LOG_PATH enabled.
Apr 17, 2023
1ff057a
Added code to add transaction debug outputs. Started decoding MASP tr…
Apr 19, 2023
4b65a73
Added asset type decodings to the MaspBuilder section. Now use readab…
Apr 19, 2023
5b0e690
Added some bash scripts to generate test vectors.
Apr 19, 2023
625febe
Improved the formatting of test vectors.
Apr 19, 2023
2466df7
Increased the maximum proposal code size to 500000 so that proposal t…
Apr 20, 2023
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
Made outer Tx data non-optional.
  • Loading branch information
Murisi Tarusenga committed Apr 3, 2023
commit fcc691b3dd9ee899bd3b7b8920cbbd79f2ae1298
35 changes: 16 additions & 19 deletions apps/src/lib/node/ledger/shell/prepare_proposal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,23 +231,21 @@ mod test_prepare_proposal {
// an unsigned wrapper will cause an error in processing
let wrapper = Tx::new(
"".as_bytes().to_owned(),
Some(
SignedOuterTxData {
data: Some(TxType::Wrapper(WrapperTx::new(
Fee {
amount: 0.into(),
token: shell.storage.native_token.clone(),
},
&keypair,
Epoch(0),
0.into(),
#[cfg(not(feature = "mainnet"))]
None,
)
.bind(tx.clone()))),
sig: None,
}
),
SignedOuterTxData {
data: TxType::Wrapper(WrapperTx::new(
Fee {
amount: 0.into(),
token: shell.storage.native_token.clone(),
},
&keypair,
Epoch(0),
0.into(),
#[cfg(not(feature = "mainnet"))]
None,
)
.bind(tx.clone())),
sig: None,
},
)
.attach_inner_tx(&tx, Default::default())
.to_bytes();
Expand Down Expand Up @@ -319,7 +317,7 @@ mod test_prepare_proposal {
expected_wrapper.append(&mut expected_decrypted);
let expected_txs: Vec<SignedOuterTxData> = expected_wrapper
.iter()
.map(|tx| tx.outer_data.clone().expect("Test failed"))
.map(|tx| tx.outer_data.clone())
.collect();
#[cfg(feature = "abcipp")]
{
Expand Down Expand Up @@ -360,7 +358,6 @@ mod test_prepare_proposal {
Tx::try_from(tx_bytes.as_slice())
.expect("Test failed")
.outer_data
.expect("Test failed")
})
.collect();
// check that the order of the txs is correct
Expand Down
20 changes: 9 additions & 11 deletions apps/src/lib/node/ledger/shell/process_proposal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ mod test_process_proposal {
.bind(tx.clone());
let tx = Tx::new(
vec![],
Some(SignedOuterTxData {data: Some(TxType::Wrapper(wrapper)), sig: None}),
SignedOuterTxData {data: TxType::Wrapper(wrapper), sig: None},
)
.attach_inner_tx(&tx, Default::default())
.to_bytes();
Expand Down Expand Up @@ -306,12 +306,11 @@ mod test_process_proposal {
.sign(&keypair)
.expect("Test failed")
.attach_inner_tx(&tx, Default::default());
let new_tx = if let Some(SignedOuterTxData {
data: Some(data),
let new_tx = if let SignedOuterTxData {
data,
sig,
}) = wrapper
} = wrapper
.outer_data
.take()
{
let mut new_wrapper = if let TxType::Wrapper(wrapper) = data {
wrapper
Expand All @@ -324,12 +323,11 @@ mod test_process_proposal {
let new_data = TxType::Wrapper(new_wrapper);
Tx {
outer_code: vec![],
outer_data: Some(
SignedOuterTxData {
sig,
data: Some(new_data),
},
),
outer_data:
SignedOuterTxData {
sig,
data: new_data,
},
outer_timestamp: timestamp,
inner_tx: Some(tx),
outer_extra: vec![],
Expand Down
77 changes: 35 additions & 42 deletions core/src/proto/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ pub struct SignedTxData {
pub sig: Option<common::Signature>,
}

#[derive(Clone, Debug, BorshSerialize, BorshDeserialize, BorshSchema, Default, Deserialize, Serialize)]
#[derive(Clone, Debug, BorshSerialize, BorshDeserialize, BorshSchema, Deserialize, Serialize)]
pub struct SignedOuterTxData {
/// The original tx data bytes, if any
pub data: Option<TxType>,
pub data: TxType,
/// The signature is produced on the tx data concatenated with the tx code
/// and the timestamp.
pub sig: Option<common::Signature>,
Expand Down Expand Up @@ -152,7 +152,7 @@ where
)]
pub struct Tx {
pub outer_code: Vec<u8>,
pub outer_data: Option<SignedOuterTxData>,
pub outer_data: SignedOuterTxData,
pub outer_timestamp: DateTimeUtc,
pub outer_extra: Vec<u8>,
/// the encrypted inner transaction if data contains a WrapperTx
Expand All @@ -175,7 +175,7 @@ pub struct InnerTx {
impl From<SignedOuterTxData> for SignedTxData {
fn from(data: SignedOuterTxData) -> Self {
Self {
data: data.data.map(|x| x.try_to_vec().unwrap()),
data: Some(data.data.try_to_vec().unwrap()),
sig: data.sig,
}
}
Expand All @@ -185,7 +185,7 @@ impl From<Tx> for InnerTx {
fn from(tx: Tx) -> Self {
Self {
code: tx.outer_code,
data: tx.outer_data.map(|x| x.into()),
data: Some(tx.outer_data.into()),
timestamp: tx.outer_timestamp,
extra: tx.outer_extra,
}
Expand All @@ -208,13 +208,14 @@ impl TryFrom<&[u8]> for Tx {
.map_err(Error::TxDeserializingError)
})
.transpose()?;
let data = tx
.data
.map(|x| {
BorshDeserialize::try_from_slice(&x)
.map_err(Error::TxDeserializingError)
})
.transpose()?;
let data = BorshDeserialize::try_from_slice(
&tx
.data
.ok_or(Error::TxDeserializingError(std::io::Error::new(
std::io::ErrorKind::Other,
"Missing data",
)))?
).map_err(Error::TxDeserializingError)?;
Ok(Tx {
outer_code: tx.code,
outer_data: data,
Expand Down Expand Up @@ -257,10 +258,10 @@ impl From<Tx> for types::Tx {
x.try_to_vec()
.expect("Unable to serialize encrypted transaction")
});
let data = tx.outer_data.map(|x| {
x.try_to_vec()
let data = Some(
tx.outer_data.try_to_vec()
.expect("Unable to serialize encrypted transaction")
});
);
types::Tx {
code: tx.outer_code,
data,
Expand Down Expand Up @@ -357,20 +358,8 @@ impl From<Tx> for ResponseDeliverTx {
}
}

impl Default for Tx {
fn default() -> Self {
Tx {
outer_code: vec![],
outer_data: None,
outer_timestamp: DateTimeUtc::now(),
inner_tx: None,
outer_extra: vec![],
}
}
}

impl Tx {
pub fn new(code: Vec<u8>, data: Option<SignedOuterTxData>) -> Self {
pub fn new(code: Vec<u8>, data: SignedOuterTxData) -> Self {
Tx {
outer_code: code,
outer_data: data,
Expand All @@ -381,16 +370,14 @@ impl Tx {
}

pub fn header(&self) -> TxType {
if let Some(data) = self.outer_data.clone().and_then(|data| data.data) {
data
} else {
TxType::Raw(self.clone().into())
}
self.outer_data.data.clone()
}

pub fn code(&self) -> Option<Vec<u8>> {
if let TxType::Decrypted(DecryptedTx::Decrypted {tx, ..}) = self.header() {
return Some(tx.code);
} else if let TxType::Raw(tx) = self.header() {
return Some(tx.code);
}
if let Some(inner_tx) = &self.inner_tx {
Some(inner_tx.code.clone())
Expand All @@ -402,6 +389,8 @@ impl Tx {
pub fn extra(&self) -> Option<Vec<u8>> {
if let TxType::Decrypted(DecryptedTx::Decrypted {tx, ..}) = self.header() {
return Some(tx.extra);
} else if let TxType::Raw(tx) = self.header() {
return Some(tx.extra);
}
if let Some(inner_tx) = &self.inner_tx {
Some(inner_tx.extra.clone())
Expand All @@ -413,6 +402,8 @@ impl Tx {
pub fn data(&self) -> Option<Vec<u8>> {
if let TxType::Decrypted(DecryptedTx::Decrypted {tx, ..}) = self.header() {
return tx.data.and_then(|x| x.data);
} else if let TxType::Raw(tx) = self.header() {
return tx.data.and_then(|x| x.data);
}
if let Some(InnerTx { data: Some(SignedTxData { data, ..}), .. }) = &self.inner_tx {
data.clone()
Expand All @@ -424,6 +415,8 @@ impl Tx {
pub fn data_hash(&self) -> Option<crate::types::hash::Hash> {
if let TxType::Decrypted(DecryptedTx::Decrypted {tx, ..}) = self.header() {
return Some(crate::types::hash::Hash(tx.partial_hash()));
} else if let TxType::Raw(tx) = self.header() {
return Some(crate::types::hash::Hash(tx.partial_hash()));
}
if let Some(tx) = &self.inner_tx {
Some(crate::types::hash::Hash(tx.partial_hash()))
Expand All @@ -435,6 +428,8 @@ impl Tx {
pub fn inner_tx(&self) -> Option<InnerTx> {
if let TxType::Decrypted(DecryptedTx::Decrypted {tx, ..}) = self.header() {
return Some(tx);
} else if let TxType::Raw(tx) = self.header() {
return Some(tx);
}
self.inner_tx.clone()
}
Expand All @@ -452,10 +447,8 @@ impl Tx {
/// leaves out inner tx.
pub fn signing_tx(&self) -> types::Tx {
let timestamp = Some(self.outer_timestamp.into());
let data = self.outer_data.as_ref().map(|x| {
x.try_to_vec()
.expect("Unable to serialize encrypted transaction")
});
let data = Some(self.outer_data.try_to_vec()
.expect("Unable to serialize encrypted transaction"));
types::Tx {
code: hash_tx(&self.outer_code).0.to_vec(),
extra: hash_tx(&self.outer_extra).0.to_vec(),
Expand Down Expand Up @@ -491,12 +484,12 @@ impl Tx {
let to_sign = self.partial_hash();
let sig = common::SigScheme::sign(keypair, to_sign);
let signed = SignedOuterTxData {
data: self.outer_data.and_then(|x| x.data),
data: self.outer_data.data,
sig: Some(sig),
};
Tx {
outer_code: self.outer_code,
outer_data: Some(signed),
outer_data: signed,
outer_extra: self.outer_extra,
outer_timestamp: self.outer_timestamp,
inner_tx: self.inner_tx,
Expand All @@ -511,13 +504,13 @@ impl Tx {
sig: &common::Signature,
) -> std::result::Result<(), VerifySigError> {
// Try to get the transaction data from decoded `SignedTxData`
let signed_tx_data = self.outer_data.clone().ok_or(VerifySigError::MissingData)?;
let signed_tx_data = self.outer_data.clone();
let mut data = signed_tx_data.clone();
data.sig = None;
let tx = Tx {
outer_code: self.outer_code.clone(),
outer_extra: self.outer_extra.clone(),
outer_data: Some(data),
outer_data: data,
outer_timestamp: self.outer_timestamp,
inner_tx: self.inner_tx.clone(),
};
Expand All @@ -532,7 +525,7 @@ impl Tx {
) -> std::result::Result<(), VerifySigError> {
let inner_tx = self.inner_tx();
if self.partial_hash() == hash.0 {
self.outer_data.as_ref().ok_or(VerifySigError::MissingData)?
self.outer_data
.sig.as_ref().ok_or(VerifySigError::MissingData)
.and_then(|sig| self.verify_sig(pk, &sig))
} else if inner_tx.is_some() && inner_tx.as_ref().unwrap().partial_hash() == hash.0 {
Expand Down
12 changes: 4 additions & 8 deletions core/src/types/transaction/decrypted.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,10 @@ pub mod decrypted_tx {
fn from(decrypted: DecryptedTx) -> Self {
Tx::new(
vec![],
Some(
SignedOuterTxData {
data: Some(
TxType::Decrypted(decrypted)
),
sig: None,
}
),
SignedOuterTxData {
data: TxType::Decrypted(decrypted),
sig: None,
},
)
}
}
Expand Down
Loading