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

fix(protocol): fix bridge bugs in getMessageMinGasLimit #17284

Merged
merged 8 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions packages/protocol/contracts/bridge/Bridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -448,9 +448,16 @@ contract Bridge is EssentialContract, IBridge {
/// @return The minimal gas limit required for sending this message.
function getMessageMinGasLimit(uint256 dataLength) public pure returns (uint32) {
unchecked {
// Message struct takes 7*32=224 bytes + a variable length array.
// Since ABI.encode pads data to multiples of 32 bytes, we over-charge 32 bytes
return GAS_RESERVE + uint32((dataLength + 256) >> 4);
// The abi encoding of A = (Message calldata msg) is 10 * 32 bytes
// + 32 bytes (A is a dynamic tuple, offset to first elements)
// + 32 bytes (offset to last bytes element of Message)
// + 32 bytes (padded encoding of length of Message.data + dataLength (padded to 32
// bytes)
// = 13 * 32 + (dataLength / 32 * 32) + 32.
// non-zero calldata cost per byte is 16.

uint256 dataCost = (dataLength / 32 * 32 + 448) << 4;
dantaik marked this conversation as resolved.
Show resolved Hide resolved
return SafeCastUpgradeable.toUint32(dataCost + GAS_RESERVE);
}
}

Expand Down
2 changes: 2 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.