Skip to content

Commit

Permalink
fix: try to resolve xudt compatibility issue
Browse files Browse the repository at this point in the history
  • Loading branch information
quake committed Jun 20, 2024
1 parent c8b1140 commit 85904ca
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
1 change: 1 addition & 0 deletions contracts/funding-lock/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ This is a simple funding lock script for ckb fiber network. It utilizes the [ckb

The lock script args is a blake160 hash of the aggregated public key of the two parties, to unlock this lock, the transaction must provide following fields in the witness:

- `empty_witness_args`: 16 bytes, fixed to 0x10000000100000001000000010000000, for compatibility with the xudt
- `version`: 8 bytes, u64 in little-endian
- `funding_out_point`: 36 bytes, out point of the funding transaction
- `pubkey`: 32 bytes, x only aggregated public key
Expand Down
13 changes: 9 additions & 4 deletions contracts/funding-lock/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ pub enum Error {
// Add customized errors here...
MultipleInputs,
WitnessLenError,
EmptyWitnessArgsError,
FundingOutPointError,
AuthError,
}
Expand Down Expand Up @@ -63,18 +64,22 @@ fn auth() -> Result<(), Error> {
return Err(Error::MultipleInputs);
}
let witness = load_witness(0, Source::GroupInput)?;
if witness.len() != 8 + 36 + 32 + 64 {
if witness.len() != 16 + 8 + 36 + 32 + 64 {
return Err(Error::WitnessLenError);
}
let tx_hash = load_tx_hash()?;
let version = witness[0..8].to_vec();
let funding_out_point = witness[8..44].to_vec();
let empty_witness_args = witness[0..16].to_vec();
let version = witness[16..24].to_vec();
let funding_out_point = witness[24..60].to_vec();
let input_out_point = load_input_out_point(0, Source::GroupInput)?;
if empty_witness_args != [16, 0, 0, 0, 16, 0, 0, 0, 16, 0, 0, 0, 16, 0, 0, 0] {
return Err(Error::EmptyWitnessArgsError);
}
if input_out_point.as_slice() != funding_out_point.as_slice() {
return Err(Error::FundingOutPointError);
}
// Schnorr signature cannot recover the public key, so we need to provide the public key
let pubkey_and_signature = witness[44..].to_vec();
let pubkey_and_signature = witness[60..].to_vec();
let message = blake2b_256([version, funding_out_point, tx_hash.to_vec()].concat());

let mut pubkey_hash = [0u8; 20];
Expand Down
1 change: 1 addition & 0 deletions tests/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ fn test_funding_lock() {
println!("signature: {:?}", aggregated_signature_1.to_bytes());

let witness = [
[16, 0, 0, 0, 16, 0, 0, 0, 16, 0, 0, 0, 16, 0, 0, 0].to_vec(),
version.to_vec(),
funding_out_point.to_vec(),
x_only_pub_key.to_vec(),
Expand Down

0 comments on commit 85904ca

Please sign in to comment.