-
Notifications
You must be signed in to change notification settings - Fork 49
feat: cbor witnesses support #830
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,8 +1,11 @@ | ||||||||||||||||||||||||
| use jsonrpsee::types::Params; | ||||||||||||||||||||||||
| use pallas::{codec::utils::NonEmptySet, ledger::primitives::conway::VKeyWitness}; | ||||||||||||||||||||||||
| use pallas::{ | ||||||||||||||||||||||||
| codec::utils::NonEmptySet, | ||||||||||||||||||||||||
| ledger::primitives::conway::{VKeyWitness, WitnessSet}, | ||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||
| use std::sync::Arc; | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| use tx3_resolver::trp::{ResolveParams, SubmitParams, SubmitResponse, SubmitWitness, TxEnvelope}; | ||||||||||||||||||||||||
| use tx3_resolver::{trp::{ResolveParams, SubmitResponse, SubmitParams, WitnessInput, TxEnvelope}}; | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| use dolos_core::{facade::receive_tx, Domain, MempoolAwareUtxoStore, StateStore as _}; | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
|
|
@@ -39,15 +42,32 @@ | |||||||||||||||||||||||
| }) | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| fn apply_witnesses(original: &[u8], witnesses: &[SubmitWitness]) -> Result<Vec<u8>, Error> { | ||||||||||||||||||||||||
| fn apply_witnesses(original: &[u8], witnesses: &[WitnessInput]) -> Result<Vec<u8>, Error> { | ||||||||||||||||||||||||
| let tx = pallas::ledger::traverse::MultiEraTx::decode(original)?; | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| let mut tx = tx.as_conway().ok_or(Error::UnsupportedTxEra)?.to_owned(); | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| let map_witness = |witness: &SubmitWitness| VKeyWitness { | ||||||||||||||||||||||||
| vkey: Vec::<u8>::from(witness.key.clone()).into(), | ||||||||||||||||||||||||
| signature: Vec::<u8>::from(witness.signature.clone()).into(), | ||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||
| let mut new_vkeys = Vec::new(); | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| for witness in witnesses { | ||||||||||||||||||||||||
| match witness { | ||||||||||||||||||||||||
| WitnessInput::Object(w) => { | ||||||||||||||||||||||||
| new_vkeys.push(VKeyWitness { | ||||||||||||||||||||||||
| vkey: Vec::<u8>::from(w.key.clone()).into(), | ||||||||||||||||||||||||
| signature: Vec::<u8>::from(w.signature.clone()).into(), | ||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| WitnessInput::Hex(h) => { | ||||||||||||||||||||||||
| let bytes = hex::decode(h).map_err(|_| Error::InternalError("Invalid witness hex".into()))?; | ||||||||||||||||||||||||
| let witness_set: WitnessSet = pallas::codec::minicbor::decode(&bytes) | ||||||||||||||||||||||||
| .map_err(|_| Error::InternalError("Invalid witness set cbor".into()))?; | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| if let Some(vkeys) = witness_set.vkeywitness { | ||||||||||||||||||||||||
| new_vkeys.extend(vkeys.to_vec()); | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| let mut witness_set = tx.transaction_witness_set.unwrap(); | ||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Handle missing witness set to prevent panic. The 🔎 Proposed fix to handle missing witness set- let mut witness_set = tx.transaction_witness_set.unwrap();
+ let mut witness_set = tx.transaction_witness_set.unwrap_or_else(|| WitnessSet {
+ vkeywitness: None,
+ native_script: None,
+ bootstrap_witness: None,
+ plutus_v1_script: None,
+ plutus_data: None,
+ redeemer: None,
+ plutus_v2_script: None,
+ plutus_v3_script: None,
+ });📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
|
|
@@ -57,9 +77,7 @@ | |||||||||||||||||||||||
| .flat_map(|x| x.iter()) | ||||||||||||||||||||||||
| .cloned(); | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| let new = witnesses.iter().map(map_witness); | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| let all: Vec<_> = old.chain(new).collect(); | ||||||||||||||||||||||||
| let all: Vec<_> = old.chain(new_vkeys).collect(); | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| witness_set.vkeywitness = NonEmptySet::from_vec(all); | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider adding size limits and validation for witness inputs.
The function accepts unbounded hex-encoded witness data without size validation, which could be exploited for denial-of-service attacks through excessive memory consumption or maliciously crafted CBOR payloads.
Consider adding:
🤖 Prompt for AI Agents