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

optimistic starting #561

Closed
wants to merge 1 commit into from
Closed

optimistic starting #561

wants to merge 1 commit into from

Conversation

ponderingdemocritus
Copy link
Contributor

No description provided.

Copy link

vercel bot commented Feb 27, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
loot-survivor ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 27, 2024 11:36am

@@ -224,6 +225,45 @@ mod Game {
_start_game(ref self, weapon, name, interface_camel);
}

fn optimistic_start(ref self: ContractState, adventurer_id: felt252, block_hash: felt252) {
Copy link
Contributor

Choose a reason for hiding this comment

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

only the owner of the adventurer should be able to call this function, otherwise a bot could pwn every game of LS by calling this function on every new adventurer with an invalid

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since the attack is getting called - it checks it in there

assert(
self._starting_entropy.read(adventurer_id) == 0, messages::STARTING_HASH_NOT_ZERO
);

Copy link
Contributor

Choose a reason for hiding this comment

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

lets assert hash is not zero as a basic sanity check. Contract should always do its best to protect player from a faulty client.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this function can only be called once by the owner and only if they haven't started the game. This is what the null check does

Copy link
Contributor

@starknetdev starknetdev left a comment

Choose a reason for hiding this comment

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

See inline comments

_assert_not_dead(adventurer);

// assert adventurer is idle
_assert_is_idle(@self, adventurer, adventurer_id);
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need to wait for idle, can we stop the invalid adventurer from getting a good score and collecting any payment?

if !adventurer.block_changed_since_last_action(block_number) {

// we check if optimistic start and has not started
let is_starting = self._starting_entropy.read(adventurer_id) == 0
Copy link
Contributor

Choose a reason for hiding this comment

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

Can't see anything that prevents a player from starting, waiting one block, then calling attack directly rather than optimistic_start.

let optimistic_hash = self._starting_entropy.read(adventurer_id);

// must be optimistic start
assert(optimistic_hash != 0, messages::NO_OPTIMISTIC_START);
Copy link
Contributor

Choose a reason for hiding this comment

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

See comment in attack. I believe the bypass would render _starting_entropy as 0 and therefore you cannot slay them for being invalid.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants