Skip to content
10 changes: 7 additions & 3 deletions contracts/src/bridge/Outbox.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ contract Outbox is DelegateCallAware, IOutbox {
address public rollup; // the rollup contract
IBridge public bridge; // the bridge contract

mapping(uint256 => bool) public spent; // maps leaf number => if spent
mapping(uint256 => bytes32) public spent; // packed spent bitmap
mapping(bytes32 => bytes32) public roots; // maps root hashes => L2 block hash

struct L2ToL1Context {
Expand Down Expand Up @@ -182,8 +182,12 @@ contract Outbox is DelegateCallAware, IOutbox {
bytes32 calcRoot = calculateMerkleRoot(proof, index, item);
if (roots[calcRoot] == bytes32(0)) revert UnknownRoot(calcRoot);

if (spent[index]) revert AlreadySpent(index);
spent[index] = true;
uint256 spentIndex = index / 256;
uint256 bitOffset = index - spentIndex * 256;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use 255 instead of 256 here.. this will leave the most significant bit reserved.
We might do something clever with this reserved bit later, to avoid 1/256 users paying more gas for the release.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, just made that change. : )


bytes32 replay = spent[spentIndex];
if (((replay >> bitOffset) & bytes32(uint256(1))) != bytes32(0)) revert AlreadySpent(index);
spent[spentIndex] = (replay | bytes32(1 << bitOffset));

return bytes32(index);
}
Expand Down