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

Reorder state changes and event emission for consistency #2719

Merged
merged 5 commits into from Jun 18, 2021

Conversation

Amxx
Copy link
Collaborator

@Amxx Amxx commented Jun 14, 2021

No description provided.

@frangio
Copy link
Contributor

frangio commented Jun 14, 2021

On second thought about this, I think we should emit events after state changes... It's what we do everywhere else already.

_balances[recipient] += amount;
emit Transfer(sender, recipient, amount);

@Amxx
Copy link
Collaborator Author

Amxx commented Jun 15, 2021

In transferOwnership (and other places where the event contains the "old value") we emit the event before doing the state change. This is so the event can read the old state from storage without having to assign a temporary variable.

This is why I followed this logic ... but its true that in tokens we emit events after ...

@Amxx
Copy link
Collaborator Author

Amxx commented Jun 15, 2021

I have the feeling that our logic is "Emit the event after changing the state, unless the event needs knowledge of the previous state"

Maybe we should keep doing that.

@Amxx Amxx added the on hold Put on hold for some reason that must be specified in a comment. label Jun 15, 2021
@frangio
Copy link
Contributor

frangio commented Jun 15, 2021

Sorry did that last edit before seeing these comments thinking we had agreed.

I get that it's technically consistent if we establish this convention you just mentioned, but it's not immediately apparent that the convention is "do this unless we need to do this other thing", and I don't see an issue in defining a local variable.

@Amxx
Copy link
Collaborator Author

Amxx commented Jun 16, 2021

The local variable might cause gas cost (the stack might need to be reordered to push it back to the top when emitting the event). It might even cause stack too deep errors :/

petross8901
petross8901 previously approved these changes Jun 18, 2021
@frangio frangio enabled auto-merge (squash) June 18, 2021 14:53
@frangio frangio merged commit 27e0900 into OpenZeppelin:master Jun 18, 2021
@Amxx Amxx deleted the audit-fix/N01 branch June 18, 2021 16:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
on hold Put on hold for some reason that must be specified in a comment.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants