Skip to content

Commit

Permalink
Merge pull request #408 from icon-project/fix/rlp-zero-values
Browse files Browse the repository at this point in the history
fix: rlp zero values
  • Loading branch information
gcranju authored Nov 14, 2024
2 parents 756c5b8 + d595c10 commit 2a22cfd
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
25 changes: 25 additions & 0 deletions contracts/sui/libs/sui_rlp/sources/encoder.move
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ module sui_rlp::encoder {
let vec=vector::singleton(num);
encode(&vec)

}

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

}

public fun encode_u64(num:u64):vector<u8>{
Expand Down Expand Up @@ -126,5 +132,24 @@ module sui_rlp::encoder {
vector<u8>[0]
}

#[test]
fun test_encode_zero_value(){
let num=0_u128;
let bytes=encode_u128(num);
assert!(bytes==x"00");

let num=0_u64;
let bytes=encode_u64(num);
assert!(bytes==x"00");

let num=0_u32;
let bytes=encode_u32(num);
assert!(bytes==x"00");

let num=0_u8;
let bytes=encode_u8(num);
assert!(bytes==x"00");
}


}
7 changes: 5 additions & 2 deletions contracts/sui/libs/sui_rlp/sources/utils.move
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,11 @@ module sui_rlp::utils {

i = i + 1;
};

result
if (result.length()==0){
vector<u8>[0]
}else{
result
}
}


Expand Down

0 comments on commit 2a22cfd

Please sign in to comment.