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

[signature] Fix EVMAddress padding and crop bug #84

Merged
merged 1 commit into from
Aug 9, 2022
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
2 changes: 1 addition & 1 deletion build/StarcoinFramework/BuildInfo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ compiled_package_info:
? address: "0x00000000000000000000000000000001"
name: YieldFarmingV2
: StarcoinFramework
source_digest: 909CE74C85980EFA85EC499713FA015307F578F64A8BB1B25942B9F63440DBA4
source_digest: 6F307AEE1142B5C572B5235CABAE88249D55900EC0E687DD762DF015D0591BB1
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);
}
}
}