Skip to content
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

Conway cert builder support #270

Merged
merged 4 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 48 additions & 31 deletions chain/rust/src/builders/certificate_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,15 @@ pub enum CertBuilderError {
// comes from witsVKeyNeeded in the Ledger spec
pub fn cert_required_wits(cert: &Certificate, required_witnesses: &mut RequiredWitnessSet) {
match cert {
// stake key registrations do not require a witness
Certificate::StakeRegistration(_cert) => (),
Certificate::StakeDeregistration(cert) => match &cert.stake_credential {
StakeCredential::Script { hash, .. } => {
required_witnesses.add_script_hash(hash.clone());
}
StakeCredential::PubKey { hash, .. } => {
required_witnesses.add_vkey_key_hash(hash.clone());
}
},
Certificate::StakeDelegation(cert) => match &cert.stake_credential {
StakeCredential::Script { hash, .. } => {
required_witnesses.add_script_hash(hash.clone());
}
StakeCredential::PubKey { hash, .. } => {
required_witnesses.add_vkey_key_hash(hash.clone());
}
},
Certificate::StakeRegistration(_cert) => {
// stake key registrations do not require a witness
}
Certificate::StakeDeregistration(cert) => {
required_witnesses.add_from_credential(cert.stake_credential.clone());
}
Certificate::StakeDelegation(cert) => {
required_witnesses.add_from_credential(cert.stake_credential.clone());
}
Certificate::PoolRegistration(cert) => {
for owner in &cert.pool_params.pool_owners {
required_witnesses.add_vkey_key_hash(owner.clone());
Expand All @@ -52,18 +43,42 @@ pub fn cert_required_wits(cert: &Certificate, required_witnesses: &mut RequiredW
Certificate::PoolRetirement(cert) => {
required_witnesses.add_vkey_key_hash(cert.ed25519_key_hash.clone());
}
Certificate::RegCert(_cert) => todo!(),
Certificate::UnregCert(_cert) => todo!(),
Certificate::VoteDelegCert(_cert) => todo!(),
Certificate::StakeVoteDelegCert(_cert) => todo!(),
Certificate::StakeRegDelegCert(_cert) => todo!(),
Certificate::VoteRegDelegCert(_cert) => todo!(),
Certificate::StakeVoteRegDelegCert(_cert) => todo!(),
Certificate::AuthCommitteeHotCert(_cert) => todo!(),
Certificate::ResignCommitteeColdCert(_cert) => todo!(),
Certificate::RegDrepCert(_cert) => todo!(),
Certificate::UnregDrepCert(_cert) => todo!(),
Certificate::UpdateDrepCert(_cert) => todo!(),
Certificate::RegCert(cert) => {
required_witnesses.add_from_credential(cert.stake_credential.clone());
}
Certificate::UnregCert(cert) => {
required_witnesses.add_from_credential(cert.stake_credential.clone());
}
Certificate::VoteDelegCert(cert) => {
required_witnesses.add_from_credential(cert.stake_credential.clone());
}
Certificate::StakeVoteDelegCert(cert) => {
required_witnesses.add_from_credential(cert.stake_credential.clone());
}
Certificate::StakeRegDelegCert(cert) => {
required_witnesses.add_from_credential(cert.stake_credential.clone());
}
Certificate::VoteRegDelegCert(cert) => {
required_witnesses.add_from_credential(cert.stake_credential.clone());
}
Certificate::StakeVoteRegDelegCert(cert) => {
required_witnesses.add_from_credential(cert.stake_credential.clone());
}
Certificate::AuthCommitteeHotCert(cert) => {
required_witnesses.add_from_credential(cert.committee_cold_credential.clone());
}
Certificate::ResignCommitteeColdCert(cert) => {
required_witnesses.add_from_credential(cert.committee_cold_credential.clone());
}
Certificate::RegDrepCert(_cert) => {
// does not need a witness
}
Certificate::UnregDrepCert(cert) => {
required_witnesses.add_from_credential(cert.drep_credential.clone());
}
Certificate::UpdateDrepCert(cert) => {
required_witnesses.add_from_credential(cert.drep_credential.clone());
}
};
}

Expand Down Expand Up @@ -101,7 +116,9 @@ pub fn add_cert_vkeys(
Certificate::PoolRetirement(cert) => {
vkeys.insert(cert.ed25519_key_hash.clone());
}
Certificate::RegCert(_cert) => todo!(),
Certificate::RegCert(_cert) => {
// does not require a witness
}
Certificate::UnregCert(_cert) => todo!(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why todos?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Forgot to add them here too. The ones in cert_required_wits were all tested so this should be fine since it's based on those and identical except it errors when the wits aren't vkeys. I just pushed a commit that includes these too.

Certificate::VoteDelegCert(_cert) => todo!(),
Certificate::StakeVoteDelegCert(_cert) => todo!(),
Expand Down
8 changes: 8 additions & 0 deletions chain/rust/src/builders/witness_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use std::{

use crate::{
byron::ByronAddress,
certs::Credential,
crypto::{hash::hash_plutus_data, BootstrapWitness, Vkey, Vkeywitness},
plutus::{PlutusData, PlutusScript, PlutusV1Script, PlutusV2Script, Redeemer},
transaction::{RequiredSigners, TransactionWitnessSet},
Expand Down Expand Up @@ -141,6 +142,13 @@ impl RequiredWitnessSet {
}
}

pub(crate) fn add_from_credential(&mut self, credential: Credential) {
match credential {
Credential::PubKey { hash, .. } => self.add_vkey_key_hash(hash),
Credential::Script { hash, .. } => self.add_script_hash(hash),
}
}

// pub fn add_plutus_script(&mut self, plutus_v1_script: &PlutusScript) {
// self.add_script_hash(&plutus_v1_script.hash());
// }
Expand Down
3 changes: 3 additions & 0 deletions chain/rust/src/deposit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ pub fn internal_get_implicit_input(
.try_fold(0u64, |acc, cert| match cert {
Certificate::PoolRetirement(_cert) => acc.checked_add(pool_deposit),
Certificate::StakeDeregistration(_cert) => acc.checked_add(key_deposit),
Certificate::UnregCert(_cert) => acc.checked_add(key_deposit),
_ => Some(acc),
})
.ok_or(ArithmeticError::IntegerOverflow)?,
Expand All @@ -45,6 +46,8 @@ pub fn internal_get_deposit(
.try_fold(0u64, |acc, cert| match cert {
Certificate::PoolRegistration(_cert) => acc.checked_add(pool_deposit),
Certificate::StakeRegistration(_cert) => acc.checked_add(key_deposit),
Certificate::RegCert(_cert) => acc.checked_add(key_deposit),
Certificate::StakeRegDelegCert(_cert) => acc.checked_add(key_deposit),
_ => Some(acc),
})
.ok_or(ArithmeticError::IntegerOverflow)?,
Expand Down
2 changes: 1 addition & 1 deletion chain/rust/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ impl NetworkId {

pub fn testnet() -> Self {
Self {
network: 1,
network: 0,
encoding: None,
}
}
Expand Down