title: Corda: How Contract Attachments are being transferred in Transaction?
body: <p>The <a href="https://docs.corda.net/tutorial-attachments.html" rel="nofollow noreferrer">Using Attachments</a> page states:</p>
  
  <blockquote>
    <p>Attachments are ZIP/JAR files referenced from a transaction by hash,
    but not included in the transaction itself.</p>
  </blockquote>
  
  <p>However, <a href="https://docs.corda.net/api-contract-constraints.html?highlight=contractattachment#using-contract-constraints-in-transactions" rel="nofollow noreferrer">API: Contract Constraints page</a> states that:</p>
  
  <blockquote>
    <p>The JAR containing the state and contract classes, and optionally its
    dependencies, are all attached to the transaction.</p>
  </blockquote>
  
  <p>And there is a code snippet showing how to add the Contract Constraint:</p>
  
  <pre><code>transaction.addOutputState(state, constraint = HashAttachmentConstraint(serviceHub.cordappProvider.getContractAttachmentID(CONTRACT_ID)!!))
  </code></pre>
  
  <p>However, while checking out <strong><a href="https://github.com/corda/corda/blob/c32e3a9e267c44d9a995354dc88464c036eedf33/core/src/main/kotlin/net/corda/core/contracts/AttachmentConstraint.kt#L49" rel="nofollow noreferrer">HashAttachment</a></strong> code, I do not see that it contains the internals of Contract Jar file. </p>
  
  <p>My assumption is that we are not transferring the Contract Jar with the Transaction. What happens could be described:</p>
  
  <ol>
  <li>During Nodes start-up Corda scans all CorDapps and load jars that consists of Contract classes into local Attachment Storage.</li>
  <li>Each Output state in the Transaction can have a Contract Constraint.</li>
  <li>During the verification stage, <code>verifyConstraints(contractAttachmentsByContract)</code> will be invoked and those constraints (e.g. HashAttachmentConstraint) will be validated against attachments that Node has in its local storage.</li>
  </ol>
  
  <p>Questions:</p>
  
  <ol>
  <li>Does Transaction include the Contract Attachment?</li>
  <li>Will that Contract Attachment be transferred over the network or attachments from the local attachment storage will be used for verification?</li>
  <li>What am I missing something in my assumption?</li>
  </ol>