LogcSig (delegated approval) - General - Algorand

LogcSig (delegated approval)

post by anujsaxena97 on Oct 31, 2022

I have question related to LogicSig Implemented

generated LogicSig and signing the transaction with that logicSig, but how can that logicSig be used for the future transactions?


post by scholtz on Nov 1, 2022

You cannot check with logicsig the block number. Only if you make the appcall with logicsig and interact with the dApp.
There is no way to my knowledge that you can make a feature to run the app call / asset transfer or whatever in the future. You always need some offchain trigger that does that in the future.

But generally you can make the logicsig, place there some funds, and if some conditions are met in future anyone can sign the tx with that logicSig account and for example withdraw the funds.


post by anujsaxena97 on Nov 1, 2022

for the next transaction How that same logicSig be used?


post by scholtz on Nov 1, 2022

you can sign many transactions with the same logic sig… logic sig program is even public onchain and everybody can see it.


post by anujsaxena97 on Nov 2, 2022

I have followed some steps for signing the next transactions with the same logicSig:

  1. I have created the logicSig with the teal logic, and we got an escrow account.
  2. We are creating the logisSig for the delegated approval, So I have signed that LogicSig by the private key and public key of the User.
  3. We have signed the transaction with that LogicSig, and again we want to sign more transactions with the same logicSig in this case we stuck as that logicSig is not able to sign the more transactions.

So my question is:
Is there any teal logic do I need to write to increase the number of attempts to sign the transactions by logicSig?
For reference you can check this find what logicSig we are using Algorand Transaction
any reference or code snippet can you provide for that?


post by fabrice on Nov 2, 2022

What is your end goal?

Nowadays, most dApps should use applications. Escrow accounts can be created as application accounts.

This is much more flexible than using logicsigs.

Now, concretely for the logicSig

#pragma version 1
    intcblock 1
    intc_0 // 1

which approves all transactions!

This means anyone can re-use to make any transaction from the account. This is very dangerous.

As a proof, I’ve sent this transaction myself:
https://testnet.algoexplorer.io/tx/Y7KRQVXJBO2OXSRWMFGWW6S5WRZF22RJWXRPJ6KBZAXAVZCVW4ZA

see the note!
Here is what I did:

  1. Recover the signed lsig:
$ curl -s https://testnet-idx.algonode.cloud/v2/transactions/UNEKKO5JP4QLBRDAAY3J3HRMRCVNAGRDHYBL2M7BBQQ5EZKQCTKA | jq
{
  "current-round": 25258013,
  "transaction": {
    "asset-transfer-transaction": {
      "amount": 2000000,
      "asset-id": 10458941,
      "close-amount": 0,
      "receiver": "U3JLNIMNHZ7NWNKAOKSC44GOUF2QR4N42GZL6QFL7IPS3TORIUW3RMH44Y"
    },
    "close-rewards": 0,
    "closing-amount": 0,
    "confirmed-round": 24799938,
    "fee": 1000,
    "first-valid": 24799931,
    "genesis-hash": "SGO1GKSzyE7IEPItTxCByw9x8FmnrCDexi9/cOUJOiI=",
    "genesis-id": "testnet-v1.0",
    "id": "UNEKKO5JP4QLBRDAAY3J3HRMRCVNAGRDHYBL2M7BBQQ5EZKQCTKA",
    "intra-round-offset": 30,
    "last-valid": 24800931,
    "receiver-rewards": 0,
    "round-time": 1665743600,
    "sender": "IDL6C73DAOICYQMOK6EGFFRVZTGINWRDDXSJS3SNMSNX2TGNHYCXBHIKHI",
    "sender-rewards": 0,
    "signature": {
      "logicsig": {
        "args": [
          "bXkgc3RyaW5nIHNlY29uZA=="
        ],
        "logic": "ASABASI=",
        "signature": "PE/xkIakGgyvqOLXAmOk3tTwlD0KWEyozP8wTESRYqTZn/TiQCnazg0dnM6S0HNn5A0ZroVy1sr84eiVuAYrBg=="
      }
    },
    "tx-type": "axfer"
  }
}
  1. create the file thelsig.json with the logic code and signature retrieved above
{
    "l:b64": "ASABASI=",
    "sig:b64": "PE/xkIakGgyvqOLXAmOk3tTwlD0KWEyozP8wTESRYqTZn/TiQCnazg0dnM6S0HNn5A0ZroVy1sr84eiVuAYrBg=="
}
  1. convert it to msgpack (I’m assuming you installed the Algorand developer tools)
$ msgpacktool -e <thelsig.json >thelsig.sig
  1. use goal to send a new transaction with this lsig, that is approved!
goal clerk send --from IDL6C73DAOICYQMOK6EGFFRVZTGINWRDDXSJS3SNMSNX2TGNHYCXBHIKHI --to IDL6C73DAOICYQMOK6EGFFRVZTGINWRDDXSJS3SNMSNX2TGNHYCXBHIKHI --amount 1 --note "this is a proof this lsig is insecure" --logic-sig thelsig.sig

post by anujsaxena97 on Nov 2, 2022

My End Goal Is ,
In my Use case I have to pay in a recurring manner kind of monthly billing of something, In such case we are exploring about the delegated approval where we can Sign the LogicSig once by the User’s private key and public key provided, after signing that logicSig we can do more future transactions without any intervention of the User. (Custodial wallet)

after that my next step goal is :
We will Use the non custodial wallet apps like perawallet for signing the logicSig once by the user and after that we will try to use his logicSig for more transactions on behalf of him for future transactions / monthly billing.

Any suggestion?


post by fabrice on Nov 2, 2022

You can in theory do that by having a logicsig allowing payments every certain time.

As you have seen above delegated logicsigs can be re-used as many times as you want as long as the logic TEAL program approves it. (And it can be used by anyone, not just the creator of the logicsig, unless there is some logic requiring such creator for example to sign something.)

So you essentially need the logicsig to only allow payments once every x rounds and use a lease.

See Leased Transactions for lease, PyTeal Examples — PyTeal documentation for the smart signature code (not audited and requires code around), and Periodic payment smart signature can be used multiple times within the same block · Issue #143 · algorand/pyteal · GitHub for a comment


post by anujsaxena97 on Nov 4, 2022

1- Can we secure logicSig by putting the receiver’s wallet address as receiver of monthly billing will be always same in my use case? 2- Is there any way to secure logicSig from unwanted transactions by teal logic? 3- Can we set future transactions limit and maximum cost of that transaction into the logicSig by teal logic, like for monthly billing that logicSig should only work for single transaction in a month? 4- in above example you have used goal for transaction with the thelsig.sig, can we do same operation with the algoSDK?

Thanks in advance


post by fabrice on Nov 7, 2022

LogicSig is arbitrary code. You can secure them. See the examples linked above.

For a single transaction every x rounds (x being a parameter you choose), this is easy.

For a single transaction every month, this most likely requires a complex code linking it to an application (aka smart contract).

This is possible but requires more work.
Yes, everything done with goal can be done with AlgoSDK (except potentially participation in consensus).


post by anujsaxena97 on Nov 7, 2022

Thanks for your responses! I have created an account on discord and I will query there. Thanks.