Skip to content

Commit

Permalink
[signature] Fix EVMAddress padding and crop bug (#84)
Browse files Browse the repository at this point in the history
  • Loading branch information
jolestar authored and nkysg committed Mar 3, 2023
1 parent 8edaa39 commit 5ea36b6
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion build/StarcoinFramework/BuildInfo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ compiled_package_info:
? address: "0x00000000000000000000000000000001"
name: YieldFarmingV2
: StarcoinFramework
source_digest: 67767729C9EABF47B639C952C38726E42416E5D8744D7BCA7D1B60F95FED3415
source_digest: 5D9D1DB48FABDB66B69DD23C52DDC141BAFD8E44C0BBCFB4B788EF975DA1A11D
build_flags:
dev_mode: false
test_mode: false
Expand Down
Binary file modified build/StarcoinFramework/bytecode_modules/EVMAddress.mv
Binary file not shown.
Binary file modified build/StarcoinFramework/source_maps/EVMAddress.mvsm
Binary file not shown.
Binary file modified build/StarcoinFramework/source_maps/Signature.mvsm
Binary file not shown.
24 changes: 24 additions & 0 deletions sources/Signature.move
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ module Signature {
spec module {
pragma intrinsic = true;
}

#[test]
fun test_ecrecover_invalid(){
let h = b"00";
let s = b"00";
let addr = ecrecover(h, s);
assert!(Option::is_none(&addr), 1001);
}
}

module EVMAddress{
Expand All @@ -52,6 +60,7 @@ module EVMAddress{
let i = 0;
while (i < EVM_ADDR_LENGTH) {
Vector::push_back(&mut new_bytes, *Vector::borrow(&bytes, i));
i = i + 1;
};
new_bytes
}else if (len == EVM_ADDR_LENGTH){
Expand All @@ -62,6 +71,7 @@ module EVMAddress{
while (i < EVM_ADDR_LENGTH - len) {
// pad zero to address
Vector::push_back(&mut new_bytes, 0);
i = i + 1;
};
Vector::append(&mut new_bytes, bytes);
new_bytes
Expand Down Expand Up @@ -96,5 +106,19 @@ module EVMAddress{
pragma verify = false;
//TODO
}

#[test]
fun test_evm_address_padding(){
let addr1 = new(x"00");
let addr2 = new(x"0000");
assert!(&addr1.bytes == &addr2.bytes, 1001);
}

#[test]
fun test_evm_address_crop(){
let addr1 = new(x"01234567890123456789012345678901234567891111");
let addr2 = new(x"01234567890123456789012345678901234567892222");
assert!(&addr1.bytes == &addr2.bytes, 1001);
}
}
}

0 comments on commit 5ea36b6

Please sign in to comment.