Skip to content

feat: charge fee for signature verification - #1651

Closed
markin-io wants to merge 5 commits into
v1.0-devfrom
feat/charge-fee-for-signature-verification
Closed

feat: charge fee for signature verification#1651
markin-io wants to merge 5 commits into
v1.0-devfrom
feat/charge-fee-for-signature-verification

Conversation

@markin-io

@markin-io markin-io commented Dec 28, 2023

Copy link
Copy Markdown
Contributor

Issue being fixed or feature implemented

Feature implements fee charging for signature verification in state transitions.

What was done?

Added validation operations for every state transitions:

How Has This Been Tested?

  • CI

Breaking Changes

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated relevant unit/integration/functional/e2e tests
  • I have added "!" to the title and described breaking changes in the corresponding section if my code contains any
  • I have made corresponding changes to the documentation if needed

For repository code-owners and collaborators only

  • I have assigned this pull request to a milestone

ExecutionEvent::PaidFromAssetLockDriveEvent {
identity,
operations,
signature_verifications,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

No, this should be something like "validation_costs"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed. Renamed to validation_operations

// Apply signature verification costs
if let Some(signature_verifications) = signature_verifications {
let total_verification_cost: Credits =
signature_verifications.iter().fold(0, |acc, op| {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

you need to handle errors, I don't think fold is right.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed

identity: PartialIdentity,
/// the operations that the identity is requesting to perform
operations: Vec<DriveOperation<'a>>,
signature_verifications: Option<Vec<SignatureVerificationOperation>>,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

validation_costs

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

They should not be an Option.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This should contain a vec of validation Operations, which should be an enum

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed

identity: Option<&PartialIdentity>,
) -> Option<Vec<SignatureVerificationOperation>> {
match state_transition {
StateTransition::IdentityCreate(state_transition) => Some(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

There's also an hashed ecdsa verification

let key = identity
.loaded_public_keys
.get(&state_transition.signature_public_key_id())
.unwrap();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

don't unwrap in production code.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Do we really need to introduce Result to this function?
We are expecting signer identity to posses signature_public_key_id. If it doesn't, then something radically wrong is happening.

let key = identity
.loaded_public_keys
.get(&state_transition.signature_public_key_id().unwrap())
.unwrap();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

don't unwrap in production

@markin-io
markin-io marked this pull request as ready for review January 3, 2024 17:48
@markin-io markin-io added this to the v1.0.0 milestone Jan 3, 2024
for validation_operation in validation_operations {
let cost = validation_operation.processing_cost(platform_version)?;
individual_fee_result
.checked_add_assign(FeeResult::default_with_fees(0, cost))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Not ideal to do it this way as checked_add_assign is more much expensive than adding, imo it would be best to add all costs for processing, then only do 1 checked_add_assign.

pub trait OperationLike {
fn processing_cost(&self, platform_version: &PlatformVersion) -> Result<Credits, Error>;

fn storage_cost(&self, platform_version: &PlatformVersion) -> Result<Credits, Error>;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't think a validation operation would ever have a storage_cost.

let key = identity
.loaded_public_keys
.get(&state_transition.signature_public_key_id())
.unwrap();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Don't unwrap here, have the function return an error.

StateTransition::IdentityUpdate(state_transition) => {
let mut operations = vec![];

let identity = identity.unwrap();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Don't unwrap here.

let key = identity
.loaded_public_keys
.get(&state_transition.signature_public_key_id().unwrap())
.unwrap();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Don't unwrap here.

pub fn signature_verification_operations_from_state_transition(
state_transition: &StateTransition,
identity: Option<&PartialIdentity>,
) -> Vec<ValidationOperation> {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I believe the better approach is to get the operations from the execution context.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Also this was not versioned

@shumkov

shumkov commented Jan 4, 2024

Copy link
Copy Markdown
Collaborator

Closed in favor of #1656

@shumkov shumkov closed this Jan 4, 2024
@shumkov
shumkov deleted the feat/charge-fee-for-signature-verification branch January 4, 2024 09:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants