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

Launchpad v2 audit fixes #84

Merged
merged 25 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
5b39945
setup config optimization tryout
psorinionut Oct 28, 2024
57493fd
launchpad v2 audit fixes
psorinionut Nov 12, 2024
9fc07c1
distribution of leftover tickets fix
psorinionut Nov 12, 2024
88cf10a
revert logic for addTickets endpoint
psorinionut Nov 13, 2024
b864047
clippy fixes
psorinionut Nov 13, 2024
f3dc412
framework upgrade 0.54.1
psorinionut Nov 14, 2024
060fbbc
launchpad v2 addTickets new parameter types
psorinionut Nov 14, 2024
d10268a
framework upgrade 0.54.2
psorinionut Nov 18, 2024
374929e
Merge pull request #85 from multiversx/framework-upgrade-0.54.1
psorinionut Nov 18, 2024
70b4b5f
framework upgrade 0.54.2
psorinionut Nov 18, 2024
fcfe8cb
fix after framework upgrade
psorinionut Nov 18, 2024
7708e07
use MultiValueManagedVecCounted
psorinionut Nov 18, 2024
fbbf595
replace MultiValueEncoded with MultiValueManagedVec for addTickets
psorinionut Nov 18, 2024
18a1d54
revert addTickets params types
psorinionut Nov 18, 2024
b7064ef
Merge pull request #86 from multiversx/launchpad-v2-add-tickets-new-p…
psorinionut Nov 18, 2024
1225e73
audit fixes unit tests
psorinionut Nov 22, 2024
d587001
added MAX_TICKETS_ALLOWANCE check
psorinionut Nov 22, 2024
08af875
Added user accounts only check
psorinionut Nov 22, 2024
d7a992f
updated MAX_TICKETS_ALLOWANCE value
psorinionut Nov 22, 2024
492b053
Blacklist mechanism extensive unit test
psorinionut Nov 22, 2024
d5b0667
fix remove from blacklist checks
psorinionut Nov 22, 2024
ab7ee57
blacklist storage logic optimization
psorinionut Nov 25, 2024
9345234
remove unneeded comments
psorinionut Nov 26, 2024
ddf0836
addTickets extra check
psorinionut Nov 26, 2024
0799d90
Merge pull request #88 from multiversx/launchpad-v2-audit-fixes-unit-…
psorinionut Dec 3, 2024
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
109 changes: 91 additions & 18 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions launchpad-common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ edition = "2021"
path = "src/lib.rs"

[dependencies.multiversx-sc]
version = "0.53.0"
version = "0.54.2"

[dependencies.multiversx-sc-modules]
version = "0.53.0"
version = "0.54.2"
8 changes: 8 additions & 0 deletions launchpad-common/src/blacklist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ pub trait BlacklistModule:

let blacklist_mapper = self.blacklist();
for address in users_list {
require!(
!blacklist_mapper.contains(&address),
"User already blacklisted"
);
let confirmed_tickets_mapper = self.nr_confirmed_tickets(&address);
let nr_confirmed_tickets = confirmed_tickets_mapper.get();
if nr_confirmed_tickets > 0 {
Expand All @@ -32,6 +36,10 @@ pub trait BlacklistModule:

let blacklist_mapper = self.blacklist();
for address in users_list {
require!(
blacklist_mapper.contains(&address),
"User is not blacklisted"
);
blacklist_mapper.remove(&address);
}
}
Expand Down
6 changes: 6 additions & 0 deletions launchpad-common/src/tickets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,12 @@ pub trait TicketsModule:

let last_ticket_id_mapper = self.last_ticket_id();
let first_ticket_id = last_ticket_id_mapper.get() + 1;

require!(
first_ticket_id < usize::MAX - nr_tickets,
"Maximum number of tickets was reached"
);

let last_ticket_id = first_ticket_id + nr_tickets - 1;

ticket_range_mapper.set(TicketRange {
Expand Down
26 changes: 20 additions & 6 deletions launchpad-common/src/winner_selection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,17 @@ pub trait WinnerSelectionModule:
}

let run_result = self.run_while_it_has_gas(|| {
if first_ticket_id_in_batch == last_ticket_id + 1 {
return STOP_OP;
}

let current_ticket_batch_mapper = self.ticket_batch(first_ticket_id_in_batch);
let ticket_batch: TicketBatch<Self::Api> = current_ticket_batch_mapper.get();
let address = &ticket_batch.address;
let nr_tickets_in_batch = ticket_batch.nr_tickets;

let nr_confirmed_tickets = self.nr_confirmed_tickets(address).get();
if self.is_user_blacklisted(address) || nr_confirmed_tickets == 0 {
if nr_confirmed_tickets == 0 {
self.ticket_range_for_address(address).clear();
current_ticket_batch_mapper.clear();
} else if nr_removed > 0 || nr_confirmed_tickets < nr_tickets_in_batch {
Expand All @@ -64,11 +68,7 @@ pub trait WinnerSelectionModule:
nr_removed += nr_tickets_in_batch - nr_confirmed_tickets;
first_ticket_id_in_batch += nr_tickets_in_batch;

if first_ticket_id_in_batch == last_ticket_id + 1 {
STOP_OP
} else {
CONTINUE_OP
}
CONTINUE_OP
});

match run_result {
Expand Down Expand Up @@ -104,6 +104,8 @@ pub trait WinnerSelectionModule:
self.require_not_paused();
self.require_winner_selection_period();

self.check_caller_owner_or_user();
psorinionut marked this conversation as resolved.
Show resolved Hide resolved

let flags_mapper = self.flags();
let mut flags: Flags = flags_mapper.get();
require!(flags.were_tickets_filtered, "Must filter tickets first");
Expand All @@ -114,6 +116,10 @@ pub trait WinnerSelectionModule:

let (mut rng, mut ticket_position) = self.load_select_winners_operation();
let run_result = self.run_while_it_has_gas(|| {
if nr_winning_tickets == 0 {
return STOP_OP;
}

self.shuffle_single_ticket(&mut rng, ticket_position, last_ticket_position);

if ticket_position == nr_winning_tickets {
Expand Down Expand Up @@ -193,4 +199,12 @@ pub trait WinnerSelectionModule:

ticket_ids
}

fn check_caller_owner_or_user(&self) {
if self.blockchain().get_owner_address() == self.blockchain().get_caller() {
return;
}

self.blockchain().check_caller_is_user_account();
}
Comment on lines +203 to +209
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't respect the doc, i.e. or an account from another shard, you just check the caller is a user account.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, this was not what was requested, but it is a more simpler and clear/cleaner solution. which covers the initial request. No need for external SCs to call this function.

}
8 changes: 4 additions & 4 deletions launchpad-guaranteed-tickets-v2/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ path = "src/lib.rs"
path = "../launchpad-common"

[dependencies.multiversx-sc]
version = "0.53.0"
version = "0.54.2"

[dependencies.multiversx-sc-modules]
version = "0.53.0"
version = "0.54.2"

[dev-dependencies]
num-bigint = "0.4.2"

[dev-dependencies.multiversx-sc-meta-lib]
version = "0.53.0"
version = "0.54.2"

[dev-dependencies.multiversx-sc-scenario]
version = "0.53.0"
version = "0.54.2"
4 changes: 2 additions & 2 deletions launchpad-guaranteed-tickets-v2/meta/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ publish = false
path = ".."

[dependencies.multiversx-sc]
version = "0.53.0"
version = "0.54.2"

[dependencies.multiversx-sc-meta-lib]
version = "0.53.0"
version = "0.54.2"
Loading
Loading