Skip to content

Commit eb38a68

Browse files
committed
llm check
1 parent 55c5e81 commit eb38a68

File tree

1 file changed

+50
-34
lines changed

1 file changed

+50
-34
lines changed

llms.txt

+50-34
Original file line numberDiff line numberDiff line change
@@ -21920,7 +21920,7 @@ export const TXS = [
2192021920

2192121921
- **`RPC`** - endpoint for interacting with an Ethereum RPC node
2192221922
- **`ETH_CORE`** - [Wormhole's Core Contract address on Ethereum](/docs/build/reference/contract-addresses/#core-contracts){target=\_blank} responsible for verifying VAAs
21923-
- **`WORMHOLESCAN_API`** - base URL for querying the Wormholescan API to fetch VAA data and guardian sets
21923+
- **`WORMHOLESCAN_API`** - base URL for querying the Wormholescan API to fetch VAA data and Guardian sets
2192421924
- **`LOG_MESSAGE_PUBLISHED_TOPIC`** - the event signature hash for `LogMessagePublished`, a Wormhole contract event that signals when a VAA has been emitted. This is used to identify relevant logs in transaction receipts
2192521925
- **`TXS`** - list of example transaction hashes that will be used for testing
2192621926

@@ -21969,7 +21969,8 @@ export const TXS = [
2196921969

2197021970
## Create VAA Handling Functions
2197121971

21972-
In this section, we'll create a series of helper functions in the `src/helpers/vaaHelper.ts` file that will retrieve and verify VAAs and fetch and replace outdated Guardian signatures to generate a correctly signed VAA.
21972+
In this section, we'll create a series of helper functions in the `src/helpers/vaaHelper.ts` file that will retrieve and verify VAAs and fetch and replace outdated Guardian signatures to generate a correctly signed VAA.
21973+
2197321974
To get started, import the necessary dependencies:
2197421975

2197521976
```typescript title="src/helpers/vaaHelper.ts"
@@ -22003,7 +22004,16 @@ chain/emitter/sequence
2200322004
- `sequence` - a unique identifier for the event
2200422005

2200522006
We must assemble the ID correctly since this is the format the Wormholescan API expects when querying VAAs.
22006-
Add the `fetchVaaId()` function to extract the VAA ID from a transaction hash. Query the Ethereum node for a transaction receipt, check for a Wormhole message, and construct the VAA ID in the format `chain/emitter/sequence`.
22007+
22008+
To retrieve a VAA, we need to extract its VAA ID from a transaction hash. Follow the below steps to process the transaction logs and construct the VAA ID:
22009+
22010+
1. **Get the transaction receipt** - iterate over the array of transaction hashes and fetch the receipt to access its logs
22011+
22012+
2. **Find the Wormhole event** - iterate over the transaction logs and check for events emitted by the Wormhole Core contract. Look specifically for `LogMessagePublished` events, which indicate a VAA was created
22013+
22014+
3. **Extract the emitter and sequence number** - if a matching event is found, extract the emitter address from `log.topics[1]` and remove the `0x` prefix. Then, the sequence number from `log.data` is extracted, converting it from hex to an integer
22015+
22016+
4. **Construct the VAA ID** - format the extracted data in `chain/emitter/sequence` format
2200722017

2200822018
```typescript title="src/helpers/vaaHelper.ts"
2200922019
const vaaIds: string[] = [];
@@ -22041,11 +22051,6 @@ const vaaIds: string[] = [];
2204122051
}
2204222052
```
2204322053

22044-
- **`log.address === ETH_CORE`** - ensures the event was emitted by the Wormhole contract
22045-
- **`log.topics?.[0] === LOG_MESSAGE_PUBLISHED_TOPIC`** - filters for `LogMessagePublished` events, which indicate a VAA was created
22046-
- **`emitter`** - extracts the emitter address from `log.topics[1]`, removing the `0x` prefix
22047-
- **`seq`** - extracts the sequence number by reading the first 66 characters of `log.data`, converting it from hex to an integer
22048-
2204922054
???- code "Try it out: VAA ID retrieval"
2205022055
If you want to try out the function before moving forward, create a test file inside the `test` directory:
2205122056

@@ -22103,7 +22108,7 @@ testFetchVaaId();
2210322108

2210422109
Now that you have the VAA ID, we can use it to fetch the full VAA payload from the Wormholescan API. This payload contains the VAA bytes, which will later be used for signature validation.
2210522110

22106-
Open `src/helpers/vaaHelper.ts` and create the `fetchVaa()` function to iterate through VAA IDs, query the API, and extract the `vaaBytes` payload. Log any errors and continue processing the remaining IDs to ensure all available VAAs are retrieved.
22111+
Open `src/helpers/vaaHelper.ts` and create the `fetchVaa()` function to iterate through VAA IDs and extract the `vaaBytes` payload.
2210722112

2210822113
```typescript title="src/helpers/vaaHelper.ts"
2210922114
vaaIds: string[]
@@ -22123,7 +22128,7 @@ vaaIds: string[]
2212322128
}
2212422129
```
2212522130

22126-
???- note "Try it out: VAA retrieval"
22131+
???- code "Try it out: VAA retrieval"
2212722132
If you want to try the function before moving forward, create a script inside the `test` directory
2212822133

2212922134
1. **Create the script file**
@@ -22186,9 +22191,17 @@ testFetchVaa();
2218622191

2218722192
### Validate VAA Signatures
2218822193

22189-
Now, we need to verify its validity. A VAA is only considered valid if it contains signatures from currently active guardians and is correctly verified by the Wormhole Core contract.
22194+
Now, we need to verify its validity. A VAA is only considered valid if it contains signatures from currently active Guardians and is correctly verified by the Wormhole Core contract.
22195+
22196+
Open `src/helpers/vaaHelper.ts` and add the `checkVaaValidity()` function. This function verifies whether a VAA is valid by submitting it to an Ethereum RPC node and checking for outdated signatures.
2219022197

22191-
Open `src/helpers/vaaHelper.ts` and add the `checkVaaValidity()` function. Send the VAA to an Ethereum RPC node, call the `parseAndVerifyVM` function on the Wormhole Core contract, and determine whether the VAA is valid or contains outdated signatures that need replacing.
22198+
Follow these steps to implement the function:
22199+
22200+
1. **Prepare the VAA for verification** - construct the VAA payload in a format that can be sent to the Wormhole Core contract
22201+
22202+
2. **Send an `eth_call` request** - submit the VAA to an Ethereum RPC node, calling the `parseAndVerifyVM` function on the Wormhole Core contract
22203+
22204+
3. **Decode the response** - check whether the VAA is valid. If it contains outdated signatures, further action will be required to replace them
2219222205

2219322206
```typescript title="src/helpers/vaaHelper.ts"
2219422207
try {
@@ -22231,7 +22244,7 @@ try {
2223122244
}
2223222245
```
2223322246

22234-
???- note "Try it out: VAA Validity"
22247+
???- code "Try it out: VAA Validity"
2223522248
If you want to try the function before moving forward, create a script inside the `test` directory
2223622249

2223722250
1. **Create the script file**
@@ -22308,9 +22321,9 @@ testCheckVaaValidity();
2230822321

2230922322
### Fetch Observations (VAA Signatures)
2231022323

22311-
Before replacing outdated signatures, we need to fetch the original VAA signatures from Wormholescan. This allows us to compare them with the latest guardian set and determine which ones need updating.
22324+
Before replacing outdated signatures, we need to fetch the original VAA signatures from Wormholescan. This allows us to compare them with the latest Guardian set and determine which ones need updating.
2231222325

22313-
Inside `src/helpers/vaaHelper.ts`, create the `fetchObservations()` function to query the Wormholescan API for observations related to a given VAA. Format the response by converting guardian addresses to lowercase for consistency, and return an empty array if an error occurs.
22326+
Inside `src/helpers/vaaHelper.ts`, create the `fetchObservations()` function to query the Wormholescan API for observations related to a given VAA. Format the response by converting Guardian addresses to lowercase for consistency, and return an empty array if an error occurs.
2231422327

2231522328
```typescript title="src/helpers/vaaHelper.ts"
2231622329
try {
@@ -22331,7 +22344,7 @@ try {
2233122344
}
2233222345
```
2233322346

22334-
???- note "Try it out: Fetch Observations"
22347+
???- code "Try it out: Fetch Observations"
2233522348
If you want to try the function before moving forward, create a script inside the `test` directory
2233622349

2233722350
1. **Create the script file**
@@ -22404,9 +22417,9 @@ testFetchObservations();
2240422417

2240522418
### Fetch the Latest Guardian Set
2240622419

22407-
Now that we have the original VAA signatures, we must fetch the latest guardian set from Wormholescan. This will allow us to compare the stored signatures with the current guardians and determine which signatures need replacing.
22420+
Now that we have the original VAA signatures, we must fetch the latest Guardian set from Wormholescan. This will allow us to compare the stored signatures with the current Guardians and determine which signatures need replacing.
2240822421

22409-
Create the `fetchGuardianSet()` function inside `src/helpers/vaaHelper.ts` to fetch the latest guardian set.
22422+
Create the `fetchGuardianSet()` function inside `src/helpers/vaaHelper.ts` to fetch the latest Guardian set.
2241022423

2241122424
```typescript title="src/helpers/vaaHelper.ts"
2241222425
export async function fetchGuardianSet() {
@@ -22427,7 +22440,7 @@ export async function fetchGuardianSet() {
2242722440
}
2242822441
```
2242922442

22430-
???- note "Try it out: Fetch Guardian Set"
22443+
???- code "Try it out: Fetch Guardian Set"
2243122444
If you want to try the function before moving forward, create a script inside the `test` directory
2243222445

2243322446
1. **Create the script file**
@@ -22474,38 +22487,37 @@ testFetchGuardianSet();
2247422487
<span data-ty="input"><span class="file-path"></span></span>
2247522488
</div>
2247622489

22477-
If an error occurs while fetching the guardian set, a `500` status error will be logged.
22490+
If an error occurs while fetching the Guardian set, a `500` status error will be logged.
2247822491

2247922492
### Replace Outdated Signatures
2248022493

22481-
With the full VAA, guardian signatures, and the latest guardian set, we can now update outdated signatures while maintaining the required signature count.
22494+
With the full VAA, Guardian signatures, and the latest Guardian set, we can now update outdated signatures while maintaining the required signature count.
2248222495

22483-
1. **Create the `replaceSignatures()` function** - open `src/helpers/vaaHelper.ts` and add the function header
22496+
1. **Create the `replaceSignatures()` function** - open `src/helpers/vaaHelper.ts` and add the function header. To catch and handle errors properly, all logic will be wrapped inside a `try` block.
2248422497

2248522498
```typescript title="src/helpers/vaaHelper.ts"
2248622499
vaa: string | Uint8Array<ArrayBufferLike>,
2248722500
observations: { guardianAddr: string; signature: string }[],
2248822501
currentGuardians: string[],
2248922502
guardianSetIndex: number
2249022503
) {
22491-
console.log('Replacing Signatures...');
22504+
try {}
2249222505
```
2249322506

2249422507
- **`vaa`** - original VAA bytes
2249522508
- **`observations`** - observed signatures from the network
22496-
- **`currentGuardians`** - latest guardian set
22497-
- **`guardianSetIndex`** - current guardian set index
22509+
- **`currentGuardians`** - latest Guardian set
22510+
- **`guardianSetIndex`** - current Guardian set index
2249822511

22499-
2. **Validate input data** - ensure all required parameters are present before proceeding. If any required input is missing, the function throws an error to prevent execution with incomplete data. The guardian set should never be empty; if it is, this likely indicates an error in fetching the guardian set in a previous step
22512+
2. **Validate input data** - ensure all required parameters are present before proceeding. If any required input is missing, the function throws an error to prevent execution with incomplete data. The Guardian set should never be empty; if it is, this likely indicates an error in fetching the Guardian set in a previous step
2250022513

2250122514
```typescript
22502-
if (!vaa) throw new Error('VAA is undefined or empty.');
2250322515
if (currentGuardians.length === 0)
2250422516
throw new Error('Guardian set is empty.');
2250522517
if (observations.length === 0) throw new Error('No observations provided.');
2250622518
```
2250722519

22508-
3. **Filter valid signatures** - remove signatures from inactive guardians, keeping only valid ones. If there aren't enough valid signatures to replace the outdated ones, execution is halted to prevent an incomplete or invalid VAA
22520+
3. **Filter valid signatures** - remove signatures from inactive Guardians, keeping only valid ones. If there aren't enough valid signatures to replace the outdated ones, execution is halted to prevent an incomplete or invalid VAA
2250922521

2251022522
```typescript
2251122523
currentGuardians.includes(sig.guardianAddr)
@@ -22560,7 +22572,7 @@ With the full VAA, guardian signatures, and the latest guardian set, we can now
2256022572
}
2256122573
```
2256222574

22563-
6. **Identify outdated signatures** - compare the current VAA signatures with the newly formatted ones to detect which signatures belong to outdated guardians. Remove these outdated signatures to ensure only valid ones remain
22575+
6. **Identify outdated signatures** - compare the current VAA signatures with the newly formatted ones to detect which signatures belong to outdated Guardians. Remove these outdated signatures to ensure only valid ones remain
2256422576

2256522577
```typescript
2256622578
.filter(
@@ -22617,7 +22629,7 @@ With the full VAA, guardian signatures, and the latest guardian set, we can now
2261722629
}
2261822630
```
2261922631

22620-
9. **Send the updated VAA for verification and handle errors** - submit the updated VAA to an Ethereum RPC node for validation, ensuring it can be proposed for guardian approval. If an error occurs during submission or signature replacement, log the issue and prevent further execution
22632+
9. **Send the updated VAA for verification and handle errors** - submit the updated VAA to an Ethereum RPC node for validation, ensuring it can be proposed for Guardian approval. If an error occurs during submission or signature replacement, log the issue and prevent further execution
2262122633

2262222634
```typescript
2262322635
if (!(patchedVaa instanceof Uint8Array))
@@ -22650,12 +22662,11 @@ With the full VAA, guardian signatures, and the latest guardian set, we can now
2265022662
} catch (error) {
2265122663
console.error('Unexpected error in replaceSignatures:', error);
2265222664
}
22653-
}
2265422665
```
2265522666

2265622667
## Create Script to Replace Outdated VAA Signatures
2265722668

22658-
Now that we have all the necessary helper functions, we will create a script to automate replacing outdated VAA signatures. This script will retrieve a transaction’s VAA sequentially, check its validity, fetch the latest guardian set, and update its signatures. By the end, it will output a correctly signed VAA that can be proposed for guardian approval.
22669+
Now that we have all the necessary helper functions, we will create a script to automate replacing outdated VAA signatures. This script will retrieve a transaction’s VAA sequentially, check its validity, fetch the latest Guardian set, and update its signatures. By the end, it will output a correctly signed VAA that can be proposed for Guardian approval.
2265922670

2266022671
1. **Open the file** - inside `src/scripts/replaceSignatures.ts`, import the required helper functions needed to process the VAAs
2266122672

@@ -22723,6 +22734,10 @@ import { TXS } from '../config/constants';
2272322734

2272422735
To run the script, use the following command:
2272522736

22737+
```bash
22738+
npx tsx src/scripts/replaceSignatures.ts
22739+
```
22740+
2272622741
<div id="termynal" data-termynal>
2272722742
<span data-ty="input"><span class="file-path"></span>npx tsx src/scripts/replaceSignatures.ts</span>
2272822743
<span data-ty> </span>
@@ -22741,14 +22756,15 @@ The script logs each step, skipping valid VAAs, replacing outdated signatures fo
2274122756

2274222757
## Resources
2274322758

22744-
You can explore the complete project and find all necessary scripts and configurations in Wormhole's [demo GitHub repository](https://github.com/wormhole-foundation/demo-vaa-signature-replacement){target=_blank}.
22759+
You can explore the complete project and find all necessary scripts and configurations in Wormhole's [demo GitHub repository](https://github.com/wormhole-foundation/demo-vaa-signature-replacement){target=\_blank}.
22760+
2274522761
The demo repository includes a bonus script to check the VAA redemption status on Ethereum and Solana, allowing you to verify whether a transaction has already been redeemed on the destination chain.
2274622762

2274722763
## Conclusion
2274822764

2274922765
You've successfully built a script to fetch, validate, and replace outdated signatures in VAAs using Wormholescan and the Wormhole SDK.
2275022766

22751-
It's important to note that this tutorial does not update VAAs in the Wormhole network. Before redeeming the VAA, you must propose it for guardian approval to finalize the process.
22767+
It's important to note that this tutorial does not update VAAs in the Wormhole network. Before redeeming the VAA, you must propose it for Guardian approval to finalize the process.
2275222768
--- END CONTENT ---
2275322769

2275422770
Doc-Content: https://wormhole.com/docs/tutorials/

0 commit comments

Comments
 (0)