Can a stateful smart contract create a logic sig?

Is there a way for a smart contract’s logic to create a LogicSig with specified logic?

Yes, it’s possible as a logicsig contract account is just the hash of the compiled bytecode of the contract with some prefix.
In the past it was useful to create customized escrow accounts.

Now most use cases can be dealt with inner transactions.

That being said, I can see edge cases where it can still be useful such as Unique NFT ASA Implementation - #2 by fabrice

1 Like

Say I have the bytecode for a stateless contract stored in global storage of the contract. I then hash that and get an address. Is that address immedietly an algorand address, or do I first need to send it some algos for it to “activate”?

Also, i heard using SHA can be quite expensive in terms of opcode cost, is this true?

It’s immediately an Algorand address.
But you need to put some Algos to be able to transact or opt-in to smart contracts.

SHA-512/256 (which is what you need) is a bit expensive but reasonable.
It’s 45 cost (Opcodes - Algorand Developer Portal) out of 700 (if you have a single app call in the group - but you can always have multiple app calls to increase the limit in AVM 1.0). So there is quite a lot of margin there.

1 Like

Just curious about how this works technically. Once the bytecode is hashed, how does the blockchain know about the underlying logic of the bytecode? Obviously, SHA hashes cannot be reversed to the original data, so how does it know about the logic?

Logicsig TEAL bytecode is provided in each transaction using the logicsig.

1 Like

You are limited in the storage size, so I doubt you can store any reasonable logicsic bytecode in the contract storage.

1 Like