Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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
5 changes: 4 additions & 1 deletion contracts/pm/mixins/MixinTicketProcessor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,15 @@
pure
returns (uint256 creationRound, bytes32 creationRoundBlockHash)
{
require(_auxData.length == 64, "invalid length for ticket auxData: must be 64 bytes");
require(
_auxData.length >= 64 && _auxData.length <= 96,
"invalid length for ticket auxData: must be between 64 and 96 bytes"
);

// _auxData format:
// Bytes [0:31] = creationRound
// Bytes [32:63] = creationRoundBlockHash
assembly {

Check warning on line 85 in contracts/pm/mixins/MixinTicketProcessor.sol

View workflow job for this annotation

GitHub Actions / Test with coverage

Avoid to use inline assembly. It is acceptable only in rare cases
creationRound := mload(add(_auxData, 32))
creationRoundBlockHash := mload(add(_auxData, 64))
}
Expand Down
65 changes: 61 additions & 4 deletions test/unit/TicketBroker.js
Original file line number Diff line number Diff line change
Expand Up @@ -798,24 +798,81 @@ describe("TicketBroker", () => {
).to.be.revertedWith("ticket sender is null address")
})

it("reverts if ticket auxData != 64 bytes", async () => {
const auxData = ethers.constants.HashZero
it("reverts if ticket auxData length is less than 64 bytes", async () => {
await expect(
broker.redeemWinningTicket(
createTicket({
recipient,
sender,
auxData: ethers.constants.HashZero
}),
web3.utils.asciiToHex("sig"),
5
)
).to.be.revertedWith(
"invalid length for ticket auxData: must be between 64 and 96 bytes"
)
})

it("reverts if ticket auxData is greater than 96 bytes", async () => {
await expect(
broker.redeemWinningTicket(
createTicket({
recipient,
sender,
auxData
auxData: ethers.utils.hexConcat([
createAuxData(
currentRound,
DUMMY_TICKET_CREATION_ROUND_BLOCK_HASH
),
ethers.constants.HashZero,
ethers.constants.HashZero
])
}),
web3.utils.asciiToHex("sig"),
5
)
).to.be.revertedWith(
"invalid length for ticket auxData: must be 64 bytes"
"invalid length for ticket auxData: must be between 64 and 96 bytes"
)
})

it("accepts 96-byte ticket auxData", async () => {
const recipientRand = 5
const faceValue = 1

await broker.fundDeposit({value: faceValue})
const auxData = ethers.utils.hexConcat([
createAuxData(
currentRound,
DUMMY_TICKET_CREATION_ROUND_BLOCK_HASH
),
ethers.constants.HashZero
])

const ticket = createWinningTicket(
recipient,
sender,
recipientRand,
faceValue,
auxData
)
const senderSig = await signMsg(getTicketHash(ticket), sender)

try {
await broker.redeemWinningTicket(
ticket,
senderSig,
recipientRand
)
} catch (error) {
console.log(
error.reason || error.error?.message || error.message
)
throw error
}
})

it("reverts if block hash for ticket creationRound is null", async () => {
await fixture.roundsManager.setMockBytes32(
functionSig("blockHashForRound(uint256)"),
Expand Down
Loading