Skip to content

Commit 60e4621

Browse files
committed
fix so tests pass
1 parent 2247679 commit 60e4621

File tree

4 files changed

+6932
-13
lines changed

4 files changed

+6932
-13
lines changed

basics/solana-signature-verification/anchor/README.md

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,30 @@
11
# Solana Program: Unlocking a Vault Based on SOL Price and Signature Verification
2+
23
This Solana escrow program allows users to withdraw funds only when the SOL price reaches a certain target and after verifying their Ed25519 signature.
4+
35
## Ed25519 Signature Verification
6+
47
In Solana, programs cannot directly call the Ed25519 program using a CPI (Cross-Program Invocation) because signature verification is computationally expensive. Instead, the Ed25519 signature verification program exists as a precompiled instruction outside the Solana Virtual Machine (SVM).
58
we do verification by passing two instructions one [Ed25519 program](https://github.com/anza-xyz/agave/blob/master/sdk/ed25519-program/src/lib.rs) ix and second our custom logic ix (it mush have a sysvar ix to get current chain state)
69

710
The sysvar instructions account provides access to all instructions within the same transaction.
811
This allows our program to fetch and verify the arguments passed to the Ed25519 program, ensuring they were correctly signed before unlocking funds.
12+
13+
## Running test
14+
15+
To run this test on devnet, you can do the following:
16+
17+
```bash
18+
$ pnpm install
19+
$ anchor test --skip-deploy
20+
```
21+
922
# Vault Unlock Conditions
23+
1024
The SOL price must meet or exceed the target threshold & Ed25519 signature must be verified
25+
1126
# Vault Architecture
27+
1228
```mermaid
1329
flowchart TD
1430
%% Style Definitions - GitHub Monochrome Colors
@@ -28,13 +44,13 @@ flowchart TD
2844
%% Program Logic
2945
subgraph ProgramFlow["Escrow Program"]
3046
class ProgramFlow boxStyle
31-
47+
3248
%% Signature Verification
3349
subgraph SigVerification["Ed25519 Signature Verification"]
3450
class SigVerification subBoxStyle
3551
GetPrevIx["Get Previous Instruction"]
3652
VerifyProgram["Verify Ed25519 Program ID"]
37-
53+
3854
subgraph OffsetValidation["Signature Offset Validation"]
3955
class OffsetValidation lighterBoxStyle
4056
ValidatePK["Validate Public Key Offset"]
@@ -47,7 +63,7 @@ flowchart TD
4763
%% Main Operations
4864
subgraph Operations["Program Operations"]
4965
class Operations subBoxStyle
50-
66+
5167
subgraph DepositFlow["Deposit Handler"]
5268
class DepositFlow lighterBoxStyle
5369
UpdateState["Update Escrow State:
@@ -71,13 +87,13 @@ flowchart TD
7187
GetPrevIx --> VerifyProgram
7288
VerifyProgram --> OffsetValidation
7389
ValidatePK & ValidateSig & ValidateMsg --> VerifyIndices
74-
90+
7591
VerifyIndices -->|"Signature Valid"| Operations
7692
VerifyIndices -->|"Invalid"| Error["Return Signature Error"]
77-
93+
7894
Operations --> DepositFlow
7995
Operations --> WithdrawFlow
80-
96+
8197
GetPrice --> PriceCheck
8298
PriceCheck -->|"Price > Unlock Price"| TransferToUser
8399
PriceCheck -->|"Price <= Unlock Price"| WithdrawError["Return Invalid Withdrawal Error"]
@@ -87,4 +103,3 @@ flowchart TD
87103
class GetPrevIx,VerifyProgram,Error,WithdrawError subBoxStyle
88104
class UpdateState,TransferToEscrow,GetPrice,CheckAge,PriceCheck,TransferToUser lighterBoxStyle
89105
```
90-

basics/solana-signature-verification/anchor/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"license": "ISC",
33
"scripts": {
4-
"lint:fix": "prettier */*.js \"*/**/*{.js,.ts}\" -w",
5-
"lint": "prettier */*.js \"*/**/*{.js,.ts}\" --check"
4+
"lint:fix": "prettier */*.ts \"*/**/*{.js,.ts}\" -w",
5+
"lint": "prettier */*.ts \"*/**/*{.js,.ts}\" --check"
66
},
77
"dependencies": {
88
"@coral-xyz/anchor": "^0.30.1",

0 commit comments

Comments
 (0)