-
Notifications
You must be signed in to change notification settings - Fork 303
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
Making well-known pre-approved transactions useful #51
Comments
Yes we're working on making this better. In the meanwhile, I think that for this particular case you can achieve what you want by taking advantage of an escrow account where you set its master weight to 0. The property that you want to use is that updating the signers should be done with the last operations within your transaction (to enable/disable the next edges in the graph), not as a way to modify the current transaction; you also need to make sure that the order of those operations are always valid from a signature point of view (see example below for transaction ID #2). Also, something to note is that if a transaction is submitted to the network with a sequence number that doesn't match the current account's counter, it will be rejected without consuming the sequence number. I used sequence number 1 as the sequence number for the escrow account, but of course you'd need to adjust it to be whatever the escrow account has. I also added an extra step, I think you were missing a transition that lets the consumer acknowledge receipt of the goods. Also, I use Transactions should only be signed before submitting to the network in this particular case. Tx #1 Signature: (setup by Consumer)seq=1 Escrow account setup with escrow amount.
Tx #2 Signature: Merchantseq=2 Updated - Merchant said they shipped (no-op= send 1 XLM to self).
Tx #3 Signature: Merchantseq=2 Merchant refunds consumer & account cleanup Tx #4 Signature: Noneseq=2 Valid after T+30days: "UnlockExpiredEscrow" refund & cleanup Tx #5 Signature: Consumerseq=3 New: Consumer acks receipt, release amount from escrow, cleanup Tx #6 Signature: Merchantseq=3 Valid after T+5 days: Merchant - starts dispute "consumer didn't ack/release funds"
Tx #7 Signature: Consumerseq=3 Updated - Consumer starts dispute: "not received"/"not what I wanted" (follows #2)
Tx #8 Signature: Resolver, Merchantseq=4 completeDisputedEscrow: send funds to merchant, fee to Resolver & cleanup Tx #9 Signature: Resolver, Consumerseq=4 refundDisputedEscrow: send funds back to consumer, fee to resolver & cleanup |
In Tx#2:
Including the tx hash of itself is kind of difficult. I recall the documentation saying that the hash of the signed contract would be removed automatically. Tho it does bring up another idea - maybe in the future, the transaction seq number could be included besides the hash, so once it becomes impossible to execute that tx it would be automatically removed? It would also help with long chain of transactions that are dependent on oneanother which makes removing their hashes difficult and freeying up the 20 available signer slots is sometimes needed for large graph. |
Ah yes, sorry the I agree, I think we need to make those one time signatures easier to manage. I don't know what should be enabled just yet at the protocol layer though (a condition on sequence number is just one of the conditions that people may want). One of the steps here that is not easy to do is "cleanup" that cannot be a |
btw, I opened #53 that should help reduce the need to rely on |
@roosmaa, do you feel a core enhancement (CAP) or ecosystem proposal (SEP) is needed, or can we close this out? |
@theaeolianmachine it's been so long since I created this issue that I cannot really answer that question. So let's close this. |
The ability to authorize certain transactions by approving their hash under the account signers is quite a powerful concept. It also has the potential to cater for a certain subset of smart contracts, if used creatively. A state machine can be constructed with the prepared transactions that make up a chain of valid actions that can be executed.
For example, a near-zero-trust escrow account contract could be constructed using those principles. In an escrow smart contract we need 3 parties: the sender, the recipient and the 3rd party dispute resolver. The contract needs to support the following state flows:
This can be achieved by preparing the following transactions:
In order for all parties to trust the contract, the transactions which produce the pre-authorized hashes need to be known by all parties. In effect those transactions can be considered well-known and public knowledge.
In order to setup the transactions in that way we need to rely on couple of assumptions:
My first attempt at limiting transactions to certain signers was to add the signer and increasing the required weights at the start of the transaction and remove them at the end. But apparently the transaction signature validation happens too early for this kind of approach to work (stellar/stellar-core#1329). My second attempt at this was to add the signers to the account and remove the disallowed signers at the beginning of the transaction which results in the transaction failing for wrong users, which by transaction ACID promises made by documentation should work fine. See below for example code of constructing the transactions.
But in reality even the failed transaction manages to increase the account sequence number according to stellar/stellar-core#1330 . Which basically makes well-known public transactions useless as anyone can try to execute them and make them invalid for the future. For example, in our previous escrow example the sender could take the transaction meant for the recipient, submit it with the wrong signatures and the recipient wouldn't ever be able to use that transaction themselves.
In stellar/stellar-core#1330 vogel suggested proposing changes to the protocol that would allow transactions with flexible sequence number to be preauthorized. However, I personally feel that the whole sequence number incremented when the actual transaction failed to apply makes more sense to "fix".
Though, of course, I'm not that versed in the nitty-gritty of the protocol to know why this kind of design decision was made in the first place. Maybe it's for a good reason (protecting against spammy behaviour or some such). Though in that case claiming that the transaction are ACID is somewhat false and the actual usecases for the pre-authorized transaction hashes drops significantly.
I would like to start a discussion around how to make such contracts possible on the Stellar network. And if such usecase is even something that the core team considers worthwhile?
JS code example of constructing an escrow account contract
The text was updated successfully, but these errors were encountered: