Skip to content

Commit 0eeb163

Browse files
committed
override guardian set
1 parent 154c200 commit 0eeb163

File tree

5 files changed

+161
-1
lines changed

5 files changed

+161
-1
lines changed

bun.lock

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"dependencies": {
77
"@types/express": "^5.0.3",
88
"express": "^5.1.0",
9+
"viem": "^2.31.7",
910
},
1011
"devDependencies": {
1112
"@types/bun": "latest",
@@ -16,6 +17,20 @@
1617
},
1718
},
1819
"packages": {
20+
"@adraffy/ens-normalize": ["@adraffy/[email protected]", "", {}, "sha512-/3DDPKHqqIqxUULp8yP4zODUY1i+2xvVWsv8A79xGWdCAG+8sb0hRh0Rk2QyOJUnnbyPUAZYcpBuRe3nS2OIUg=="],
21+
22+
"@noble/ciphers": ["@noble/[email protected]", "", {}, "sha512-2I0gnIVPtfnMw9ee9h1dJG7tp81+8Ob3OJb3Mv37rx5L40/b0i7djjCVvGOVqc9AEIQyvyu1i6ypKdFw8R8gQw=="],
23+
24+
"@noble/curves": ["@noble/[email protected]", "", { "dependencies": { "@noble/hashes": "1.8.0" } }, "sha512-HxngEd2XUcg9xi20JkwlLCtYwfoFw4JGkuZpT+WlsPD4gB/cxkvTD8fSsoAnphGZhFdZYKeQIPCuFlWPm1uE0g=="],
25+
26+
"@noble/hashes": ["@noble/[email protected]", "", {}, "sha512-jCs9ldd7NwzpgXDIf6P3+NrHh9/sD6CQdxHyjQI+h/6rDNo88ypBxxz45UDuZHz9r3tNz7N/VInSVoVdtXEI4A=="],
27+
28+
"@scure/base": ["@scure/[email protected]", "", {}, "sha512-g/nm5FgUa//MCj1gV09zTJTaM6KBAHqLN907YVQqf7zC49+DcO4B1so4ZX07Ef10Twr6nuqYEH9GEggFXA4Fmg=="],
29+
30+
"@scure/bip32": ["@scure/[email protected]", "", { "dependencies": { "@noble/curves": "~1.9.0", "@noble/hashes": "~1.8.0", "@scure/base": "~1.2.5" } }, "sha512-E4FFX/N3f4B80AKWp5dP6ow+flD1LQZo/w8UnLGYZO674jS6YnYeepycOOksv+vLPSpgN35wgKgy+ybfTb2SMw=="],
31+
32+
"@scure/bip39": ["@scure/[email protected]", "", { "dependencies": { "@noble/hashes": "~1.8.0", "@scure/base": "~1.2.5" } }, "sha512-+lF0BbLiJNwVlev4eKelw1WWLaiKXw7sSl8T6FvBlWkdX+94aGJ4o8XjUdlyhTCjd8c+B3KT3JfS8P0bLRNU6A=="],
33+
1934
"@types/body-parser": ["@types/[email protected]", "", { "dependencies": { "@types/connect": "*", "@types/node": "*" } }, "sha512-HLFeCYgz89uk22N5Qg3dvGvsv46B8GLvKKo1zKG4NybA8U2DiEO3w9lqGg29t/tfLRJpJ6iQxnVw4OnB7MoM9g=="],
2035

2136
"@types/bun": ["@types/[email protected]", "", { "dependencies": { "bun-types": "1.2.18" } }, "sha512-Xf6RaWVheyemaThV0kUfaAUvCNokFr+bH8Jxp+tTZfx7dAPA8z9ePnP9S9+Vspzuxxx9JRAXhnyccRj3GyCMdQ=="],
@@ -42,6 +57,8 @@
4257

4358
"@types/serve-static": ["@types/[email protected]", "", { "dependencies": { "@types/http-errors": "*", "@types/node": "*", "@types/send": "*" } }, "sha512-roei0UY3LhpOJvjbIP6ZZFngyLKl5dskOtDhxY5THRSpO+ZI+nzJ+m5yUMzGrp89YRa7lvknKkMYjqQFGwA7Sg=="],
4459

60+
"abitype": ["[email protected]", "", { "peerDependencies": { "typescript": ">=5.0.4", "zod": "^3 >=3.22.0" }, "optionalPeers": ["typescript", "zod"] }, "sha512-ZeiI6h3GnW06uYDLx0etQtX/p8E24UaHHBj57RSjK7YBFe7iuVn07EDpOeP451D06sF27VOz9JJPlIKJmXgkEg=="],
61+
4562
"accepts": ["[email protected]", "", { "dependencies": { "mime-types": "^3.0.0", "negotiator": "^1.0.0" } }, "sha512-5cvg6CtKwfgdmVqY1WIiXKc3Q1bkRqGLi+2W/6ao+6Y7gu/RCwRuAhGEzh5B4KlszSuTLgZYuqFqo5bImjNKng=="],
4663

4764
"body-parser": ["[email protected]", "", { "dependencies": { "bytes": "^3.1.2", "content-type": "^1.0.5", "debug": "^4.4.0", "http-errors": "^2.0.0", "iconv-lite": "^0.6.3", "on-finished": "^2.4.1", "qs": "^6.14.0", "raw-body": "^3.0.0", "type-is": "^2.0.0" } }, "sha512-02qvAaxv8tp7fBa/mw1ga98OGm+eCbqzJOKoRt70sLmfEEi+jyBYVTDGfCL/k06/4EMk/z01gCe7HoCH/f2LTg=="],
@@ -84,6 +101,8 @@
84101

85102
"etag": ["[email protected]", "", {}, "sha512-aIL5Fx7mawVa300al2BnEE4iNvo1qETxLrPI/o05L7z6go7fCw1J6EQmbK4FmJ2AS7kgVF/KEZWufBfdClMcPg=="],
86103

104+
"eventemitter3": ["[email protected]", "", {}, "sha512-GWkBvjiSZK87ELrYOSESUYeVIc9mvLLf/nXalMOS5dYrgZq9o5OVkbZAVM06CVxYsCwH9BDZFPlQTlPA1j4ahA=="],
105+
87106
"express": ["[email protected]", "", { "dependencies": { "accepts": "^2.0.0", "body-parser": "^2.2.0", "content-disposition": "^1.0.0", "content-type": "^1.0.5", "cookie": "^0.7.1", "cookie-signature": "^1.2.1", "debug": "^4.4.0", "encodeurl": "^2.0.0", "escape-html": "^1.0.3", "etag": "^1.8.1", "finalhandler": "^2.1.0", "fresh": "^2.0.0", "http-errors": "^2.0.0", "merge-descriptors": "^2.0.0", "mime-types": "^3.0.0", "on-finished": "^2.4.1", "once": "^1.4.0", "parseurl": "^1.3.3", "proxy-addr": "^2.0.7", "qs": "^6.14.0", "range-parser": "^1.2.1", "router": "^2.2.0", "send": "^1.1.0", "serve-static": "^2.2.0", "statuses": "^2.0.1", "type-is": "^2.0.1", "vary": "^1.1.2" } }, "sha512-DT9ck5YIRU+8GYzzU5kT3eHGA5iL+1Zd0EutOmTE9Dtk+Tvuzd23VBU+ec7HPNSTxXYO55gPV/hq4pSBJDjFpA=="],
88107

89108
"finalhandler": ["[email protected]", "", { "dependencies": { "debug": "^4.4.0", "encodeurl": "^2.0.0", "escape-html": "^1.0.3", "on-finished": "^2.4.1", "parseurl": "^1.3.3", "statuses": "^2.0.1" } }, "sha512-/t88Ty3d5JWQbWYgaOGCCYfXRwV1+be02WqYYlL6h0lEiUAMPM8o8qKGO01YIkOHzka2up08wvgYD0mDiI+q3Q=="],
@@ -114,6 +133,8 @@
114133

115134
"is-promise": ["[email protected]", "", {}, "sha512-hvpoI6korhJMnej285dSg6nu1+e6uxs7zG3BYAm5byqDsgJNWwxzM6z6iZiAgQR4TJ30JmBTOwqZUw3WlyH3AQ=="],
116135

136+
"isows": ["[email protected]", "", { "peerDependencies": { "ws": "*" } }, "sha512-I1fSfDCZL5P0v33sVqeTDSpcstAg/N+wF5HS033mogOVIp4B+oHC7oOCsA3axAbBSGTJ8QubbNmnIRN/h8U7hg=="],
137+
117138
"math-intrinsics": ["[email protected]", "", {}, "sha512-/IXtbwEk5HTPyEwyKX6hGkYXxM9nbj64B+ilVJnC/R6B0pH5G4V3b0pVbL7DBj4tkhBAppbQUlf6F6Xl9LHu1g=="],
118139

119140
"media-typer": ["[email protected]", "", {}, "sha512-aisnrDP4GNe06UcKFnV5bfMNPBUw4jsLGaWwWfnH3v02GnBuXX2MCVn5RbrWo0j3pczUilYblq7fQ7Nw2t5XKw=="],
@@ -134,6 +155,8 @@
134155

135156
"once": ["[email protected]", "", { "dependencies": { "wrappy": "1" } }, "sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w=="],
136157

158+
"ox": ["[email protected]", "", { "dependencies": { "@adraffy/ens-normalize": "^1.11.0", "@noble/ciphers": "^1.3.0", "@noble/curves": "^1.9.1", "@noble/hashes": "^1.8.0", "@scure/bip32": "^1.7.0", "@scure/bip39": "^1.6.0", "abitype": "^1.0.8", "eventemitter3": "5.0.1" }, "peerDependencies": { "typescript": ">=5.4.0" }, "optionalPeers": ["typescript"] }, "sha512-e+z5epnzV+Zuz91YYujecW8cF01mzmrUtWotJ0oEPym/G82uccs7q0WDHTYL3eiONbTUEvcZrptAKLgTBD3u2A=="],
159+
137160
"parseurl": ["[email protected]", "", {}, "sha512-CiyeOxFT/JZyN5m0z9PfXw4SCBJ6Sygz1Dpl0wqjlhDEGGBP1GnsUVEL0p63hoG1fcj3fHynXi9NYO4nWOL+qQ=="],
138161

139162
"path-to-regexp": ["[email protected]", "", {}, "sha512-TdrF7fW9Rphjq4RjrW0Kp2AW0Ahwu9sRGTkS6bvDi0SCwZlEZYmcfDbEsTz8RVk0EHIS/Vd1bv3JhG+1xZuAyQ=="],
@@ -180,8 +203,12 @@
180203

181204
"vary": ["[email protected]", "", {}, "sha512-BNGbWLfd0eUPabhkXUVm0j8uuvREyTh5ovRa/dyow/BqAbZJyC+5fU+IzQOzmAKzYqYRAISoRhdQr3eIZ/PXqg=="],
182205

206+
"viem": ["[email protected]", "", { "dependencies": { "@noble/curves": "1.9.2", "@noble/hashes": "1.8.0", "@scure/bip32": "1.7.0", "@scure/bip39": "1.6.0", "abitype": "1.0.8", "isows": "1.0.7", "ox": "0.8.1", "ws": "8.18.2" }, "peerDependencies": { "typescript": ">=5.0.4" }, "optionalPeers": ["typescript"] }, "sha512-mpB8Hp6xK77E/b/yJmpAIQcxcOfpbrwWNItjnXaIA8lxZYt4JS433Pge2gg6Hp3PwyFtaUMh01j5L8EXnLTjQQ=="],
207+
183208
"wrappy": ["[email protected]", "", {}, "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ=="],
184209

210+
"ws": ["[email protected]", "", { "peerDependencies": { "bufferutil": "^4.0.1", "utf-8-validate": ">=5.0.2" }, "optionalPeers": ["bufferutil", "utf-8-validate"] }, "sha512-DMricUmwGZUVr++AEAe2uiVM7UoO9MAVZMDu05UQOaUII0lp+zOzLLU4Xqh/JvTqklB1T4uELaaPBKyjE1r4fQ=="],
211+
185212
"http-errors/statuses": ["[email protected]", "", {}, "sha512-RwNA9Z/7PrK06rYLIzFMlaF+l73iwpzsqRIFgbMLbTcLD6cOao82TaWefPXQvB2fOC4AjuYSEndS7N/mTCbkdQ=="],
186213
}
187214
}

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
},
1515
"dependencies": {
1616
"@types/express": "^5.0.3",
17-
"express": "^5.1.0"
17+
"express": "^5.1.0",
18+
"viem": "^2.31.7"
1819
}
1920
}

src/abis/core.ts

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// partial ABI from the Wormhole Core contract
2+
// https://etherscan.io/address/0x3c3d457f1522d3540ab3325aa5f1864e34cba9d0#code
3+
4+
export const CORE_ABI = [
5+
{
6+
anonymous: false,
7+
inputs: [
8+
{
9+
indexed: true,
10+
internalType: "address",
11+
name: "sender",
12+
type: "address",
13+
},
14+
{
15+
indexed: false,
16+
internalType: "uint64",
17+
name: "sequence",
18+
type: "uint64",
19+
},
20+
{ indexed: false, internalType: "uint32", name: "nonce", type: "uint32" },
21+
{ indexed: false, internalType: "bytes", name: "payload", type: "bytes" },
22+
{
23+
indexed: false,
24+
internalType: "uint8",
25+
name: "consistencyLevel",
26+
type: "uint8",
27+
},
28+
],
29+
name: "LogMessagePublished",
30+
type: "event",
31+
},
32+
{
33+
inputs: [],
34+
name: "getCurrentGuardianSetIndex",
35+
outputs: [{ internalType: "uint32", name: "", type: "uint32" }],
36+
stateMutability: "view",
37+
type: "function",
38+
},
39+
{
40+
inputs: [{ internalType: "uint32", name: "index", type: "uint32" }],
41+
name: "getGuardianSet",
42+
outputs: [
43+
{
44+
components: [
45+
{ internalType: "address[]", name: "keys", type: "address[]" },
46+
{ internalType: "uint32", name: "expirationTime", type: "uint32" },
47+
],
48+
internalType: "struct Structs.GuardianSet",
49+
name: "",
50+
type: "tuple",
51+
},
52+
],
53+
stateMutability: "view",
54+
type: "function",
55+
},
56+
] as const;

src/index.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
11
import express, { type Request, type Response } from "express";
2+
import { overrideGuardianSet } from "./overrideGuardianSet";
3+
4+
await overrideGuardianSet(
5+
"http://anvil-eth-sepolia:8545",
6+
"0x4a8bc80Ed5a4067f1CCf107057b8270E0cC11A78"
7+
);
8+
await overrideGuardianSet(
9+
"http://anvil-base-sepolia:8545",
10+
"0x79A1027a6A159502049F10906D333EC57E95F083"
11+
);
212

313
const app = express();
414
app.use(express.json());

src/overrideGuardianSet.ts

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import {
2+
createPublicClient,
3+
createTestClient,
4+
encodeAbiParameters,
5+
getContract,
6+
http,
7+
keccak256,
8+
padHex,
9+
parseAbiParameters,
10+
toHex,
11+
type Hex,
12+
} from "viem";
13+
import { anvil } from "viem/chains";
14+
import { CORE_ABI } from "./abis/core";
15+
16+
export async function overrideGuardianSet(
17+
anvilRpcUrl: string,
18+
coreContractAddress: Hex
19+
) {
20+
const transport = http(anvilRpcUrl);
21+
const publicClient = createPublicClient({
22+
chain: anvil,
23+
transport,
24+
});
25+
const coreContract = getContract({
26+
address: coreContractAddress,
27+
abi: CORE_ABI,
28+
client: publicClient,
29+
});
30+
const guardianSetIndex = await coreContract.read.getCurrentGuardianSetIndex();
31+
const anvilClient = createTestClient({
32+
chain: anvil,
33+
mode: "anvil",
34+
transport,
35+
});
36+
const GUARDIAN_SETS_SLOT = padHex("0x02", { dir: "left", size: 32 });
37+
const addressesStorageSlot = keccak256(
38+
encodeAbiParameters(parseAbiParameters("uint32, bytes32"), [
39+
guardianSetIndex,
40+
GUARDIAN_SETS_SLOT,
41+
])
42+
);
43+
const firstIndexStorageSlot = BigInt(keccak256(addressesStorageSlot));
44+
await anvilClient.setStorageAt({
45+
address: coreContractAddress,
46+
index: addressesStorageSlot,
47+
value: padHex("0x01", { dir: "left", size: 32 }),
48+
});
49+
await anvilClient.setStorageAt({
50+
address: coreContractAddress,
51+
index: toHex(firstIndexStorageSlot),
52+
// devnet guardian https://github.com/wormhole-foundation/wormhole/blob/b9d34bef10ec74c345fa4b406559cf44e3d70095/scripts/devnet-consts.json#L323
53+
value: padHex("0xbeFA429d57cD18b7F8A4d91A2da9AB4AF05d0FBe", {
54+
dir: "left",
55+
size: 32,
56+
}),
57+
});
58+
const guardianSet = await coreContract.read.getGuardianSet([
59+
guardianSetIndex,
60+
]);
61+
console.log(
62+
`Overrode guardian set ${guardianSetIndex} of ${anvilRpcUrl} contract ${coreContractAddress} to ${guardianSet.keys.join(
63+
", "
64+
)}`
65+
);
66+
}

0 commit comments

Comments
 (0)