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 sanlee42 committed Mar 22, 2023
1 parent ade5f0f commit 4e0e28c
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 @@ -264,7 +264,7 @@ compiled_package_info:
? address: "0x00000000000000000000000000000001"
name: YieldFarmingV2
: StarcoinFramework
source_digest: 9D5BEAD2A40807817B23BF8C474DA0D8ADC2A14B229B1CF06B74F8726614B3F9
source_digest: 82C91F693CBA69A8415383783174B3D58F464233948146883E10250E47309ED3
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 4e0e28c

Please sign in to comment.