-
Notifications
You must be signed in to change notification settings - Fork 85
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
0 byte/payable selector bug #246
0 byte/payable selector bug #246
Conversation
Linking #60 because I believe it's related. |
if ( | ||
selectorSlot != 0 || | ||
(selectorInSlotIndex != 0 && selector == 0) | ||
) { | ||
selectorInSlotIndex--; | ||
} else { | ||
selectorSlotCount--; | ||
selectorSlot = l.selectorSlots[selectorSlotCount]; | ||
selectorInSlotIndex = 7; |
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.
Invert the logic and revert the order of the if/else blocks:
if ( | |
selectorSlot != 0 || | |
(selectorInSlotIndex != 0 && selector == 0) | |
) { | |
selectorInSlotIndex--; | |
} else { | |
selectorSlotCount--; | |
selectorSlot = l.selectorSlots[selectorSlotCount]; | |
selectorInSlotIndex = 7; | |
if ( | |
selectorSlot == 0 && | |
(selectorInSlotIndex == 0 || selector != 0) | |
) { | |
selectorSlotCount--; | |
selectorSlot = l.selectorSlots[selectorSlotCount]; | |
selectorInSlotIndex = 7; | |
} else { | |
selectorInSlotIndex--; | |
Makes the diff easier to reason about, and ==
is fundamentally easier to reason about than !=
.
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.
Also I'm rather confident that the selector
comparison is redundant. And I'm somewhat confident that selectorSlot
comparison is also redundant. Isn't the selectorInSlotIndex
comparison all we need? Tests pass if I remove the others.
Like this:
if (selectorInSlotIndex == 0) {
selectorSlotCount--;
selectorSlot = l.selectorSlots[selectorSlotCount];
selectorInSlotIndex = 7;
} else {
selectorInSlotIndex--;
}
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.
Yeah, I think you are definitely right about this. Updating.
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.
I made the above changes after merging the diamond-cleanup
branch and pushed them here.
@startswithaj I changed the base of this PR to |
Should I merge this? |
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.
@startswithaj Okay to merge as long as you're okay with the new changes I've pushed. Let's also wait 12 hours so that @NouDaimon can analyse the situation.
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.
Fix looks good to me.
There is a bug where selector tracking is broken when adding and then removing the payable selector
0x00000000
. For this issue to occur the 0x00000000 selector has to be added to a new row, and then removed.Only effects
facet-> selector
tracking and does not/cannot effectselector -> facet
.Please see
SolidStateDiamond.behavior.ts
for POC. AndDiamondWritableInternal.sol
for a potential fix.If an already deployed Diamond suffers from this issue, whereby a selector is missing from a facet mapping, you must
Remove
the selector andAdd
it again.Replace
on the same facet will not fix the mapping.If you want to check if a Diamond Suffers from this bug, you get a list of the selectors you expect to be on each facet and compare them to the output of
diamond.facets()
. You can use the event history of a diamond to calculate which selectors should be exposed on each facet.This does not affect the onchain behaviour of a diamond.
closes #60