# CKB Witness Layout Selection Proposal
## Metadata
**Status**:: #x
**Zettel**:: #zettel/permanent
**Created**:: [[2023-12-29]]
**Topic**:: [[♯ CKB Co-Build]]
**Notion**:: [CKB Witness Layout Selection Proposal](https://www.notion.so/cryptape/CKB-Witness-Layout-Selection-Proposal-32fe028e587b413e864fd370ac48d76c)
## Synopsis
There are many legacy scripts can only support WitnessArgs layout, this proposal describes a workflow to build transactions containing both legacy WitnessArgs layout scripts, and new Co-Build layout scripts.
[RFC 2119: Key words for use in RFCs to Indicate Requirement Levels (rfc-editor.org)](https://www.rfc-editor.org/rfc/rfc2119)
## Workflow
The whole workflow consists of 3 phases: Type Script Phase, Lock Script Phase, and an optional Fallback Phase.
### P1. Type Script Phase
For each type script in both input and output cells, if it needs to store data in witness:
1. If the type script supports Co-Build, it MUST add the data as an action in Co-Build message.
2. If the type script MUST use WitnessArgs, it MUST add them now into the transaction.
The order to process type scripts does not matter.
### P2. Lock Script Phase
In this phase, lock script which supports Co-Build MUST check whether it CAN use Co-Build layout.
For Co-Build Sighash transactions, the lock script MUST NOT use Co-Build layout if any non-blank witness is present and has the same index as any input locked by this lock script.
For Co-Build Otx transactions, TODO.
The Lock Script Phase performs for each lock script in input cells:
1. If the lock script supports Co-Build and it CAN use Co-Build layout, it MUST use Co-Build layout.
2. If the lock script supports Co-Build and it MUST NOT use Co-Build layout
- a. If it CAN support WitnessArgs layout, it MUST use WitnessArgs layout.
- b. Otherwise it MUST abort the transaction building.
3. If the lock script MUST use WitnessArgs layout, it MUST add them now into the transaction.
The order to process lock scripts does not matter. If any script adds new WitnessArgs in indices not in its lock script group in this round, another round of Phase 2 is REQUIRED.
### P3. Fallback Phase
The Fallback Phrase is required when there are no lock scripts using Co-Build layout and the Co-Build message is not empty.
In this phrase, for each type script that has set an action in the Co-Build message:
1. If the type script CAN support WitnessArgs layout, switch to WitnessArgs layout and remove the action from the message.
2. Otherwise it MUST abort the transaction building.