user56: I've just read something that suggests Validators aren't actually kept on the blockchain. To save the space, only the hash of the Validator is kept at the UTxO and users willing to spend it must themselves provide the Validator code with matching hash value.
Besides the funny fact that on-chain code doesn't actually live on the chain, that brings a number of questions, of which the first and most obvious will be:

How the actual Validators are stored? I mean the repositories may and should be distributed and each SC author could provide their own source of the code, but
Is there any standard format of such packages (most likely containing also off-chain code) that could be loaded into wallets or other clients?
Since the hash refers to a compiled version of the Validator, i.e. the Plutus Script code, how could users make sure that the binary is a result of compilation of the source the author publishes? Having the compilator and libraries being developed and optimized, it's almost sure the compilation results will vary over time, obviously changing the hash.


user382: Auxiliary scripts are an attribute in the txbody that can have the validator script in it if it's small enough. You could also have metadata that links your users to the script off-chain.

user2335: As stated by Samuel, the code that a validator runs to check whether a transaction is valid is sent and stored in the transaction body as an input.
So all scripts, be they Plutus or Native scripts, get stored on chain when any UTxO's locked by the script are consumed (though they are not part of the UTxO ledger state, but stored in another part of the ledger) and are retrievable through the chain-indexer, Blockfrost or even in some cases, from some blockchain explorers.
For example, you can use the Blockfrost API "Script CBOR" to access the script CBOR. Here's a link to understand how to do this.
Additionally, if you just look at a sample transaction on CardanoScan itself, for example this transaction claiming an UTxO for the simple "Always succeed" plutus script address [3], we can see that the datum in CBOR is 182a.
Using an online tool caller cbor.me we see that the datum/redeemer was 42 (182a in CBOR hex). The contract bytecode is also listed there, but this is not human-readable plutus core code.
Now for the off-chain part that safely can construct transactions for users, that needs to be distributed by the writer of that script. I know that IOG (also known as IOHK) is building a Dapp store to safely distribute such offline code.
And lastly, you are correct! The plutus script hashes to the address, so if one would change the code, a new address should be used. Note however that complex Dapps may use several contracts, for example look at the Occam dex that they showed off [5] They used 3 contracts to implement certain behavior. So over time use cases may change, and other addresses might be used.
EDIT
After the Vasil HF in the Babbage era, transactions can witness the scripts by referencing them in other UTxO's that may not be consumed in the transaction. This way, scripts do get stored on the active UTxO graph part of the ledger. These referenced validators will also become available inside plutus (6).

56: <p>I've just read something that suggests <a href="https://medium.com/@gianmarcoturchiano/whats-so-different-about-cardano-smart-contracts-anyway-5cbf3c95aa4b" rel="noreferrer">Validators aren't actually kept on the blockchain</a>. To save the space, only the hash of the Validator is kept at the UTxO and users willing to spend it must themselves provide the Validator code with matching hash value.</p>
<p>Besides the funny fact that on-chain code doesn't actually live on the chain, that brings a number of questions, of which the first and most obvious will be:</p>
<ol>
<li>How the actual Validators are stored? I mean the repositories may and should be distributed and each SC author could provide their own source of the code, but</li>
<li>Is there any standard format of such packages (most likely containing also off-chain code) that could be loaded into wallets or other clients?</li>
<li>Since the hash refers to a compiled version of the Validator, i.e. the <em>Plutus Script</em> code, how could users make sure that the binary is a result of compilation of the source the author publishes? Having the compilator and libraries being developed and optimized, it's almost sure the compilation results will vary over time, obviously changing the hash.</li>
</ol>
 382: <p>Auxiliary scripts are an attribute in the txbody that can have the validator script in it if it's small enough. You could also have metadata that links your users to the script off-chain.</p>
 2335: <p>As stated by Samuel, the code that a validator runs to check whether a transaction is valid is sent and stored in the transaction body as an input.</p>
<p>So all scripts, be they Plutus or Native scripts, get stored on chain when any UTxO's locked by the script are consumed (though they are not part of the UTxO ledger state, but stored in another part of the ledger) and are retrievable through the chain-indexer, Blockfrost or even in some cases, from some blockchain explorers.</p>
<p>For example, you can use the Blockfrost API &quot;<a href="https://docs.blockfrost.io/#tag/Cardano-Scripts/paths/%7E1scripts%7E1%7Bscript_hash%7D%7E1cbor/get" rel="nofollow noreferrer">Script CBOR</a>&quot; to access the script CBOR. <a href="https://github.com/mallapurbharat/cardano-tx-sample/blob/513ef239cf182172d9a1afc1ae3ebb94b85b9bdb/plutus/getPlutusCBOR.md" rel="nofollow noreferrer">Here's a link</a> to understand how to do this.</p>
<p>Additionally, if you just look at a sample transaction on CardanoScan itself, for example this transaction claiming an UTxO for the simple &quot;<em>Always succeed</em>&quot; plutus script address [<a href="https://cardanoscan.io/transaction/f5f72ad369da02c772f8e158aaf3ccd41681e73693887f7a38158c53341d495d?tab=contracts" rel="nofollow noreferrer">3</a>], we can see that the datum in CBOR is 182a.</p>
<p>Using an online tool caller <a href="http://cbor.me/" rel="nofollow noreferrer">cbor.me</a> we see that the datum/redeemer was 42 (182a in CBOR hex). The contract bytecode is also listed there, but this is not human-readable plutus core code.</p>
<p>Now for the off-chain part that safely can construct transactions for users, that needs to be distributed by the writer of that script. I know that IOG (also known as IOHK) is building a Dapp store to safely distribute such offline code.</p>
<p>And lastly, you are correct! The plutus script hashes to the address, so if one would change the code, a new address should be used. Note however that complex Dapps may use several contracts, for example look at the Occam dex that they showed off [<a href="https://testnet.cardanoscan.io/transaction/c4650b25dadf55a3d932e320b21432ceb59a8f1d5450400f02fd2f9c97077053?tab=contracts" rel="nofollow noreferrer">5</a>] They used 3 contracts to implement certain behavior. So over time use cases may change, and other addresses might be used.</p>
<p><strong>EDIT</strong>
After the Vasil HF in the Babbage era, transactions can witness the scripts by referencing them in other UTxO's that may not be consumed in the transaction. This way, scripts do get stored on the active UTxO graph part of the ledger. These referenced validators will also become available inside plutus <a href="https://github.com/input-output-hk/plutus/blob/00b2fc41080e544e3e93ac6f1274745100e81dd3/plutus-ledger-api/src/PlutusLedgerApi/V2/Tx.hs#L84" rel="nofollow noreferrer">(6)</a>.</p>
