-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
check msg.data length #13352
check msg.data length #13352
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"chainlink": patch | ||
--- | ||
|
||
check data size #bugfix |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@chainlink/contracts": patch | ||
--- | ||
|
||
check data size #bugfix |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1611,6 +1611,43 @@ contract BillingOverrides is SetUp { | |
} | ||
|
||
contract Transmit is SetUp { | ||
function test_transmitRevertWithExtraBytes() external { | ||
bytes32[3] memory exampleReportContext = [ | ||
bytes32(0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef), | ||
bytes32(0xabcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890), | ||
bytes32(0x7890abcdef1234567890abcdef1234567890abcdef1234567890abcdef123456) | ||
Comment on lines
+1616
to
+1618
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. total nitpick, but it might be a little cleaner if we just use the bytes32[3] memory exampleReportContext = [_random(), _random(), _random()]; There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good call! I will take a note for this. will leave it as is for now since dont want tobother to get approvals again. |
||
]; | ||
|
||
bytes memory exampleRawReport = hex"deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef"; | ||
|
||
bytes32[] memory exampleRs = new bytes32[](3); | ||
exampleRs[0] = bytes32(0x1234561234561234561234561234561234561234561234561234561234561234); | ||
exampleRs[1] = bytes32(0x1234561234561234561234561234561234561234561234561234561234561234); | ||
exampleRs[2] = bytes32(0x7890789078907890789078907890789078907890789078907890789078907890); | ||
|
||
bytes32[] memory exampleSs = new bytes32[](3); | ||
exampleSs[0] = bytes32(0x1234561234561234561234561234561234561234561234561234561234561234); | ||
exampleSs[1] = bytes32(0x1234561234561234561234561234561234561234561234561234561234561234); | ||
exampleSs[2] = bytes32(0x1234561234561234561234561234561234561234561234561234561234561234); | ||
|
||
bytes32 exampleRawVs = bytes32(0x1234561234561234561234561234561234561234561234561234561234561234); | ||
|
||
bytes memory transmitData = abi.encodeWithSelector( | ||
registry.transmit.selector, | ||
exampleReportContext, | ||
exampleRawReport, | ||
exampleRs, | ||
exampleSs, | ||
exampleRawVs | ||
); | ||
bytes memory badTransmitData = bytes.concat(transmitData, bytes1(0x00)); // add extra data | ||
vm.startPrank(TRANSMITTERS[0]); | ||
(bool success, bytes memory returnData) = address(registry).call(badTransmitData); // send the bogus transmit | ||
assertFalse(success, "Call did not revert as expected"); | ||
assertEq(returnData, abi.encodePacked(Registry.InvalidDataLength.selector)); | ||
Comment on lines
+1645
to
+1647
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I didn't realize we wouldn't be able to use the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. indeed, i also prefer the shorter expectRevert, but expectRevert doesnt work for low level calls, which we are doing here. |
||
vm.stopPrank(); | ||
} | ||
|
||
function test_handlesMixedBatchOfBillingTokens() external { | ||
uint256[] memory prevUpkeepBalances = new uint256[](3); | ||
prevUpkeepBalances[0] = registry.getBalance(linkUpkeepID); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -90,6 +90,11 @@ contract AutomationRegistry2_3 is AutomationRegistryBase2_3, OCR2Abstract, Chain | |
bytes32 rawVs | ||
) external override { | ||
uint256 gasOverhead = gasleft(); | ||
// use this msg.data length check to ensure no extra data is included in the call | ||
// 4 is first 4 bytes of the keccak-256 hash of the function signature. ss.length == rs.length so use one of them | ||
// 4 + (32 * 3) + (rawReport.length + 32 + 32) + (32 * rs.length + 32 + 32) + (32 * ss.length + 32 + 32) + 32 | ||
uint256 requiredLength = 324 + rawReport.length + 64 * rs.length; | ||
Comment on lines
+93
to
+96
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. amazing 🎉 I'm so glad there was a minimally complex solution to this problem |
||
if (msg.data.length != requiredLength) revert InvalidDataLength(); | ||
HotVars memory hotVars = s_hotVars; | ||
|
||
if (hotVars.paused) revert RegistryPaused(); | ||
|
Large diffs are not rendered by default.
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.
👍 crazy we've made it this far without having to add this lol