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: sui rlp upgrade #417

Merged
merged 3 commits into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 5 additions & 5 deletions contracts/sui/libs/sui_rlp/sources/encoder.move
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ module sui_rlp::encoder {
vector::append(&mut encoded_list,result);

} else {
let length_bytes = utils::to_bytes_u64(len,false);
let length_bytes = utils::to_bytes_u64_sign(len,false);
let prefix = (0xf7 + vector::length(&length_bytes)) as u8;
vector::push_back(&mut encoded_list, prefix);
vector::append(&mut encoded_list, length_bytes);
Expand All @@ -69,7 +69,7 @@ module sui_rlp::encoder {
let len_u8=(len as u8);
vector::push_back(&mut length_info,(offset+len_u8));
}else {
let length_bytes=utils::to_bytes_u64(len,false);
let length_bytes=utils::to_bytes_u64_sign(len,false);
let length_byte_len=vector::length(&length_bytes);
let length_byte_len=offset+(length_byte_len as u8);
vector::push_back(&mut length_info,length_byte_len);
Expand All @@ -86,19 +86,19 @@ module sui_rlp::encoder {
}

public fun encode_u32(num:u32):vector<u8>{
let vec= utils::to_bytes_u32(num,true);
let vec= utils::to_bytes_u32_sign(num,true);
encode(&vec)

}

public fun encode_u64(num:u64):vector<u8>{
let vec= utils::to_bytes_u64(num,true);
let vec= utils::to_bytes_u64_sign(num,true);
encode(&vec)

}

public fun encode_u128(num:u128):vector<u8>{
let vec= utils::to_bytes_u128(num,true);
let vec= utils::to_bytes_u128_sign(num,true);
encode(&vec)
}

Expand Down
29 changes: 23 additions & 6 deletions contracts/sui/libs/sui_rlp/sources/utils.move
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,35 @@ module sui_rlp::utils {

}

public fun to_bytes_u128(number:u128,signed:bool):vector<u8>{
//Deprecated
public fun to_bytes_u128(number:u128):vector<u8>{
let bytes=bcs::to_bytes(&number);
to_signed_bytes(bytes,true)
}

public fun to_bytes_u128_sign(number:u128,signed:bool):vector<u8>{
let bytes=bcs::to_bytes(&number);
to_signed_bytes(bytes,signed)
}

//Deprecated
public fun to_bytes_u64(number:u64):vector<u8>{
let bytes=bcs::to_bytes(&number);
to_signed_bytes(bytes,true)
}

public fun to_bytes_u64(number:u64,signed:bool):vector<u8>{
public fun to_bytes_u64_sign(number:u64,signed:bool):vector<u8>{
let bytes=bcs::to_bytes(&number);
to_signed_bytes(bytes,signed)
}

//Deprecated
public fun to_bytes_u32(number: u32): vector<u8> {
let bytes=bcs::to_bytes(&number);
to_signed_bytes(bytes,true)
}

public fun to_bytes_u32(number: u32,signed:bool): vector<u8> {
public fun to_bytes_u32_sign(number: u32,signed:bool): vector<u8> {
let bytes=bcs::to_bytes(&number);
to_signed_bytes(bytes,signed)
}
Expand Down Expand Up @@ -120,7 +137,7 @@ module sui_rlp::utils_test {
#[test]
fun test_u32_conversion() {
let num= (122 as u32);
let bytes= utils::to_bytes_u32(num,true);
let bytes= utils::to_bytes_u32_sign(num,true);
let converted=utils::from_bytes_u32(&bytes);
assert!(num==converted,0x01);

Expand All @@ -129,7 +146,7 @@ module sui_rlp::utils_test {
#[test]
fun test_u64_conversion() {
let num= (55000 as u64);
let bytes= utils::to_bytes_u64(num,true);
let bytes= utils::to_bytes_u64_sign(num,true);
let converted=utils::from_bytes_u64(&bytes);
std::debug::print(&bytes);
std::debug::print(&converted);
Expand All @@ -140,7 +157,7 @@ module sui_rlp::utils_test {
#[test]
fun test_u128_conversion() {
let num= (1222223333 as u128);
let bytes= utils::to_bytes_u128(num,true);
let bytes= utils::to_bytes_u128_sign(num,true);
std::debug::print(&bytes);
let converted=utils::from_bytes_u128(&bytes);
std::debug::print(&converted);
Expand Down
Loading