Skip to content

Commit 76c4c6e

Browse files
committed
feat(lazer/sui): readme, cleanup
1 parent 5fa402b commit 76c4c6e

File tree

3 files changed

+39
-6
lines changed

3 files changed

+39
-6
lines changed

lazer/contracts/sui/README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
## Pyth Lazer Sui Contract
2+
3+
`pyth_lazer` is a Sui module that allows consumers to easily parse and verify cryptographically signed price feed data from the Pyth Network's high-frequency Lazer protocol for use on-chain.
4+
5+
This package is built using the Move language and Sui framework.
6+
7+
### Build, test, deploy
8+
9+
Install Sui CLI and build the project:
10+
11+
```shell
12+
brew install sui
13+
sui move build
14+
```
15+
16+
Run tests:
17+
18+
```shell
19+
sui move test
20+
sui move test test_parse_and_verify_le_ecdsa_update # run a specific test
21+
```
22+
23+
Deploy:
24+
TODO

lazer/contracts/sui/sources/pyth_lazer.move

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,23 @@ use pyth_lazer::channel::Self;
88
use sui::bcs;
99
use sui::ecdsa_k1::secp256k1_ecrecover;
1010

11+
const SECP256K1_SIG_LEN: u32 = 65;
1112
const UPDATE_MESSAGE_MAGIC: u32 = 1296547300;
1213
const PAYLOAD_MAGIC: u32 = 2479346549;
1314

1415

16+
// TODO:
17+
// initializer
18+
// administration -> admin cap, upgrade cap, governance?
19+
// storage module -> trusted signers, update fee?, treasury?
20+
// error handling
21+
// standalone verify signature function
22+
1523
/// Parse the Lazer update message and validate the signature.
1624
///
1725
/// The parsing logic is based on the Lazer rust protocol definition defined here:
1826
/// https://github.com/pyth-network/pyth-crosschain/tree/main/lazer/sdk/rust/protocol
19-
public fun parse_and_validate_update(update: vector<u8>): Update {
27+
public fun parse_and_verify_le_ecdsa_update(update: vector<u8>): Update {
2028
let mut cursor = bcs::new(update);
2129

2230
let magic = cursor.peel_u32();
@@ -25,7 +33,7 @@ public fun parse_and_validate_update(update: vector<u8>): Update {
2533
let mut signature = vector::empty<u8>();
2634

2735
let mut sig_i = 0;
28-
while (sig_i < 65) {
36+
while (sig_i < SECP256K1_SIG_LEN) {
2937
signature.push_back(cursor.peel_u8());
3038
sig_i = sig_i + 1;
3139
};
@@ -40,6 +48,7 @@ public fun parse_and_validate_update(update: vector<u8>): Update {
4048
let pubkey = secp256k1_ecrecover(&signature, &payload, 0);
4149

4250
// Lazer signer pubkey
51+
// FIXME: validate against trusted signer set in storage
4352
assert!(pubkey == x"03a4380f01136eb2640f90c17e1e319e02bbafbeef2e6e67dc48af53f9827e155b", 0);
4453

4554
let mut cursor = bcs::new(payload);
@@ -139,7 +148,7 @@ public fun parse_and_validate_update(update: vector<u8>): Update {
139148
} else {
140149
// When we have an unknown property, we do not know its length, and therefore
141150
// we cannot ignore it and parse the next properties.
142-
abort 0
151+
abort 0 // FIXME: return more granular error messages
143152
};
144153

145154
properties_i = properties_i + 1;

lazer/contracts/sui/tests/pyth_lazer_tests.move

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
#[test_only]
22
module pyth_lazer::pyth_lazer_tests;
3-
use pyth_lazer::pyth_lazer::parse_and_validate_update;
3+
use pyth_lazer::pyth_lazer::parse_and_verify_le_ecdsa_update;
44
use pyth_lazer::channel::new_fixed_rate_200ms;
55
use pyth_lazer::i16::{Self};
66
use pyth_lazer::i64::{Self};
77

88
#[test]
9-
public fun test_parse_and_validate_update() {
9+
public fun test_parse_and_verify_le_ecdsa_update() {
1010
/*
1111
The test data is from the Lazer subscription:
1212
> Request
@@ -51,7 +51,7 @@ public fun test_parse_and_validate_update() {
5151
let hex_message =
5252
x"e4bd474daafa101a7cdc2f4af22f5735aa3278f7161ae15efa9eac3851ca437e322fde467c9475497e1297499344826fe1209f6de234dce35bdfab8bf6b073be12a07cb201930075d3c793c063467c0f3b0600030301000000060055a0e054c40a0000011f679842c40a0000021c94868bc40a000004f8ff0600070002000000060032521511590000000177ac04105900000002a33b71125900000004f8ff060007007000000006000038d1d42c43a60101000000000000000002000000000000000004f4ff060100e1f50500000000070100e07ecb0c3b0600";
5353

54-
let update = parse_and_validate_update(hex_message);
54+
let update = parse_and_verify_le_ecdsa_update(hex_message);
5555

5656
// If we reach this point, the function worked correctly
5757
// (no assertion failures in parse_and_validate_update)

0 commit comments

Comments
 (0)