-
Notifications
You must be signed in to change notification settings - Fork 300
feat(lazer/sui): verify signatures against trusted signers #2982
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
2c4ae46
feat(lazer/sui): specify version
tejasbadadare 69682bc
feat(lazer-sui): add state module with trusted signer storage and tests
devin-ai-integration[bot] 21d8937
Merge branch 'tb/lazer/sui-storage' of github.com:pyth-network/pyth-c…
tejasbadadare 7380293
fix
devin-ai-integration[bot] 0e70796
Merge branch 'tb/lazer/sui-storage' of github.com:pyth-network/pyth-c…
tejasbadadare f34b7fc
fix(sui-lazer): finalize state module with trusted signer management …
devin-ai-integration[bot] 112cd39
Merge branch 'tb/lazer/sui-storage' of github.com:pyth-network/pyth-c…
tejasbadadare d7bd862
chore(sui-lazer): remove warnings in state module; clean build on Sui…
devin-ai-integration[bot] 48e070d
feat(lazer/sui): add trusted signer state
tejasbadadare 8ee64ba
feat(lazer/sui): add package init and AdminCapability; share State an…
devin-ai-integration[bot] a7436fa
comments
tejasbadadare 88ef465
Merge branch 'tb/lazer/sui-storage' of github.com:pyth-network/pyth-c…
tejasbadadare e64eb21
resolve warnings
tejasbadadare 187f0e9
feat(sui-lazer): add admin-gated entry to update trusted signer via A…
devin-ai-integration[bot] ddad6d6
Revert "feat(sui-lazer): add admin-gated entry to update trusted sign…
devin-ai-integration[bot] 0fc417e
naming, make update_trusted_signer public
tejasbadadare da1a2a1
feat(sui-lazer): use OTW for AdminCap in admin::init; add OTW to pyth…
devin-ai-integration[bot] 389f5d7
lint
tejasbadadare f1b6fc4
doc
tejasbadadare 96eaa10
feat(lazer/sui): verify against trusted signers
tejasbadadare f53e83f
docs, clean up
tejasbadadare b9a844d
remove unneeded otw type check
tejasbadadare 9c92f6e
Merge branch 'tb/lazer/sui-storage' of github.com:pyth-network/pyth-c…
tejasbadadare 41c66dc
lint
tejasbadadare 7f10b9d
Merge branch 'tb/lazer/sui-storage' of github.com:pyth-network/pyth-c…
tejasbadadare d8028d1
max verify_le_ecdsa_message package private
tejasbadadare 54ad564
Merge branch 'main' of github.com:pyth-network/pyth-crosschain into t…
tejasbadadare 049363c
fix imports
tejasbadadare File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,11 @@ | ||
module pyth_lazer::state; | ||
|
||
use pyth_lazer::admin::AdminCap; | ||
use pyth_lazer::admin; | ||
use pyth_lazer::admin::{Self, AdminCap}; | ||
|
||
const ED25519_PUBKEY_LEN: u64 = 32; | ||
const SECP256K1_COMPRESSED_PUBKEY_LEN: u64 = 33; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Was this mislabeled? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Gave a more accurate name |
||
const EInvalidPubkeyLen: u64 = 1; | ||
const ESignerNotFound: u64 = 2; | ||
|
||
|
||
/// Lazer State consists of the current set of trusted signers. | ||
/// By verifying that a price update was signed by one of these public keys, | ||
/// you can validate the authenticity of a Lazer price update. | ||
|
@@ -18,7 +16,7 @@ public struct State has key, store { | |
trusted_signers: vector<TrustedSignerInfo>, | ||
} | ||
|
||
/// A trusted signer is comprised of a pubkey and an expiry time. | ||
/// A trusted signer is comprised of a pubkey and an expiry timestamp (seconds since Unix epoch). | ||
/// A signer's signature should only be trusted up to timestamp `expires_at`. | ||
public struct TrustedSignerInfo has copy, drop, store { | ||
public_key: vector<u8>, | ||
|
@@ -37,7 +35,7 @@ public fun public_key(info: &TrustedSignerInfo): &vector<u8> { | |
&info.public_key | ||
} | ||
|
||
/// Get the trusted signer's expiry timestamp | ||
/// Get the trusted signer's expiry timestamp (seconds since Unix epoch) | ||
public fun expires_at(info: &TrustedSignerInfo): u64 { | ||
info.expires_at | ||
} | ||
|
@@ -52,7 +50,7 @@ public fun get_trusted_signers(s: &State): &vector<TrustedSignerInfo> { | |
/// - If the expired_at is set to zero, the trusted signer will be removed. | ||
/// - If the pubkey isn't found, it is added as a new trusted signer with the given expires_at. | ||
public fun update_trusted_signer(_: &AdminCap, s: &mut State, pubkey: vector<u8>, expires_at: u64) { | ||
assert!(vector::length(&pubkey) as u64 == ED25519_PUBKEY_LEN, EInvalidPubkeyLen); | ||
assert!(vector::length(&pubkey) as u64 == SECP256K1_COMPRESSED_PUBKEY_LEN, EInvalidPubkeyLen); | ||
|
||
let mut maybe_idx = find_signer_index(&s.trusted_signers, &pubkey); | ||
if (expires_at == 0) { | ||
|
@@ -80,12 +78,15 @@ public fun update_trusted_signer(_: &AdminCap, s: &mut State, pubkey: vector<u8> | |
} | ||
} | ||
|
||
fun find_signer_index(signers: &vector<TrustedSignerInfo>, target: &vector<u8>): Option<u64> { | ||
public fun find_signer_index( | ||
signers: &vector<TrustedSignerInfo>, | ||
public_key: &vector<u8>, | ||
): Option<u64> { | ||
let len = vector::length(signers); | ||
let mut i: u64 = 0; | ||
while (i < (len as u64)) { | ||
let info_ref = vector::borrow(signers, i); | ||
if (*public_key(info_ref) == *target) { | ||
if (*public_key(info_ref) == *public_key) { | ||
return option::some(i) | ||
}; | ||
i = i + 1 | ||
|
@@ -101,13 +102,20 @@ public fun new_for_test(ctx: &mut TxContext): State { | |
} | ||
} | ||
|
||
#[test_only] | ||
public fun destroy_for_test(s: State) { | ||
let State { id, trusted_signers } = s; | ||
let _ = trusted_signers; | ||
object::delete(id); | ||
} | ||
|
||
#[test] | ||
public fun test_add_new_signer() { | ||
let mut ctx = tx_context::dummy(); | ||
let mut s = new_for_test(&mut ctx); | ||
let admin_cap = admin::mint_for_test(&mut ctx); | ||
|
||
let pk = x"0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f20"; | ||
let pk = x"030102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f20"; | ||
let expiry: u64 = 123; | ||
|
||
update_trusted_signer(&admin_cap, &mut s, pk, expiry); | ||
|
@@ -117,7 +125,7 @@ public fun test_add_new_signer() { | |
let info = vector::borrow(signers_ref, 0); | ||
assert!(expires_at(info) == 123, 101); | ||
let got_pk = public_key(info); | ||
assert!(vector::length(got_pk) == (ED25519_PUBKEY_LEN as u64), 102); | ||
assert!(vector::length(got_pk) == (SECP256K1_COMPRESSED_PUBKEY_LEN as u64), 102); | ||
let State { id, trusted_signers } = s; | ||
let _ = trusted_signers; | ||
object::delete(id); | ||
|
@@ -133,13 +141,13 @@ public fun test_update_existing_signer_expiry() { | |
update_trusted_signer( | ||
&admin_cap, | ||
&mut s, | ||
x"2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a", | ||
x"032a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a", | ||
1000, | ||
); | ||
update_trusted_signer( | ||
&admin_cap, | ||
&mut s, | ||
x"2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a", | ||
x"032a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a", | ||
2000, | ||
); | ||
|
||
|
@@ -162,13 +170,13 @@ public fun test_remove_signer_by_zero_expiry() { | |
update_trusted_signer( | ||
&admin_cap, | ||
&mut s, | ||
x"0707070707070707070707070707070707070707070707070707070707070707", | ||
x"030707070707070707070707070707070707070707070707070707070707070707", | ||
999, | ||
); | ||
update_trusted_signer( | ||
&admin_cap, | ||
&mut s, | ||
x"0707070707070707070707070707070707070707070707070707070707070707", | ||
x"030707070707070707070707070707070707070707070707070707070707070707", | ||
0, | ||
); | ||
|
||
|
@@ -204,7 +212,7 @@ public fun test_remove_nonexistent_signer_fails() { | |
update_trusted_signer( | ||
&admin_cap, | ||
&mut s, | ||
x"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", | ||
x"03aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", | ||
0, | ||
); | ||
let State { id, trusted_signers } = s; | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this no longer a fixme?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still a FIXME since there are several other places in the parsing where the code can revert. Will be tackling this next.