-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchallenged_proposal.gate
55 lines (47 loc) · 2.41 KB
/
challenged_proposal.gate
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
use Call, Events, Contains, Range, Len from hexagate;
param disputeGame: address;
param honestProposer: address;
param honestChallenger: address;
// Source to retrieve `Move` events from the specified dispute game contract
source moveEvents: list<tuple<integer, bytes, address>> = Events {
contract: disputeGame,
signature: "event Move(uint256 indexed parentIndex, bytes32 indexed claim, address indexed claimant)"
};
// Retrieve the number of claims
source claimCount: integer = Call {
contract: disputeGame,
signature: "function claimDataLen() view returns (uint256)"
};
// Retrieve the claim data for each claim index
source claimData: list<tuple<integer,address,address,integer,bytes,integer,integer>> = [
Call {
contract: disputeGame,
signature: "function claimData(uint256 idx) view returns (uint32,address,address,uint128,bytes32,uint128,uint128)",
params: tuple(index)
}
for index in Range { start: 0, stop: claimCount }
];
// Parse out the root claim proposer address - the root claim is the claim at position 0 in the claimData list
source rootClaimProposer: address = claimData[0][2];
// Make a list of event numbers, which are the subgame depths that correspond to defense claims
// All attacks that are ultimately challenges to the root claim will have a parentIndex that is even
source attackClaimParentIndices: list<integer> = Range {
start: 0,
stop: claimCount, // claimCount already includes a +1
step: 2
};
// Check the rest of the claims for the following conditions:
// 1) Is the proposer of the claim CB Challenger
// 2) Is the claim attacking the root claim - we can determine if an "attack" against the root claim is happening
// by checking the parentIndex of the claim. If the parentIndex is 0 or an even number, then the claim is an
// attack ultimately against the root claim, no matter the depth.
source challengerAttacks: list<boolean> = [
(claim[2] == honestChallenger) and Contains { sequence: attackClaimParentIndices, item: claim[0] }
for claim in claimData
if (rootClaimProposer == honestProposer)
];
// Trigger an alert when an attack by the CB challenger on a state output root proposed by the CB proposer is detected
invariant {
description: "CB challenger attacked a state output root proposed by CB proposer",
condition: Len { sequence: moveEvents } > 0 ? !Contains { sequence: challengerAttacks, item: true } : true
};