Omnilock Script
Omnilock is a Lock Script designed for interoperability. It comes with built-in support for verification of transaction signing methods used in Bitcoin, Ethereum, EOS, Dogecoin and more. It also includes a regulation compliance module, which allows an administrator to revoke tokens held by users under certain circumstances.
How Omnilock Works
An Omnilock Script has the following structure:
Code hash: Omnilock script code hash
Hash type: Omnilock script hash type
Args: <21 byte auth> <Omnilock args>
There are 2 key fields in args
:
auth
: for authentication, generally with a pubkey hash in its contentOmnilock args
: for extra checking control, allowing different modes to be enabled in the sameOmnilock args
The Omnilock args
can be without mode (when Omnilock flags
= 0), while the auth
must be present. The functionality of Omnilock Script without mode is almost the same as a traditional
SECP256K1/blake160 Lock Script. The Omnilock Script can be considered as a traditional Lock Script with additional checking/modes.
Authentication
An authentication (auth) is a 21-byte data structure containing the following components:
<1 byte flag> <20 bytes auth content>
Depending on the value of the flag, the auth content has the following interpretations:
-
0x0: It represents the blake160 hash of a secp256k1 public key. The Lock Script performs secp256k1 signature verification, the same as the SECP256K1/blake160 lock.
-
0x01: It follows the unlocking method used by Ethereum. The signing message hash (sighash_all, see reference implementation) is converted as following:
"0x" + hex(signing message hash)
The hex operator converts the binary into a hex string.
-
0x03: It follows the unlocking method used by Tron. The signing message hash is converted as follows:
"0x" + hex(signing message hash)
-
0x04: It follows the unlocking method used by Bitcoin. The signing message hash is required to be converted as follows:
"CKB (Bitcoin Layer) transaction: 0x" + hex(signing message hash)
This way, it facilitates a neat presentation of messages on wallet interfaces, such as UniSat and OKX.
-
0x05: It follows the unlocking method used by Dogecoin. The signing message hash is converted as follows:
"0x" + hex(signing message hash)
-
0x12: It follows the unlocking same method as 0x02, with the signing message hash to be converted as follows:
"CKB transaction: 0x" + hex(signing message hash)
This way, it facilitates a neat presentation of messages on wallet interfaces, such as MetaMask.
-
0x06: It follows the same unlocking method used by CKB MultiSig with a minor modification. When a message is calculated for signing, there is a step to clear the
witnesses
. In Omnilock, this involves clearing the entirelock
field inwitnesses
. But in CKB MultiSig Script, it is only a partial clearance. This part is used assignatures
followed bymultisig_script
. -
0xFC: It represents the blake160 hash of a Lock Script that checks if the current transaction contains an input Cell with a matching Lock Script. Otherwise, it would return with an error, similar to P2SH in BTC.
-
0xFD: It represents the blake160 hash of a preimage that contains exec information used to delegate signature verification to another Script via exec.
-
0xFE: It represents the blake160 hash of a preimage that contains dynamic linking information used to delegate signature verification to the dynamic linking Script. The interface described in Swappable Signature Verification Protocol Spec is used here.
Omnilock args
The structure of Omnilock args
is as follows:
<1 byte Omnilock flags> <32 byte AdminList cell Type ID, optional> <2 bytes minimum ckb/udt in ACP, optional> <8 bytes since for time lock, optional> <32 bytes type script hash for supply, optional>
Name | Flags | Affected Args | Affected Args Size (byte) | Affected Witness |
---|---|---|---|---|
administrator mode | 0b00000001 | AdminList cell Type ID | 32 | omni_identity/signature in OmniLockWitnessLock |
anyone-can-pay mode | 0b00000010 | minimum ckb/udt in ACP | 2 | N/A |
time-lock mode | 0b00000100 | since for timelock | 8 | N/A |
supply mode | 0b00001000 | type script hash for supply | 32 | N/A |
You can check out the details for different modes at RFC.
Witness Structure
When unlocking an Omnilock, the corresponding witness must be a proper WitnessArgs
data structure in Molecule format. In
the lock field of the WitnessArgs
, an OmniLockWitnessLock
structure must be present as follows:
import xudt_rce;
array Auth[byte; 21];
table Identity {
identity: Auth,
proofs: SmtProofEntryVec,
}
option IdentityOpt (Identity);
// the data structure used in lock field of witness
table OmniLockWitnessLock {
signature: BytesOpt,
omni_identity: IdentityOpt,
preimage: BytesOpt,
}
To learn the detail of witness in Omnilock, check out the RFC
Script Deployed Info
The Omnilock spec has been deployed to CKB's Mainnet Mirana and Testnet Pudge. The following are the deployment details:
Mainnet
parameter | value |
---|---|
code_hash | 0x9b819793a64463aed77c615d6cb226eea5487ccfc0783043a587254cda2b6f26 |
hash_type | type |
tx_hash | 0xc76edf469816aa22f416503c38d0b533d2a018e253e379f134c3985b3472c842 |
index | 0x0 |
dep_type | code |
Testnet
parameter | value |
---|---|
code_hash | 0xf329effd1c475a2978453c8600e1eaf0bc2087ee093c3ee64cc96ec6847752cb |
hash_type | type |
tx_hash | 0x3d4296df1bd2cc2bd3f483f61ab7ebeac462a2f336f2b944168fe6ba5d81c014 |
index | 0x0 |
dep_type | code |