fix: Fixed stack too deep errors.

This commit is contained in:
Peter Michael
2022-09-02 16:07:26 +01:00
parent b124b621df
commit f7bab551ef
2 changed files with 32 additions and 25 deletions

View File

@@ -934,9 +934,12 @@ library GeneralLib {
address executor,
uint256 pubId
) private {
uint256 pubCountPointed = _getPubCount(vars.profileIdPointed);
if (pubCountPointed < vars.pubIdPointed || vars.pubIdPointed == 0)
revert Errors.PublicationDoesNotExist();
// Prevents stack too deep.
{
uint256 pubCountPointed = _getPubCount(vars.profileIdPointed);
if (pubCountPointed < vars.pubIdPointed || vars.pubIdPointed == 0)
revert Errors.PublicationDoesNotExist();
}
if (vars.profileId == vars.profileIdPointed && vars.pubIdPointed == pubId)
revert Errors.CannotCommentOnSelf();

View File

@@ -104,34 +104,38 @@ library InteractionHelpers {
) internal returns (uint256) {
(uint256 rootProfileId, uint256 rootPubId, address rootCollectModule) = GeneralHelpers
.getPointedIfMirrorWithCollectModule(profileId, pubId);
uint256 collectNFTSlot;
address collectNFT;
// Load the collect NFT and for the given publication being collected, and cache the
// collect NFT slot.
assembly {
mstore(0, rootProfileId)
mstore(32, PUB_BY_ID_BY_PROFILE_MAPPING_SLOT)
mstore(32, keccak256(0, 64))
mstore(0, rootPubId)
collectNFTSlot := add(keccak256(0, 64), PUBLICATION_COLLECT_NFT_OFFSET)
collectNFT := sload(collectNFTSlot)
}
// Prevents stack too deep.
{
uint256 collectNFTSlot;
if (collectNFT == address(0)) {
collectNFT = _deployCollectNFT(
rootProfileId,
rootPubId,
_handle(rootProfileId),
collectNFTImpl
);
// Store the collect NFT in the cached slot.
// Load the collect NFT and for the given publication being collected, and cache the
// collect NFT slot.
assembly {
sstore(collectNFTSlot, collectNFT)
mstore(0, rootProfileId)
mstore(32, PUB_BY_ID_BY_PROFILE_MAPPING_SLOT)
mstore(32, keccak256(0, 64))
mstore(0, rootPubId)
collectNFTSlot := add(keccak256(0, 64), PUBLICATION_COLLECT_NFT_OFFSET)
collectNFT := sload(collectNFTSlot)
}
if (collectNFT == address(0)) {
collectNFT = _deployCollectNFT(
rootProfileId,
rootPubId,
_handle(rootProfileId),
collectNFTImpl
);
// Store the collect NFT in the cached slot.
assembly {
sstore(collectNFTSlot, collectNFT)
}
}
}
uint256 tokenId = ICollectNFT(collectNFT).mint(onBehalfOf);
try