Skip to content

Commit

Permalink
Merge branch 'master' into mpm-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
jolestar authored Aug 14, 2022
2 parents 73d3e7a + a991c9b commit bebc454
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
18 changes: 9 additions & 9 deletions contrib-contracts/modules/EthStateVerifier.move
Original file line number Diff line number Diff line change
Expand Up @@ -28,35 +28,35 @@ module RLP {
/// Nested arrays are not supported.
public fun decode_list(data: &vector<u8>): vector<vector<u8>> {
let (decoded, consumed) = decode(data, 0);
assert(consumed == Vector::length(data), INVALID_RLP_DATA);
assert!(consumed == Vector::length(data), INVALID_RLP_DATA);
decoded
}

fun decode(data: &vector<u8>, offset: u64): (vector<vector<u8>>, u64) {
let data_len = Vector::length(data);
assert(offset < data_len, DATA_TOO_SHORT);
assert!(offset < data_len, DATA_TOO_SHORT);
let first_byte = *Vector::borrow(data, offset);
if (first_byte >= 248u8) { // 0xf8
let length_of_length = ((first_byte - 247u8) as u64);
assert(offset + length_of_length < data_len, DATA_TOO_SHORT);
assert!(offset + length_of_length < data_len, DATA_TOO_SHORT);
let length = unarrayify_integer(data, offset + 1, (length_of_length as u8));
assert(offset + length_of_length + length < data_len, DATA_TOO_SHORT);
assert!(offset + length_of_length + length < data_len, DATA_TOO_SHORT);
decode_children(data, offset, offset + 1 + length_of_length, length_of_length + length)
} else if (first_byte >= 192u8) { // 0xc0
let length = ((first_byte - 192u8) as u64);
assert(offset + length < data_len, DATA_TOO_SHORT);
assert!(offset + length < data_len, DATA_TOO_SHORT);
decode_children(data, offset, offset + 1, length)
} else if (first_byte >= 184u8) { // 0xb8
let length_of_length = ((first_byte - 183u8) as u64);
assert(offset + length_of_length < data_len, DATA_TOO_SHORT);
assert!(offset + length_of_length < data_len, DATA_TOO_SHORT);
let length = unarrayify_integer(data, offset + 1, (length_of_length as u8));
assert(offset + length_of_length + length < data_len, DATA_TOO_SHORT);
assert!(offset + length_of_length + length < data_len, DATA_TOO_SHORT);

let bytes = Bytes::slice(data, offset + 1 + length_of_length, offset + 1 + length_of_length + length);
(Vector::singleton(bytes), 1+length_of_length+length)
} else if (first_byte >= 128u8) { // 0x80
let length = ((first_byte - 128u8) as u64);
assert(offset + length < data_len, DATA_TOO_SHORT);
assert!(offset + length < data_len, DATA_TOO_SHORT);
let bytes = Bytes::slice(data, offset + 1, offset + 1 + length);
(Vector::singleton(bytes), 1+length)
} else {
Expand All @@ -72,7 +72,7 @@ module RLP {
let (decoded, consumed) = decode(data, child_offset);
Vector::append(&mut result, decoded);
child_offset = child_offset + consumed;
assert(child_offset <= offset + 1 + length, DATA_TOO_SHORT);
assert!(child_offset <= offset + 1 + length, DATA_TOO_SHORT);
};
(result, 1 + length)
}
Expand Down
4 changes: 2 additions & 2 deletions contrib-contracts/modules/MerkleDistributor.move
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,11 @@ module MerkleDistributor {

fun internal_claim<T: store>(distribution: &mut MerkleDistribution<T>, index: u64, account: address, amount: u128, merkle_proof: vector<vector<u8>>): Token<T> {
let claimed = is_claimed_(distribution, index);
assert(!claimed, Errors::custom(ALREADY_CLAIMED));
assert!(!claimed, Errors::custom(ALREADY_CLAIMED));

let leaf_data = encode_leaf(&index, &account, &amount);
let verified = MerkleProof::verify(&merkle_proof, &distribution.merkle_root, Hash::sha3_256(leaf_data));
assert(verified, Errors::custom(INVALID_PROOF));
assert!(verified, Errors::custom(INVALID_PROOF));

set_claimed_(distribution, index);

Expand Down
2 changes: 1 addition & 1 deletion vm/types/src/account_address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ mod test {

#[test]
fn address_hash() {
let address: AccountAddress = "ca843279e3427144cead5e4d5999a3d0".parse().unwrap();
let address: AccountAddress = "0xca843279e3427144cead5e4d5999a3d0".parse().unwrap();

let hash_vec =
Vec::from_hex("7d39654178dd4758d0bc33b26e3e06051f04a215fd7ad270d4fb5e4988c8e5d2")
Expand Down

0 comments on commit bebc454

Please sign in to comment.