Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug: When using dynamic linking, auth will be loaded repeatedly. #27

Merged
merged 27 commits into from
Dec 19, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
d6656ec
Fix bug: When using dynamic linking, auth will be loaded repeatedly.
joii2020 Dec 8, 2023
8f5ee08
Update Readme
joii2020 Dec 7, 2023
2c63cf0
test support auth-rust-lock
joii2020 Dec 12, 2023
c571024
ckb-auth-rs dl context in static memory
joii2020 Dec 12, 2023
b5083c6
Fix bug in auht-rust-lock
joii2020 Dec 12, 2023
d2b6b19
Add Cargo.lock
joii2020 Dec 12, 2023
e4204ea
Support feature enable-dynamic-library
joii2020 Dec 13, 2023
298815c
Add testcase about ckb-auth-rs features
joii2020 Dec 13, 2023
8f65686
Execute ckb-auth twice consecutively in auth-rust-lock
joii2020 Dec 13, 2023
a826903
Fix CI: rust-demo-tests build before testing
joii2020 Dec 13, 2023
f7391c1
ckb-auth-rs: Defaule enable dynamic-library
joii2020 Dec 13, 2023
d5aa298
Replace DynamicLinking to DynamicLibrary in ckb-auth-rs
joii2020 Dec 13, 2023
8b69cc2
Fix CI: aut-rust-demo add no default features
joii2020 Dec 13, 2023
0cfc9c4
Add more comments
XuJiandong Dec 13, 2023
8d5bc21
Merge pull request #3 from XuJiandong/add-comments
joii2020 Dec 13, 2023
bd31ce4
C ckb_auht.h support multi dynamic lib
joii2020 Dec 13, 2023
2d0847f
Some numbers are replaced with macros
joii2020 Dec 13, 2023
bc07adb
ckb_auth.h: EntryCategoryDynamicLinking replace to EntryCategoryDynam…
joii2020 Dec 13, 2023
71ea418
Init dynamic library global cache to zero
joii2020 Dec 13, 2023
8ec271c
Add comment
joii2020 Dec 13, 2023
14531e0
Fix CI: warning with docker
joii2020 Dec 13, 2023
bfc2db8
Update Cargo.lock
joii2020 Dec 13, 2023
e9b77fd
Add macro CKB_AUTH_DISABLE_DYNAMIC_LIB.
joii2020 Dec 13, 2023
d493e86
Add testcase: When disable dynamic lib
joii2020 Dec 13, 2023
9a2f645
Update auth.md, about dynamic library
joii2020 Dec 13, 2023
451d581
Fix CI: auth-c-lock add auth_c_lock_disable_dl
joii2020 Dec 13, 2023
04a659e
rust dynamic lib cache remains aligned
joii2020 Dec 18, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions c/ckb_auth.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,19 +120,24 @@ typedef int (*ckb_auth_validate_t)(uint8_t auth_algorithm_id,
uint32_t pubkey_hash_size);

static uint8_t g_code_buff[300 * 1024] __attribute__((aligned(RISCV_PGSIZE)));
static void* g_code_handle;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

init it to zero.


int ckb_auth(CkbEntryType *entry, CkbAuthType *id, const uint8_t *signature,
uint32_t signature_size, const uint8_t *message32) {
int err = 0;
if (entry->entry_category == EntryCategoryDynamicLinking) {
void *handle = NULL;
size_t consumed_size = 0;
err = ckb_dlopen2(entry->code_hash, entry->hash_type, g_code_buff,
sizeof(g_code_buff), &handle, &consumed_size);
if (err != 0) return err;

if (!g_code_handle) {
err = ckb_dlopen2(entry->code_hash, entry->hash_type, g_code_buff,
sizeof(g_code_buff), &g_code_handle, &consumed_size);
if (err != 0) {
return err;
}
}

ckb_auth_validate_t func =
(ckb_auth_validate_t)ckb_dlsym(handle, "ckb_auth_validate");
(ckb_auth_validate_t)ckb_dlsym(g_code_handle, "ckb_auth_validate");
if (func == 0) {
return CKB_INVALID_DATA;
}
Expand Down
11 changes: 9 additions & 2 deletions tests/auth-c-lock/auth_c_lock.c
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,13 @@ int main() {
break;
}

return ckb_auth(&entry, &auth, lock_bytes_seg.ptr, lock_bytes_seg.size,
msg32);
ret = ckb_auth(&entry, &auth, lock_bytes_seg.ptr, lock_bytes_seg.size, msg32);
XuJiandong marked this conversation as resolved.
Show resolved Hide resolved
if (ret) {
return ret;
}
ret = ckb_auth(&entry, &auth, lock_bytes_seg.ptr, lock_bytes_seg.size, msg32);
if (ret) {
return ret;
}
return 0;
}
1 change: 1 addition & 0 deletions tests/auth-rust-lock/contracts/auth-rust-demo/src/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ pub fn main() -> Result<(), Error> {
.unwrap(),
};

ckb_auth(&entry, &id, &signature, &message)?;
ckb_auth(&entry, &id, &signature, &message)?;

Ok(())
Expand Down