Skip to content

Commit f127cc1

Browse files
committed
update: block verification in parent chain assertion
- Replaces `NodeCreated` with `AssertionCreated` - Updates version to use the latest ABI
1 parent 93fe181 commit f127cc1

File tree

4 files changed

+39
-59
lines changed

4 files changed

+39
-59
lines changed

packages/block-verification-in-parent-chain-assertion/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
# Block verification in an assertion posted on the parent chain
22

3-
This tutorial shows how to verify whether a block of a chain has been processed as part of an RBlock assertion on its parent chain.
3+
This tutorial shows how to verify whether a block of a chain has been processed as part of an assertion on its parent chain.
44

5-
It uses the `Rollup` contract to find the latest confirmed (or created if configured in the script) RBlock/node, find the event that created it, and get the latest processed block hash of the child chain that's part of the assertion of that RBlock/node.
5+
It uses the `Rollup` contract to find the latest confirmed assertion hash, find the `AssertionCreated` event that created it, and get the latest processed block hash of the child chain that's part of that assertion's `afterState`.
66

77
Then it checks whether the block number passed as argument was created before the latest block hash of the child chain processed.
88

9-
See [./exec.js](./scripts/exec.js) for inline explanations.
9+
See [./exec.ts](./scripts/exec.ts) for inline explanations.
1010

1111
## Set environment variables
1212

packages/block-verification-in-parent-chain-assertion/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"exec": "ts-node scripts/exec.ts"
77
},
88
"dependencies": {
9-
"@arbitrum/sdk": "^v4.0.1",
9+
"@arbitrum/sdk": "^v4.0.4",
1010
"ts-node": "^10.9.2",
1111
"typescript": "^4.9.5"
1212
}

packages/block-verification-in-parent-chain-assertion/scripts/exec.ts

Lines changed: 24 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { providers, Contract } from 'ethers';
22
import { getArbitrumNetwork } from '@arbitrum/sdk';
3-
import { RollupCore__factory } from '@arbitrum/sdk/dist/lib/abi/factories/RollupCore__factory';
3+
import { BoldRollupUserLogic__factory } from '@arbitrum/sdk/dist/lib/abi-bold/factories/BoldRollupUserLogic__factory';
44
import { arbLog, requireEnvVariables, addCustomNetworkFromFile } from 'arb-shared-dependencies';
55
require('dotenv').config();
66
requireEnvVariables(['CHAIN_RPC', 'PARENT_CHAIN_RPC']);
@@ -11,93 +11,64 @@ requireEnvVariables(['CHAIN_RPC', 'PARENT_CHAIN_RPC']);
1111
const parentChainProvider = new providers.JsonRpcProvider(process.env.PARENT_CHAIN_RPC);
1212
const childChainProvider = new providers.JsonRpcProvider(process.env.CHAIN_RPC);
1313

14-
/**
15-
* Use the latest node created instead of the last confirmed one
16-
*/
17-
const useCreatedNodeInsteadOfConfirmed = false;
18-
1914
const main = async (childChainBlockNumberToVerify: number) => {
2015
await arbLog(
2116
'Find whether a block of the child chain has been processed as part of an RBlock on the parent chain',
2217
);
2318

24-
/**
25-
* Add the custom network configuration to the SDK if present
26-
*/
2719
addCustomNetworkFromFile();
2820

29-
/**
30-
* Use childChainNetwork to find the Rollup contract's address and instantiate a contract handler
31-
*/
3221
const childChainNetwork = await getArbitrumNetwork(childChainProvider);
3322
const rollupAddress = childChainNetwork.ethBridge.rollup;
34-
const rollup = new Contract(rollupAddress, RollupCore__factory.abi, parentChainProvider);
23+
const rollup = new Contract(rollupAddress, BoldRollupUserLogic__factory.abi, parentChainProvider);
3524
console.log(`Rollup contract found at address ${rollup.address}`);
3625

37-
/**
38-
* Get the latest node created or confirmed
39-
*/
40-
const nodeId = useCreatedNodeInsteadOfConfirmed
41-
? await rollup.latestNodeCreated()
42-
: await rollup.latestConfirmed();
43-
console.log(
44-
`Latest ${useCreatedNodeInsteadOfConfirmed ? 'created' : 'confirmed'} Rblock/node: ${nodeId}`,
45-
);
26+
const assertionHash: string = await rollup.latestConfirmed();
27+
console.log(`Latest confirmed assertion hash: ${assertionHash}`);
4628

47-
/**
48-
* Find the NodeCreated event
49-
*/
50-
const nodeCreatedEventFilter = rollup.filters.NodeCreated(nodeId);
51-
const nodeCreatedEvents = await rollup.queryFilter(nodeCreatedEventFilter);
52-
if (!nodeCreatedEvents) {
53-
throw new Error(`INTERNAL ERROR: NodeCreated events not found for Rblock/node: ${nodeId}`);
29+
const assertionCreatedEventFilter = (rollup as any).filters.AssertionCreated(assertionHash);
30+
const assertionCreatedEvents = await rollup.queryFilter(assertionCreatedEventFilter);
31+
if (!assertionCreatedEvents || assertionCreatedEvents.length === 0) {
32+
throw new Error(
33+
`INTERNAL ERROR: AssertionCreated events not found for assertion: ${assertionHash}`,
34+
);
5435
}
55-
const nodeCreatedEvent = nodeCreatedEvents[0];
56-
console.log(`NodeCreated event found in transaction ${nodeCreatedEvent.transactionHash}`);
36+
const assertionCreatedEvent = assertionCreatedEvents[0];
37+
console.log(
38+
`AssertionCreated event found in transaction ${assertionCreatedEvent.transactionHash}`,
39+
);
5740

58-
/**
59-
* Finding the assertion within the NodeCreated event, and getting the afterState
60-
*/
61-
if (!nodeCreatedEvent.args) {
41+
if (!assertionCreatedEvent.args) {
6242
throw new Error(
63-
`INTERNAL ERROR: NodeCreated event does not have an assertion for Rblock/node: ${nodeId}`,
43+
`INTERNAL ERROR: AssertionCreated event does not have an assertion for hash: ${assertionHash}`,
6444
);
6545
}
66-
const assertion = nodeCreatedEvent.args.assertion;
46+
const assertion = (assertionCreatedEvent as any).args.assertion;
6747
const afterState = assertion.afterState;
6848

69-
/**
70-
* Latest child chain's block hash processed is in the first element of the bytes32Vals property in the globalState
71-
*/
49+
// Latest child chain's block hash processed is in the first element of the bytes32Vals property in the globalState
7250
const lastChildChainBlockHash = afterState.globalState.bytes32Vals[0];
7351
console.log(
7452
`Last block hash of the child chain processed in this Rblock/node: ${lastChildChainBlockHash}`,
7553
);
7654

77-
/**
78-
* Getting the block number from that block hash
79-
*/
55+
// Getting the block number from that block hash
56+
8057
const lastChildChainBlock = await childChainProvider.getBlock(lastChildChainBlockHash);
8158
const lastChildChainBlockNumber = lastChildChainBlock.number;
8259
console.log(
8360
`Last block number of the child chain processed in this Rblock/node: ${lastChildChainBlockNumber}`,
8461
);
8562

86-
/**
87-
* Final verification
88-
*/
63+
// Final verification
8964
console.log(`************`);
9065
if (lastChildChainBlockNumber > childChainBlockNumberToVerify) {
9166
console.log(
92-
`${childChainBlockNumberToVerify} has been processed as part of the latest ${
93-
useCreatedNodeInsteadOfConfirmed ? 'created' : 'confirmed'
94-
} RBlock/node`,
67+
`${childChainBlockNumberToVerify} has been processed as part of the latest confirmed assertion`,
9568
);
9669
} else {
9770
console.log(
98-
`${childChainBlockNumberToVerify} has NOT been processed as part of the latest ${
99-
useCreatedNodeInsteadOfConfirmed ? 'created' : 'confirmed'
100-
} RBlock/node`,
71+
`${childChainBlockNumberToVerify} has NOT been processed as part of the latest confirmed assertion`,
10172
);
10273
}
10374
console.log(`************`);
@@ -106,9 +77,7 @@ const main = async (childChainBlockNumberToVerify: number) => {
10677
// Getting the transaction hash from the command arguments
10778
if (process.argv.length < 3) {
10879
console.log(
109-
`Missing block number of the child chain to verify whether it has been processed in the latest ${
110-
useCreatedNodeInsteadOfConfirmed ? 'created' : 'confirmed'
111-
} RBlock/node`,
80+
'Missing block number of the child chain to verify whether it has been processed in the latest confirmed assertion',
11281
);
11382
console.log(`Usage: yarn run exec <block number>`);
11483
process.exit(1);

yarn.lock

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,17 @@
3434
async-mutex "^0.4.0"
3535
ethers "^5.1.0"
3636

37+
"@arbitrum/sdk@^v4.0.4":
38+
version "4.0.4"
39+
resolved "https://registry.yarnpkg.com/@arbitrum/sdk/-/sdk-4.0.4.tgz#32f3cfa75d2b3f9ab0be01eb807112e0001f428d"
40+
integrity sha512-GscwlkHYmPzRKs9huDHntbqx1xMRhTraTUvTC9exu+prjndKxHe9ZORuIcqmtEqwLwma/l8nqxI+k+pEEdIO6Q==
41+
dependencies:
42+
"@ethersproject/address" "^5.0.8"
43+
"@ethersproject/bignumber" "^5.1.1"
44+
"@ethersproject/bytes" "^5.0.8"
45+
async-mutex "^0.4.0"
46+
ethers "^5.1.0"
47+
3748
"@arbitrum/token-bridge-contracts@^1.2.3":
3849
version "1.2.3"
3950
resolved "https://registry.yarnpkg.com/@arbitrum/token-bridge-contracts/-/token-bridge-contracts-1.2.3.tgz#b08b22b5dcac255149a10bd8b66b0b55be7f3329"

0 commit comments

Comments
 (0)