stas-token / stas-sdk

STAS token sdk
https://docs.stastoken.com/
MIT License
5 stars 0 forks source link

why cant we have multiple input more than 2 > s for merge , merge split etc #13

Open nikhil478 opened 1 month ago

nikhil478 commented 1 month ago

@paulsp94 @viralbhadeshiya @adityapanther-vaionex @cainnusti @BishopVNX

cainnusti commented 1 month ago

Hi @nikhil478 thanks for the question. The current templates only support two inputs for merging due to a limitation in the smart contract design. This restriction is based on script size, as the transaction size grows exponentially with the addition of more inputs. New script templates are being developed to remove this limitation, but there is no confirmed release date yet.

Using the two-input limit, we can create multiple merge transactions to consolidate them into a single UTXO. Although this process generates many transactions, the total size of the combined transactions remains smaller than the exponential growth that occurs when adding more inputs to a merge or merge-split transaction.

I will work on adding a bulk merging component to the library to assist developers in constructing the necessary transactions to consolidate UTXOs. This will involve providing a single STAS script and an array of objects representing each UTXO ({vout, satoshis, txid}). A fee module will also be included to calculate the fees for each transaction.

The output will be an array of transactions that can be bulk broadcasted to ARC or mAPI nodes. I have developed some proof-of-concept models that can bulk merge 500 UTXOs in a single broadcast event.

nikhil478 commented 1 month ago

oh gotcha r u checking script size on web2 level or is this an script condition which we need to satisfy? @cainnusti

with bigger script size only cons is high fee right ?

nikhil478 commented 1 month ago

or could you share your poc model is possible

cainnusti commented 1 month ago

oh gotcha r u checking script size on web2 level or is this an script condition which we need to satisfy? @cainnusti

with bigger script size only cons is high fee right ?

It is a script condition but as part of the design its more about size and practicality. The number of transactions is not the issue its more about the overall size to process the consolidation of UTXOs. The optimal method is using a layered approach to merging with transfers transactions to keep the overall size lower.

cainnusti commented 1 month ago

or could you share your poc model is possible

Here is an example of the model to follow in the image The general process for the most optimal method is as follows

  1. All UTXOs previous transactions should be minimal size which is a transfer transaction.
  2. All UTXOs can be in two sequential merge transactions before the UTXO is required to be "reset" which is just constructing another transfer transaction.
  3. Repeat the process until reaching the single UTXO remaining.

Things to consider

I will work to add a module for merging to the library in the meantime.

stasMerge

nikhil478 commented 3 weeks ago

Hi @cainnusti thanks for explaining , i am having one query like why size of script increases so much while merging

cainnusti commented 3 weeks ago

Hi @cainnusti thanks for explaining , I am having one query like why size of script increases so much while merging

@nikhil478 the way the smart contract is defined requires the previous transaction pieces to be part of the unlocking script. After each merge transaction the unlocking script grows at an exponential rate, this is because the previous transaction grows each time with the addition of more data. To circumvent this we can add interval transfer transactions after each 2 sequential merge transactions for each UTXO, as mentioned in the method above.

I will provide a module for merging to the library as soon as possible. Thanks