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
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.
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.
You are limited in the storage size, so I doubt you can store any reasonable logicsic bytecode in the contract storage.