Skip to content

Commit b9bd267

Browse files
committedDec 1, 2024
game
1 parent 681f19d commit b9bd267

File tree

2 files changed

+34
-26
lines changed

2 files changed

+34
-26
lines changed
 

‎python/op/game.ipynb

+33-26
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
},
2727
{
2828
"cell_type": "code",
29-
"execution_count": 7,
29+
"execution_count": 2,
3030
"id": "a7943f57-b9be-4168-a63e-cf3acf9ed41d",
3131
"metadata": {},
3232
"outputs": [],
@@ -42,26 +42,20 @@
4242
},
4343
{
4444
"cell_type": "code",
45-
"execution_count": 12,
45+
"execution_count": 4,
4646
"id": "b5bddad4-dbbe-47d0-8525-1d52ba9c7b58",
4747
"metadata": {},
4848
"outputs": [
4949
{
50-
"name": "stdout",
51-
"output_type": "stream",
52-
"text": [
53-
"4 defender\n",
54-
"<GameStatus.CHALLENGER_WINS: 1>\n",
55-
"defaultdict(<class 'game.ResolutionCheckpoint'>,\n",
56-
" {0: {'initial_checkpoint_complete': True, 'subgame_index': 1, 'leftmost_position': 2, 'countered_by': 'challenger'},\n",
57-
" 1: {'initial_checkpoint_complete': True, 'subgame_index': 1, 'leftmost_position': 340282366920938463463374607431768211455, 'countered_by': None},\n",
58-
" 2: {'initial_checkpoint_complete': True, 'subgame_index': 1, 'leftmost_position': 8, 'countered_by': 'challenger'},\n",
59-
" 3: {'initial_checkpoint_complete': True, 'subgame_index': 1, 'leftmost_position': 340282366920938463463374607431768211455, 'countered_by': None}})\n",
60-
"[{'parent_index': 4294967295, 'countered_by': 'challenger', 'claimant': 'defender', 'bond': 0, 'claim': '0xd6c66cad06fe14fdb6ce9297d80d32f24d7428996d0045cbf90cc345c677ba16', 'position': 1, 'clock': 0},\n",
61-
" {'parent_index': 0, 'countered_by': None, 'claimant': 'challenger', 'bond': 0, 'claim': '0x129d374684edc00de2e50d4cc4c5d89ef16c4127f5a20359339603d9e2a85e30', 'position': 2, 'clock': 18446744073709551617},\n",
62-
" {'parent_index': 1, 'countered_by': 'challenger', 'claimant': 'defender', 'bond': 0, 'claim': '0x4b68ed39e9144e18af8b167c14ebdceed81983f2598e1f1e1a3354c37e3472c7', 'position': 4, 'clock': 18446744073709551618},\n",
63-
" {'parent_index': 2, 'countered_by': None, 'claimant': 'challenger', 'bond': 0, 'claim': '0x01fdd07ee5e9f7ed3bdedc240a042a72ae2fc235840a49e6e46341dabca965ca', 'position': 8, 'clock': 36893488147419103235},\n",
64-
" {'parent_index': 3, 'countered_by': 'defender', 'claimant': 'defender', 'bond': 0, 'claim': '0x681f23a2934010b39501557ee6290d61059765df878ee56cb3b2a286565408c4', 'position': 16, 'clock': 36893488147419103236}]\n"
50+
"ename": "TypeError",
51+
"evalue": "exceptions must derive from BaseException",
52+
"output_type": "error",
53+
"traceback": [
54+
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
55+
"\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)",
56+
"Cell \u001b[0;32mIn[4], line 59\u001b[0m\n\u001b[1;32m 57\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m arg \u001b[38;5;129;01min\u001b[39;00m args:\n\u001b[1;32m 58\u001b[0m block\u001b[38;5;241m.\u001b[39minc()\n\u001b[0;32m---> 59\u001b[0m \u001b[43mgame\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mmove\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m 60\u001b[0m \u001b[43m \u001b[49m\u001b[43mdisputed\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43m \u001b[49m\u001b[43marg\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mdisputed\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\n\u001b[1;32m 61\u001b[0m \u001b[43m \u001b[49m\u001b[43mchallenge_idx\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43m \u001b[49m\u001b[43marg\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mchallenge_idx\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\n\u001b[1;32m 62\u001b[0m \u001b[43m \u001b[49m\u001b[43mclaim\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43m \u001b[49m\u001b[43marg\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mclaim\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\n\u001b[1;32m 63\u001b[0m \u001b[43m \u001b[49m\u001b[43mis_attack\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43m \u001b[49m\u001b[43marg\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mis_attack\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\n\u001b[1;32m 64\u001b[0m \u001b[43m \u001b[49m\u001b[43mmsg_value\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43m \u001b[49m\u001b[38;5;241;43m0\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\n\u001b[1;32m 65\u001b[0m \u001b[43m \u001b[49m\u001b[43mblock_timestamp\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43m \u001b[49m\u001b[43mblock\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mtimestamp\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 66\u001b[0m \u001b[43m \u001b[49m\u001b[43mmsg_sender\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43m \u001b[49m\u001b[43marg\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mmsg_sender\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 67\u001b[0m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 69\u001b[0m block\u001b[38;5;241m.\u001b[39minc()\n\u001b[1;32m 70\u001b[0m game\u001b[38;5;241m.\u001b[39mstep(\n\u001b[1;32m 71\u001b[0m claim_idx \u001b[38;5;241m=\u001b[39m \u001b[38;5;241m4\u001b[39m, \n\u001b[1;32m 72\u001b[0m is_attack \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mTrue\u001b[39;00m, \n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 76\u001b[0m msg_sender \u001b[38;5;241m=\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mchallenger\u001b[39m\u001b[38;5;124m\"\u001b[39m,\n\u001b[1;32m 77\u001b[0m )\n",
57+
"File \u001b[0;32m~/bkp/dev/t4sk/notes/python/op/game.py:139\u001b[0m, in \u001b[0;36mFaultDisputeGame.move\u001b[0;34m(self, disputed, challenge_idx, claim, is_attack, **kwargs)\u001b[0m\n\u001b[1;32m 136\u001b[0m next_pos_depth \u001b[38;5;241m=\u001b[39m Position\u001b[38;5;241m.\u001b[39mdepth(next_pos)\n\u001b[1;32m 138\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m (challenge_idx \u001b[38;5;241m==\u001b[39m \u001b[38;5;241m0\u001b[39m \u001b[38;5;129;01mor\u001b[39;00m next_pos_depth \u001b[38;5;241m==\u001b[39m SPLIT_DEPTH \u001b[38;5;241m+\u001b[39m \u001b[38;5;241m2\u001b[39m) \u001b[38;5;129;01mand\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m is_attack:\n\u001b[0;32m--> 139\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mcannot defend root claim\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 141\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39ml2_block_num_challenged \u001b[38;5;129;01mand\u001b[39;00m challenge_idx \u001b[38;5;241m==\u001b[39m \u001b[38;5;241m0\u001b[39m:\n\u001b[1;32m 142\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mL2 block num challenged\u001b[39m\u001b[38;5;124m\"\u001b[39m\n",
58+
"\u001b[0;31mTypeError\u001b[0m: exceptions must derive from BaseException"
6559
]
6660
}
6761
],
@@ -132,15 +126,28 @@
132126
" msg_sender = arg[\"msg_sender\"],\n",
133127
" )\n",
134128
"\n",
135-
"block.inc()\n",
136-
"game.step(\n",
137-
" claim_idx = 4, \n",
138-
" is_attack = True, \n",
139-
" state_data = \"0x00\", \n",
140-
" proof = \"\",\n",
141-
" block_timestamp = block.timestamp,\n",
142-
" msg_sender = \"defender\",\n",
143-
")\n",
129+
"### Attack ###\n",
130+
"# block.inc()\n",
131+
"# game.step(\n",
132+
"# claim_idx = 4, \n",
133+
"# is_attack = True, \n",
134+
"# state_data = \"0x00\", \n",
135+
"# proof = \"\",\n",
136+
"# block_timestamp = block.timestamp,\n",
137+
"# msg_sender = \"challenger\",\n",
138+
"# )\n",
139+
"\n",
140+
"### Defend, parent post disagree ###\n",
141+
"# vm.set_post_state(write_8_bits(keccak256_str(\"8,0\"), VMStatus.INVALID.value))\n",
142+
"# block.inc()\n",
143+
"# game.step(\n",
144+
"# claim_idx = 4, \n",
145+
"# is_attack = False, \n",
146+
"# state_data = \"16,0\", \n",
147+
"# proof = \"\",\n",
148+
"# block_timestamp = block.timestamp,\n",
149+
"# msg_sender = \"challenger\",\n",
150+
"# )\n",
144151
"\n",
145152
"block.warp(MAX_CLOCK_DURATION + 2)\n",
146153
"game.resolve_claim(4, 0, block_timestamp = block.timestamp)\n",

‎python/op/game.py

+1
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ def step(self, claim_idx, is_attack, state_data, proof, **kwargs):
119119

120120
valid_step = self.vm.step(state_data, proof, uuid) == post_state.claim
121121
parent_post_agree = (Position.depth(parent_pos) - Position.depth(post_state.position)) % 2 == 0
122+
print(parent_post_agree, valid_step, parent_pos, post_state.position)
122123

123124
assert parent_post_agree != valid_step, "valid step"
124125
assert parent.countered_by is None, "already countered"

0 commit comments

Comments
 (0)
Please sign in to comment.