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

Origin transaction should verify existing public key#583 #626

Merged
merged 2 commits into from
Oct 17, 2022
Merged

Origin transaction should verify existing public key#583 #626

merged 2 commits into from
Oct 17, 2022

Conversation

apoorv-2204
Copy link
Contributor

@apoorv-2204 apoorv-2204 commented Oct 12, 2022

Description

/api/origin_key -> Origin endpoint is leveraged to add origin public key and its corresponding certificate, An origin transaction is created, on post request, with content as origin_public_key and certificate, But there are no checks for to ensure that this origin public key has already been included in existing transaction. A check is introduced leveraging the OriginKey store to check if the origin Public key already exists before creating/accepting the transaction.

Checks are done at two different location/Stages:

  • In the origin Api controller, During post call
  • In Pending_transaction_validation.ex in do_accept_tx(:origin), validation of tx

New error logging for both locations api call and during validation is introduced.

##Fixes

Type of change

  • Bug fix
    • Check for existing Origin Public key
  • New feature
    • Check for existing Origin Public key
  • This change requires a documentation update
    • New error reporting if origin public key already exists

How Has This Been Tested?

  • mix dev.lbench regression
  • Running on multiple nodes
  • unit test cases

How to test?

  • key certificate is "" -Crypto.get_key_certificate(public_key)

  • Accepting a Origin tx with no existing origin public key in store

    • Generate pbkey, cert and post an origin api call with base16 encoded public key and certificate

    iex> alias Archethic.Crypto
    iex> alias Archethic.SharedSecrets.MemTable.OriginKeyLookup
    iex> {public_key, _} = Crypto.derive_keypair("has_origin_public_key_Seed", 0)
    iex> certificate = Crypto.get_key_certificate(public_key)
    iex> pb_key = public_key|>Base.encode16
    iex> cert = certificate|>Base.encode16

  • Check tx address in Origin Explorer

  • Rejecting a Origin tx with existing origin public key in store

    • Add the generated origin public key, via api, or method call
      iex>    OriginKeyLookup.add_public_key(:software, public_key)
      
    • Api response will be error - public key exists

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

@apoorv-2204 apoorv-2204 self-assigned this Oct 12, 2022
@apoorv-2204 apoorv-2204 added API Involve API facing user bug Something isn't working origin labels Oct 12, 2022
@apoorv-2204 apoorv-2204 marked this pull request as ready for review October 13, 2022 06:27
@samuelmanzanera
Copy link
Member

A way to test it from the API is to use this command:

curl --request POST \
  --url http://localhost:4000/api/origin_key \
  --header 'Content-Type: application/json' \
  --data '{
	"origin_public_key": "010104AB41291F847A601055AEDD1AF24FF76FA970D6441E2DCA3818A8319B004C96B27B8FEB1DA31A044BA0A4800B4353359735719EBB3A05F98393A9CC599C3FAFD6",
	"certificate": ""
}'

Which is trying to add the default software origin public key

@samuelmanzanera samuelmanzanera merged commit c53853e into archethic-foundation:develop Oct 17, 2022
@apoorv-2204 apoorv-2204 deleted the origin_pbkey_redundancy branch November 2, 2022 14:11
@apoorv-2204 apoorv-2204 restored the origin_pbkey_redundancy branch November 2, 2022 14:11
@apoorv-2204 apoorv-2204 deleted the origin_pbkey_redundancy branch November 11, 2022 07:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Involve API facing user bug Something isn't working origin
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants