-
Notifications
You must be signed in to change notification settings - Fork 0
(4) Settler: Signatures #50
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
57 commits
Select commit
Hold shift + click to select a range
878e5ed
Add Whitelist program
GuidoDipietro 57af08c
Settler: Intent lifecycle
GuidoDipietro cc10fad
Settler: Proposal Lifecycle
GuidoDipietro cf0e619
Settler: Signatures
GuidoDipietro f5e81b9
Fix tests
GuidoDipietro 2f91061
Merge branch 'solana/1-whitelist' into solana/2-settler-intent-lifecycle
GuidoDipietro f1545be
Trim tests to this PRs features
GuidoDipietro 9bd0e0e
Rm signatures utils as not relevant in this PR
GuidoDipietro ea31118
Trim SDK to match this PRs features
GuidoDipietro 0707a85
Trim tests to this PRs features
GuidoDipietro 1b87e10
Merge branch 'solana/2-settler-intent-lifecycle' into solana/3-settle…
GuidoDipietro 890d5de
Merge branch 'solana/3-settler-proposal-lifecycle' into solana/4-sett…
GuidoDipietro d05f128
Add remaining files from original PR
GuidoDipietro 3d93df3
EVM: Deploy contracts to Ethereum (#51)
alavarello a20c769
chore: update readme
facuspagnuolo ea6b0fb
Check deadlines on macros instead of ix fn body consistently
GuidoDipietro fc51d1c
Refactor if-return-err to require
GuidoDipietro 804e2a4
Code review: simplify set admin process
GuidoDipietro a8b019b
Code review: Remove updated_by and last_update from EntityRegistry
GuidoDipietro eff0a23
Code review: rename Whitelist to Controller/Allowlist
GuidoDipietro 90c6e3c
Code review: rm EntityRegistry status and close when not in allowlist
GuidoDipietro 5cfce2b
Several fixes in Controller code
GuidoDipietro 4282a1f
Code review: address other comments
GuidoDipietro b918391
Code review: add license
GuidoDipietro 44a93c6
Merge branch 'solana/1-whitelist' into solana/2-settler-intent-lifecycle
GuidoDipietro e916fa1
Code review: adapt Settler to Controller changes
GuidoDipietro a1eb61d
Code review: rename controller::GlobalSettings to ControllerSettings,…
GuidoDipietro 5f8eb31
Code review: rm is_paused from SettlerSettings
GuidoDipietro f42465b
Merge branch 'solana/2-settler-intent-lifecycle' into solana/3-settle…
GuidoDipietro 1039442
Code review: adapt Settler to match Controller changes
GuidoDipietro 435b7dc
Rm unused is_paused flag
GuidoDipietro 5e4eb54
Merge branch 'solana/2-settler-intent-lifecycle' into solana/3-settle…
GuidoDipietro b638369
Fix lint
GuidoDipietro 3130209
Code review: rename proposal_creator to creator
GuidoDipietro efbfea9
Fix lint
GuidoDipietro 876abc6
Merge branch 'solana/3-settler-proposal-lifecycle' into solana/4-sett…
GuidoDipietro 1c1c0c9
Code review: adapt Settler for changes in Controller
GuidoDipietro e1ef9ed
Code review: several comments
GuidoDipietro c715467
Code review: context() pattern in tests
GuidoDipietro 0d815fa
Merge branch 'solana/1-whitelist' into solana/2-settler-intent-lifecycle
GuidoDipietro 40d2ad6
Fix lint and merge errors
GuidoDipietro 89ddecc
Code review: several comments
GuidoDipietro 38d0f18
Merge branch 'solana/2-settler-intent-lifecycle' into solana/3-settle…
GuidoDipietro 4d99fd4
Merge branch 'solana/3-settler-proposal-lifecycle' into solana/4-sett…
GuidoDipietro ba1d144
Code review: change crate::controller to controller
GuidoDipietro 571ea10
Merge branch 'solana/3-settler-proposal-lifecycle' into solana/4-sett…
GuidoDipietro 0ff6529
(1) Add Controller program (#45)
GuidoDipietro e690d3c
Merge branch 'solana/settler' into solana/3-settler-proposal-lifecycle
GuidoDipietro 1ac6503
Revert "Merge branch 'solana/settler' into solana/3-settler-proposal-…
GuidoDipietro 9fd1cc8
Merge branch 'solana/settler' into solana/3-settler-proposal-lifecycle
GuidoDipietro 391eb43
Correct controller.test.ts file
GuidoDipietro f7d2a12
Merge branch 'solana/3-settler-proposal-lifecycle' into solana/4-sett…
GuidoDipietro ce6dba5
Code review: remove batch capabilities from claim_stale_proposal
GuidoDipietro 286e8de
Merge branch 'solana/3-settler-proposal-lifecycle' into solana/4-sett…
GuidoDipietro b869e79
Merge branch 'solana/settler' into solana/4-settler-signatures
GuidoDipietro 80fed04
Code review: remove unused instruction
GuidoDipietro b79f20c
Code review: add_validator_sig EntityRegistry seed checks
GuidoDipietro 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
77 changes: 77 additions & 0 deletions
77
packages/svm/programs/settler/src/instructions/add_axia_sig.rs
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 |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| use anchor_lang::{ | ||
| prelude::{instruction::Instruction, sysvar::instructions::get_instruction_relative, *}, | ||
| solana_program::sysvar::instructions::ID as IX_ID, | ||
| }; | ||
|
|
||
| use crate::{ | ||
| controller::{self, accounts::EntityRegistry, types::EntityType}, | ||
| errors::SettlerError, | ||
| state::Proposal, | ||
| utils::{check_ed25519_ix, get_args_from_ed25519_ix_data, Ed25519Args}, | ||
| }; | ||
|
|
||
| #[derive(Accounts)] | ||
| pub struct AddAxiaSig<'info> { | ||
| #[account(mut)] | ||
| pub solver: Signer<'info>, | ||
|
|
||
| #[account( | ||
| seeds = [b"entity-registry", &[EntityType::Solver as u8 + 1], solver.key().as_ref()], | ||
| bump = solver_registry.bump, | ||
| seeds::program = controller::ID, | ||
| )] | ||
| pub solver_registry: Box<Account<'info, EntityRegistry>>, | ||
|
|
||
| #[account( | ||
| seeds = [b"entity-registry", &[EntityType::Axia as u8 + 1], axia_registry.entity_pubkey.as_ref()], | ||
| bump = axia_registry.bump, | ||
| seeds::program = controller::ID, | ||
| )] | ||
| pub axia_registry: Box<Account<'info, EntityRegistry>>, | ||
|
|
||
| /// CHECK: Any proposal | ||
| #[account( | ||
| mut, | ||
| constraint = proposal.deadline > Clock::get()?.unix_timestamp as u64 @ SettlerError::ProposalIsExpired, | ||
| constraint = proposal.is_final @ SettlerError::ProposalIsNotFinal, | ||
| )] | ||
| pub proposal: Box<Account<'info, Proposal>>, | ||
|
|
||
| /// CHECK: The address check is needed because otherwise | ||
| /// the supplied Sysvar could be anything else. | ||
| #[account(address = IX_ID)] | ||
| pub ix_sysvar: AccountInfo<'info>, | ||
| } | ||
|
|
||
| pub fn add_axia_sig(ctx: Context<AddAxiaSig>) -> Result<()> { | ||
| let proposal = &mut ctx.accounts.proposal; | ||
|
|
||
| // NOP if already signed | ||
| if proposal.is_signed { | ||
| return Ok(()); | ||
| } | ||
|
|
||
| // Get Ed25519 instruction | ||
| let ed25519_ix: Instruction = get_instruction_relative(-1, &ctx.accounts.ix_sysvar)?; | ||
| let ed25519_ix_args: Ed25519Args = get_args_from_ed25519_ix_data(&ed25519_ix.data)?; | ||
|
|
||
| // Verify correct program and accounts | ||
| check_ed25519_ix(&ed25519_ix)?; | ||
|
|
||
| // Verify correct message was signed | ||
| require!( | ||
| ed25519_ix_args.msg == proposal.key().as_array(), | ||
| SettlerError::SigVerificationFailed | ||
| ); | ||
|
|
||
| // Verify pubkey is whitelisted Axia | ||
| require!( | ||
| ed25519_ix_args.pubkey == &ctx.accounts.axia_registry.entity_pubkey.to_bytes(), | ||
| SettlerError::AxiaNotAllowlisted | ||
| ); | ||
|
|
||
| // Updates proposal as signed | ||
| proposal.is_signed = true; | ||
|
|
||
| Ok(()) | ||
| } |
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
91 changes: 91 additions & 0 deletions
91
packages/svm/programs/settler/src/instructions/add_validator_sig.rs
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 |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| use anchor_lang::{ | ||
| prelude::{instruction::Instruction, sysvar::instructions::get_instruction_relative, *}, | ||
| solana_program::sysvar::instructions::ID as IX_ID, | ||
| }; | ||
|
|
||
| use crate::{ | ||
| controller::{self, accounts::EntityRegistry, types::EntityType}, | ||
| errors::SettlerError, | ||
| state::Intent, | ||
| utils::{check_ed25519_ix, get_args_from_ed25519_ix_data, Ed25519Args}, | ||
| }; | ||
|
|
||
| #[derive(Accounts)] | ||
| pub struct AddValidatorSig<'info> { | ||
| #[account(mut)] | ||
| pub solver: Signer<'info>, | ||
|
|
||
| #[account( | ||
| seeds = [b"entity-registry", &[EntityType::Solver as u8 + 1], solver.key().as_ref()], | ||
| bump = solver_registry.bump, | ||
| seeds::program = controller::ID, | ||
| )] | ||
| pub solver_registry: Box<Account<'info, EntityRegistry>>, | ||
|
|
||
| // Any Intent | ||
| #[account( | ||
| mut, | ||
| constraint = intent.deadline > Clock::get()?.unix_timestamp as u64 @ SettlerError::IntentIsExpired, | ||
| constraint = intent.is_final @ SettlerError::IntentIsNotFinal | ||
| )] | ||
| pub intent: Box<Account<'info, Intent>>, | ||
|
|
||
| #[account( | ||
| seeds = [b"fulfilled-intent", intent.hash.as_ref()], | ||
| bump | ||
| )] | ||
| /// This PDA must be uninitialized | ||
| pub fulfilled_intent: SystemAccount<'info>, | ||
|
|
||
| #[account( | ||
| seeds = [b"entity-registry", &[EntityType::Validator as u8 + 1], validator_registry.entity_pubkey.as_ref()], | ||
| bump = validator_registry.bump, | ||
| seeds::program = controller::ID, | ||
| )] | ||
| pub validator_registry: Box<Account<'info, EntityRegistry>>, | ||
|
|
||
| /// CHECK: The address check is needed because otherwise | ||
| /// the supplied Sysvar could be anything else. | ||
| #[account(address = IX_ID)] | ||
| pub ix_sysvar: AccountInfo<'info>, | ||
| } | ||
|
|
||
| pub fn add_validator_sig(ctx: Context<AddValidatorSig>) -> Result<()> { | ||
| let intent = &mut ctx.accounts.intent; | ||
|
|
||
| // Get Ed25519 instruction | ||
| let ed25519_ix: Instruction = get_instruction_relative(-1, &ctx.accounts.ix_sysvar)?; | ||
| let ed25519_ix_args: Ed25519Args = get_args_from_ed25519_ix_data(&ed25519_ix.data)?; | ||
|
|
||
| // Verify correct program and accounts | ||
| check_ed25519_ix(&ed25519_ix)?; | ||
|
|
||
| // Verify correct message was signed | ||
| require!( | ||
| ed25519_ix_args.msg == intent.hash, | ||
| SettlerError::SigVerificationFailed | ||
| ); | ||
|
|
||
| // Verify pubkey is a whitelisted Validator | ||
| require_keys_eq!( | ||
| ctx.accounts.validator_registry.entity_pubkey, | ||
| Pubkey::new_from_array(*ed25519_ix_args.pubkey), | ||
| SettlerError::ValidatorNotAllowlisted, | ||
| ); | ||
|
|
||
| // Updates intent PDA if signature not present and min_validations not met | ||
|
|
||
| if intent.validators.len() == intent.min_validations as usize { | ||
PedroAraoz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return Ok(()); | ||
| } | ||
|
|
||
| let ed25519_pubkey = Pubkey::try_from_slice(ed25519_ix_args.pubkey)?; | ||
|
|
||
| if intent.validators.contains(&ed25519_pubkey) { | ||
| return Ok(()); | ||
| } | ||
|
|
||
| intent.validators.push(ed25519_pubkey); | ||
|
|
||
| Ok(()) | ||
| } | ||
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
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
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,3 +1,5 @@ | ||
| pub mod math; | ||
| pub mod sigs; | ||
|
|
||
| pub use math::*; | ||
| pub use sigs::*; |
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 |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| use anchor_lang::prelude::{instruction::Instruction, *}; | ||
|
|
||
| use crate::errors::SettlerError; | ||
|
|
||
| pub fn check_ed25519_ix(ix: &Instruction) -> Result<()> { | ||
| if ix.program_id.to_string() != "Ed25519SigVerify111111111111111111111111111" | ||
| || ix.accounts.len() != 0 | ||
| { | ||
| return err!(SettlerError::SigVerificationFailed); | ||
| } | ||
|
|
||
| Ok(()) | ||
| } | ||
|
|
||
| pub struct Ed25519Args<'a> { | ||
| pub pubkey: &'a [u8; 32], | ||
| pub sig: &'a [u8; 64], | ||
| pub msg: &'a [u8], | ||
| } | ||
|
|
||
| pub fn get_args_from_ed25519_ix_data(data: &[u8]) -> Result<Ed25519Args<'_>> { | ||
| if data.len() < 112 { | ||
| return err!(SettlerError::SigVerificationFailed); | ||
| } | ||
|
|
||
| // Header | ||
| let num_signatures = &[data[0]]; | ||
| let padding = &[data[1]]; | ||
| let signature_offset = &data[2..=3]; | ||
| let signature_instruction_index = &data[4..=5]; | ||
| let public_key_offset = &data[6..=7]; | ||
| let public_key_instruction_index = &data[8..=9]; | ||
| let message_data_offset = &data[10..=11]; | ||
| let message_data_size = &data[12..=13]; | ||
| let message_instruction_index = &data[14..=15]; | ||
|
|
||
| // Data | ||
| let pubkey = &data[16..16 + 32]; | ||
| let sig = &data[48..48 + 64]; | ||
| let msg = &data[112..]; | ||
|
|
||
| // Expected values | ||
| let exp_public_key_offset: u16 = 16; // 2*u8 + 7*u16 | ||
| let exp_signature_offset: u16 = exp_public_key_offset + 32_u16; | ||
| let exp_message_data_offset: u16 = exp_signature_offset + 64_u16; | ||
| let exp_num_signatures: u8 = 1; | ||
| let exp_message_data_size: u16 = msg | ||
| .len() | ||
| .try_into() | ||
| .map_err(|_| SettlerError::SigVerificationFailed)?; | ||
|
|
||
| // Header | ||
| if num_signatures != &exp_num_signatures.to_le_bytes() | ||
| || padding != &[0] | ||
| || signature_offset != &exp_signature_offset.to_le_bytes() | ||
| || signature_instruction_index != &u16::MAX.to_le_bytes() | ||
| || public_key_offset != &exp_public_key_offset.to_le_bytes() | ||
| || public_key_instruction_index != &u16::MAX.to_le_bytes() | ||
| || message_data_offset != &exp_message_data_offset.to_le_bytes() | ||
| || message_data_size != &exp_message_data_size.to_le_bytes() | ||
| || message_instruction_index != &u16::MAX.to_le_bytes() | ||
| { | ||
| return err!(SettlerError::SigVerificationFailed); | ||
| } | ||
|
|
||
| Ok(Ed25519Args { | ||
| pubkey: pubkey | ||
| .try_into() | ||
| .map_err(|_| SettlerError::SigVerificationFailed)?, | ||
| sig: sig | ||
| .try_into() | ||
| .map_err(|_| SettlerError::SigVerificationFailed)?, | ||
| msg, | ||
| }) | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.