Skip to content
This repository has been archived by the owner on Mar 28, 2023. It is now read-only.

Commit

Permalink
Merge pull request #585 from keep-network/a-bit-sale
Browse files Browse the repository at this point in the history
A Bit Sale - Clear dirty bits

FundingScript and RedemptionScript use mload to cast the first
bytes of a byte array to bytes4. Because mload deals with 32-byte
chunks, the resulting bytes4 value may contain dirty lower-order
bits.
  • Loading branch information
Shadowfiend authored Apr 21, 2020
2 parents a5804d5 + 8856fac commit 0f585af
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 3 additions & 1 deletion solidity/contracts/scripts/FundingScript.sol
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ contract FundingScript {

// Verify _extraData is a call to unqualifiedDepositToTbtc.
bytes4 functionSignature;
assembly { functionSignature := mload(add(_extraData, 0x20)) }
assembly {
functionSignature := and(mload(add(_extraData, 0x20)), not(0xff))
}
require(
functionSignature == vendingMachine.unqualifiedDepositToTbtc.selector,
"Bad _extraData signature. Call must be to unqualifiedDepositToTbtc."
Expand Down
4 changes: 3 additions & 1 deletion solidity/contracts/scripts/RedemptionScript.sol
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ contract RedemptionScript {

// Verify _extraData is a call to tbtcToBtc.
bytes4 functionSignature;
assembly { functionSignature := mload(add(_extraData, 0x20)) }
assembly {
functionSignature := and(mload(add(_extraData, 0x20)), not(0xff))
}
require(
functionSignature == vendingMachine.tbtcToBtc.selector,
"Bad _extraData signature. Call must be to tbtcToBtc."
Expand Down

0 comments on commit 0f585af

Please sign in to comment.