-
Notifications
You must be signed in to change notification settings - Fork 79
refactor: input note authentication deduced by client #1624
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: next
Are you sure you want to change the base?
Changes from 4 commits
8ad3365
1925d41
ae4110d
3e3feca
a9e5113
fb7b469
2b9bc78
8db0e04
4f4a2f5
c655226
3873f12
c07e634
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 |
|---|---|---|
|
|
@@ -118,17 +118,25 @@ pub async fn test_swap_fully_onchain(client_config: ClientConfig) -> Result<()> | |
| client2.sync_state().await?; | ||
| println!("Consuming swap note on second client..."); | ||
|
|
||
| let tx_request = TransactionRequestBuilder::new() | ||
| .build_consume_notes(vec![expected_output_notes[0].id()])?; | ||
| let note = client2 | ||
| .get_input_note(expected_output_notes[0].id()) | ||
| .await? | ||
| .unwrap() | ||
| .try_into()?; | ||
| let tx_request = TransactionRequestBuilder::new().build_consume_notes(vec![note])?; | ||
|
Comment on lines
+121
to
+126
Collaborator
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. As mentioned in #1112 (comment), this does make this scenario a bit more inconvenient. I guess we could add some other way of expressing notes via note IDs but maybe this defeats the original purpose. Nothing to do for now but just making a note. Would be nice to know @mmagician's opinion on this.
Collaborator
Author
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. One possibility I can think of is wrapping the input notes the enum InputNote {
/// InputNote to be used is assumed to be present
/// on the store.
Stored(NoteId)
/// InputNote provided fully. May still be present
/// on the store.
Provided(Note)
}
#[derive(Clone, Debug)]
pub struct TransactionRequestBuilder {
/// Notes to be consumed by the transaction.
input_notes: Vec<InputNote>,
...
}This way we can still take just What do you think?
Collaborator
Author
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. Following on the proposed
The current implementation does not have this vulnerability, as we are using the notes retrieved from the store: // Retrieve all input notes from the store.
let mut authenticated_note_records = self
.store
.get_input_notes(NoteFilter::List(transaction_request.get_input_note_ids()))
.await?;
// Verify that none of the authenticated input notes are already consumed.
for note in authenticated_note_records.iter() {
if note.is_consumed() {
return Err(ClientError::TransactionRequestError(TransactionRequestError::InputNoteAlreadyConsumed(note.id())));
}
}
// Only keep authenticated input notes from the store.
authenticated_note_records.retain(InputNoteRecord::is_authenticated);But a future "optimization" might use the provided notes instead. |
||
| execute_tx_and_sync(&mut client2, account_b.id(), tx_request).await?; | ||
|
|
||
| // sync on client 1, we should get the missing payback note details. | ||
| // try consuming the received note with accountA, it should now have 25 ETH | ||
| client1.sync_state().await?; | ||
| println!("Consuming swap payback note on first client..."); | ||
|
|
||
| let tx_request = TransactionRequestBuilder::new() | ||
| .build_consume_notes(vec![expected_payback_note_details[0].id()])?; | ||
| let note = client1 | ||
| .get_input_note(expected_payback_note_details[0].id()) | ||
| .await? | ||
| .unwrap() | ||
| .try_into()?; | ||
| let tx_request = TransactionRequestBuilder::new().build_consume_notes(vec![note])?; | ||
| execute_tx_and_sync(&mut client1, account_a.id(), tx_request).await?; | ||
|
|
||
| // At the end we should end up with | ||
|
|
@@ -322,17 +330,25 @@ pub async fn test_swap_private(client_config: ClientConfig) -> Result<()> { | |
| // consume swap note with accountB, and check that the vault changed appropriately | ||
| println!("Consuming swap note on second client..."); | ||
|
|
||
| let tx_request = TransactionRequestBuilder::new() | ||
| .build_consume_notes(vec![expected_output_notes[0].id()])?; | ||
| let note = client2 | ||
| .get_input_note(expected_output_notes[0].id()) | ||
| .await? | ||
| .unwrap() | ||
| .try_into()?; | ||
| let tx_request = TransactionRequestBuilder::new().build_consume_notes(vec![note])?; | ||
| execute_tx_and_sync(&mut client2, account_b.id(), tx_request).await?; | ||
|
|
||
| // sync on client 1, we should get the missing payback note details. | ||
| // try consuming the received note with accountA, it should now have 25 ETH | ||
| client1.sync_state().await?; | ||
| println!("Consuming swap payback note on first client..."); | ||
|
|
||
| let tx_request = TransactionRequestBuilder::new() | ||
| .build_consume_notes(vec![expected_payback_note_details[0].id()])?; | ||
| let note = client1 | ||
| .get_input_note(expected_payback_note_details[0].id()) | ||
| .await? | ||
| .unwrap() | ||
| .try_into()?; | ||
| let tx_request = TransactionRequestBuilder::new().build_consume_notes(vec![note])?; | ||
| execute_tx_and_sync(&mut client1, account_a.id(), tx_request).await?; | ||
|
|
||
| // At the end we should end up with | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.