-
Notifications
You must be signed in to change notification settings - Fork 39
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
optimistic starting #561
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
@@ -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) { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 | ||
); | ||
|
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this 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); |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
No description provided.