Skip to content

Commit

Permalink
Merge pull request #129 from onflow/gio/fix-storage-underflow
Browse files Browse the repository at this point in the history
Fix cases of underflow in event of storage decrease
  • Loading branch information
sisyphusSmiling authored Oct 17, 2024
2 parents a3e9cb8 + ebdcec4 commit d0c8e29
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
9 changes: 8 additions & 1 deletion cadence/contracts/bridge/FlowEVMBridgeNFTEscrow.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,14 @@ access(all) contract FlowEVMBridgeNFTEscrow {
locker.deposit(token: <-nft)
let postStorageSnapshot = self.account.storage.used

return postStorageSnapshot - preStorageSnapshot
// Return the amount of storage used by the locker after storing the NFT
if postStorageSnapshot < preStorageSnapshot {
// Due to atree inlining, account storage usage may counterintuitively decrease at times - return 0
return 0
} else {
// Otherwise, return the storage usage delta
return postStorageSnapshot - preStorageSnapshot
}
}

/// Unlocks the NFT of the given type and ID, reverting if it isn't in escrow
Expand Down
9 changes: 8 additions & 1 deletion cadence/contracts/bridge/FlowEVMBridgeTokenEscrow.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,14 @@ access(all) contract FlowEVMBridgeTokenEscrow {
locker.deposit(from: <-vault)
let postStorageSnapshot = self.account.storage.used

return postStorageSnapshot - preStorageSnapshot
// Return the amount of storage used by the locker after storing the NFT
if postStorageSnapshot < preStorageSnapshot {
// Due to atree inlining, account storage usage may counterintuitively decrease at times - return 0
return 0
} else {
// Otherwise, return the storage usage delta
return postStorageSnapshot - preStorageSnapshot
}
}

/// Unlocks the tokens of the given type and amount, reverting if it isn't in escrow
Expand Down

0 comments on commit d0c8e29

Please sign in to comment.