Skip to content

Commit

Permalink
add assert! helper, prevent vouching for users on list.
Browse files Browse the repository at this point in the history
  • Loading branch information
0o-de-lally committed Mar 11, 2024
1 parent 69dbdbd commit 0f5a8ef
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
19 changes: 19 additions & 0 deletions framework/libra-framework/sources/ol_sources/not_my_friend.move
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,16 @@ module ol_framework::not_my_friend {
use std::vector;
use std::option::{Self, Option};

friend ol_framework::vouch;
/// no non-friend list published at this address
const ENO_LIST_PUBLISHED: u64 = 0;

/// you have not subscribed to any registries of non-friends
const ENO_REGISTRIES_SUBSCRIBED: u64 = 1;

/// user is excluded from the other's social graph
const ENOT_A_FRIEND: u64 = 2;

/// any user can publish a registry of people they would rather not do
/// business with.
// this is alice in the example above
Expand Down Expand Up @@ -137,6 +141,21 @@ module ol_framework::not_my_friend {
}
}

//////// ASSERT HELPERS ///////
/// aborts tx if maybe_friend is in a subscriber's registries
public(friend) fun assert_not_friend(subscriber: address, maybe_friend:
address) acquires NotMyFriends, Subscriptions {
assert!(is_not_a_friend(subscriber, maybe_friend), error::invalid_state(ENOT_A_FRIEND));
}

/// check in both directions if users have filtered each other out of their
/// social graphs
public(friend) fun assert_not_friends_duplex(subscriber: address,
maybe_friend: address) acquires NotMyFriends, Subscriptions {
assert_not_friend(subscriber, maybe_friend);
assert_not_friend(maybe_friend, subscriber);
}

//////// GETTERS ////////
#[view]
/// checks all registries a user is subscribed to (including own registry) for
Expand Down
14 changes: 11 additions & 3 deletions framework/libra-framework/sources/ol_sources/vouch.move
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module ol_framework::vouch {
use ol_framework::ancestry;
use ol_framework::ol_account;
use ol_framework::epoch_helper;
use ol_framework::not_my_friend;

use diem_framework::system_addresses;
use diem_framework::transaction_fee;
Expand Down Expand Up @@ -66,8 +67,15 @@ module ol_framework::vouch {
/// will only succesfully vouch if the two are not related by ancestry
/// prevents spending a vouch that would not be counted.
/// to add a vouch and ignore this check use insist_vouch
public entry fun vouch_for(grantor: &signer, wanna_be_my_friend: address) acquires MyVouches {
ancestry::assert_unrelated(signer::address_of(grantor), wanna_be_my_friend);
public entry fun vouch_for(grantor: &signer, wanna_be_my_friend: address)
acquires MyVouches {
let grantor_addr = signer::address_of(grantor);

// check in both directions if the users are filtering each other from the
// social graph
not_my_friend::assert_not_friends_duplex(grantor_addr, wanna_be_my_friend);

ancestry::assert_unrelated(grantor_addr, wanna_be_my_friend);
vouch_impl(grantor, wanna_be_my_friend);
}

Expand Down Expand Up @@ -199,4 +207,4 @@ module ol_framework::vouch {
public fun test_set_buddies(val: address, buddy_list: vector<address>) acquires MyVouches {
bulk_set(val, buddy_list);
}
}
}

0 comments on commit 0f5a8ef

Please sign in to comment.