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

feat(app): Add starknet gen pubkey #614

Merged
merged 26 commits into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
4f4dbc6
feat(app): Add starknet gen pubkey
vrockz747 Dec 11, 2024
bc9dd9c
chore: Add function docs
vrockz747 Dec 12, 2024
5e805ed
chore: Ci fix
vrockz747 Dec 13, 2024
a2f86f8
chore: Refactor starknet ecdsa operations
vrockz747 Dec 17, 2024
83fc294
feat(app): Add sign txn
vrockz747 Dec 12, 2024
d939931
fix(app): Proto options size
vrockz747 Dec 13, 2024
aeef9d9
chore: Add submodules
vrockz747 Dec 14, 2024
1b17339
fix: Sign gen minor bug
vrockz747 Dec 14, 2024
a46aefd
chore: Update submodule
vrockz747 Dec 14, 2024
2590c3c
fix: Relocate starknet init
vrockz747 Dec 16, 2024
fc02c36
chore: Add starknet verify amount
vrockz747 Dec 16, 2024
4cc6484
chore: Update starknet utxn proto
vrockz747 Dec 16, 2024
f8823f3
fix: Verify txn data
vrockz747 Dec 18, 2024
266e827
chore: Update base
vrockz747 Dec 18, 2024
462c196
chore: Complete verification data all txns
vrockz747 Dec 18, 2024
ea3033f
chore: Refactor sign utilities
vrockz747 Dec 18, 2024
bf7396f
chore: Review changes
vrockz747 Dec 23, 2024
9cc6e72
chore: Review changes
vrockz747 Dec 23, 2024
42479e6
Merge branch 'feat/starknet/refactored/base' into feat/starknet/refac…
vrockz747 Dec 23, 2024
f625d0a
chore: Update submodule and review changes
vrockz747 Jan 3, 2025
1bff1dd
chore: Remove dev build ci
vrockz747 Jan 3, 2025
d99c888
chore: Version bump(v0.6.1538++)
vrockz747 Jan 3, 2025
44a4e78
Merge pull request #617 from Cypherock/feat/starknet/refactored/sign-txn
TejasvOnly Jan 8, 2025
41d8d78
fix: Apped zeros when converting mpz to string
TejasvOnly Jan 9, 2025
33ca59f
chore: Version bump (patch++)
TejasvOnly Jan 9, 2025
0eab180
chore: Fix ci
TejasvOnly Jan 9, 2025
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
54 changes: 26 additions & 28 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
branches:
- release**
paths:
- 'version.txt'
- "version.txt"

jobs:
build-firmwares:
Expand All @@ -25,30 +25,28 @@ jobs:
runs-on: ubuntu-latest
if: ${{ github.ref_type }} == 'tag'
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Download artifacts
uses: actions/download-artifact@v3
with:
path: ./
- name: Publish a release
env:
TAG_NAME: ${{ github.ref_name }}
auth_token: ${{ secrets.GITHUB_TOKEN }}
REPOSITORY: ${{ github.repository }}
run: |
chkmain=$(sha256sum Main-Release-outputs/Cypherock-Main.bin | cut -f -1 -d ' ')
chkinit=$(sha256sum Initial-Release-outputs/Cypherock-Initial.bin | cut -f -1 -d ' ')
APP_VERSION=$(cat version.txt | grep firmware | cut -f 2-2 -d '=' | awk -F ':' '{ print 0+$1 "." 0+$2 "." $3*2**8 + $4 }')
HW_VERSION=$(cat version.txt | grep hardware | cut -f 2-2 -d '=' | awk -F ':' '{ print 0+$1 "." 0+$2 "." $3*2**8 + $4 }')
echo ${APP_VERSION}:${HW_VERSION}
curl -X POST -H "Accept: application/vnd.github+json" -H "Authorization: Bearer ${auth_token}" -H "X-GitHub-Api-Version: 2022-11-28" https://api.github.com/repos/${REPOSITORY}/releases -d '{"tag_name":"'${TAG_NAME}'","target_commitish":"main","name":"'${TAG_NAME}'","body":"Application version: '${APP_VERSION}'\r\nHardware version: '${HW_VERSION}'\r\n## SHA256 of binaries:\r\n**Cypherock-Initial.bin** : '${chkinit}' \r\n**Cypherock-Main.bin** : '${chkmain}'","draft":true,"prerelease":false,"generate_release_notes":true}' > output.txt
echo "upload_url=$(cat output.txt | grep "\"upload_url\":" | cut -f 4-4 -d '"' | cut -f 1-1 -d '{')" >> $GITHUB_ENV
- name: Upload assets
env:
auth_token: ${{ secrets.GITHUB_TOKEN }}
run: |
content_type=$(file -b --mime-type Main-Release-outputs/Cypherock-Main.bin)
curl -X POST -H "Content-Type: ${content_type}" -H "Accept: application/vnd.github+json" -H "Authorization: Bearer ${auth_token}" -H "X-GitHub-Api-Version: 2022-11-28" ${upload_url}?name=Cypherock-Main.bin --data-binary @Main-Release-outputs/Cypherock-Main.bin
curl -X POST -H "Content-Type: ${content_type}" -H "Accept: application/vnd.github+json" -H "Authorization: Bearer ${auth_token}" -H "X-GitHub-Api-Version: 2022-11-28" ${upload_url}?name=Cypherock-Initial.bin --data-binary @Initial-Release-outputs/Cypherock-Initial.bin
curl -X POST -H "Content-Type: ${content_type}" -H "Accept: application/vnd.github+json" -H "Authorization: Bearer ${auth_token}" -H "X-GitHub-Api-Version: 2022-11-28" ${upload_url}?name=version.txt --data-binary @version.txt
- name: Checkout
uses: actions/checkout@v3
- name: Download artifacts
uses: actions/download-artifact@v3
with:
path: ./
- name: Publish a release
env:
TAG_NAME: ${{ github.ref_name }}
auth_token: ${{ secrets.GITHUB_TOKEN }}
REPOSITORY: ${{ github.repository }}
run: |
chkmain=$(sha256sum Main-Release-outputs/Cypherock-Main.bin | cut -f -1 -d ' ')
APP_VERSION=$(cat version.txt | grep firmware | cut -f 2-2 -d '=' | awk -F ':' '{ print 0+$1 "." 0+$2 "." $3*2**8 + $4 }')
HW_VERSION=$(cat version.txt | grep hardware | cut -f 2-2 -d '=' | awk -F ':' '{ print 0+$1 "." 0+$2 "." $3*2**8 + $4 }')
echo ${APP_VERSION}:${HW_VERSION}
curl -X POST -H "Accept: application/vnd.github+json" -H "Authorization: Bearer ${auth_token}" -H "X-GitHub-Api-Version: 2022-11-28" https://api.github.com/repos/${REPOSITORY}/releases -d '{"tag_name":"'${TAG_NAME}'","target_commitish":"main","name":"'${TAG_NAME}'","body":"Application version: '${APP_VERSION}'\r\nHardware version: '${HW_VERSION}'\r\n## SHA256 of binaries:\r\n**Cypherock-Main.bin** : '${chkmain}'","draft":true,"prerelease":false,"generate_release_notes":true}' > output.txt
echo "upload_url=$(cat output.txt | grep "\"upload_url\":" | cut -f 4-4 -d '"' | cut -f 1-1 -d '{')" >> $GITHUB_ENV
- name: Upload assets
env:
auth_token: ${{ secrets.GITHUB_TOKEN }}
run: |
content_type=$(file -b --mime-type Main-Release-outputs/Cypherock-Main.bin)
curl -X POST -H "Content-Type: ${content_type}" -H "Accept: application/vnd.github+json" -H "Authorization: Bearer ${auth_token}" -H "X-GitHub-Api-Version: 2022-11-28" ${upload_url}?name=Cypherock-Main.bin --data-binary @Main-Release-outputs/Cypherock-Main.bin
curl -X POST -H "Content-Type: ${content_type}" -H "Accept: application/vnd.github+json" -H "Authorization: Bearer ${auth_token}" -H "X-GitHub-Api-Version: 2022-11-28" ${upload_url}?name=version.txt --data-binary @version.txt
2 changes: 1 addition & 1 deletion .github/workflows/ci-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ jobs:
fail-fast: false
matrix:
firmware: [main]
target: [release, dev]
target: [release]
platform: [device, simulator]
runs-on: ubuntu-latest

Expand Down
6 changes: 6 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,9 @@
[submodule "nanopb"]
path = vendor/nanopb
url = ../nanopb
[submodule "mini-gmp"]
path = vendor/mini-gmp
url = ../mini-gmp
[submodule "poseidon"]
path = vendor/poseidon
url = ../poseidon
5 changes: 4 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ include(utilities/cmake/version.cmake)
file(GLOB_RECURSE PROTO_SRCS "generated/proto/*.*")
list(APPEND PROTO_SRCS "vendor/nanopb/pb_common.c" "vendor/nanopb/pb_decode.c" "vendor/nanopb/pb_encode.c" "vendor/nanopb/pb_common.h" "vendor/nanopb/pb_decode.h" "vendor/nanopb/pb_encode.h" "vendor/nanopb/pb.h")

list (APPEND MINI_GMP_SRCS "vendor/mini-gmp/mini-gmp-helpers.c" "vendor/mini-gmp/mini-gmp.c")
list (APPEND POSEIDON_SRCS "vendor/poseidon/sources/f251.c" "vendor/poseidon/sources/poseidon.c" "vendor/poseidon/sources/poseidon_rc.c")

OPTION(DEV_SWITCH "Additional features/logs to aid developers" OFF)
OPTION(UNIT_TESTS_SWITCH "Compile build for main firmware or unit tests" OFF)

Expand All @@ -49,7 +52,7 @@ else()
endif()

# Include nanopb source headers
target_include_directories( ${EXECUTABLE} PRIVATE vendor/nanopb generated/proto )
target_include_directories( ${EXECUTABLE} PRIVATE vendor/nanopb generated/proto vendor/mini-gmp vendor/poseidon/sources)

# Enable support for dynamically allocated fields in nanopb
# Ref: vendor/nanopb/pb.h
Expand Down
113 changes: 113 additions & 0 deletions apps/starknet_app/starkcurve.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
/**
* @file starkcurve.h
* @author Cypherock X1 Team
* @brief Constants for Starknet curve.
* @copyright Copyright (c) 2023 HODL TECH PTE LTD
* <br/> You may obtain a copy of license at <a href="https://mitcc.org/"
*target=_blank>https://mitcc.org/</a>
*
******************************************************************************
* @attention
*
* (c) Copyright 2023 by HODL TECH PTE LTD
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject
* to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*
* "Commons Clause" License Condition v1.0
*
* The Software is provided to you by the Licensor under the License,
* as defined below, subject to the following condition.
*
* Without limiting other conditions in the License, the grant of
* rights under the License will not include, and the License does not
* grant to you, the right to Sell the Software.
*
* For purposes of the foregoing, "Sell" means practicing any or all
* of the rights granted to you under the License to provide to third
* parties, for a fee or other consideration (including without
* limitation fees for hosting or consulting/ support services related
* to the Software), a product or service whose value derives, entirely
* or substantially, from the functionality of the Software. Any license
* notice or attribution required by the License must also include
* this Commons Clause License Condition notice.
*
* Software: All X1Wallet associated files.
* License: MIT
* Licensor: HODL TECH PTE LTD
*
******************************************************************************
*/

/*****************************************************************************
* INCLUDES
*****************************************************************************/

/*****************************************************************************
* EXTERN VARIABLES
*****************************************************************************/

/*****************************************************************************
* MACROS AND DEFINES
*****************************************************************************/
#define SIZE_HEX 16

// Starknet curve constants
#define STARKNET_CURVE_PRIME \
"0800000000000011000000000000000000000000000000000000000000000001"
#define STARKNET_CURVE_GX \
"01EF15C18599971B7BECED415A40F0C7DEACFD9B0D1819E03D723D8BC943CFCA"
#define STARKNET_CURVE_GY \
"005668060AA49730B7BE4801DF46EC62DE53ECD11ABE43A32873000C36E8DC1F"
#define STARKNET_CURVE_ORDER \
"0800000000000010ffffffffffffffffb781126dcae7b2321e66a241adc64d2f"
#define STARKNET_CURVE_ORDER_HALF \
"04000000000000087fffffffffffffffdbc08936e573d9190f335120d6e32697"
#define STARKNET_CURVE_A \
"0000000000000000000000000000000000000000000000000000000000000001"
#define STARKNET_CURVE_B \
"06f21413efbe40de150e596d72f7a8c5609ad26c15c915c1f4cdfcb99cee9e89"

// starknet pedersen points
// Ref: https://docs.starkware.co/starkex/crypto/pedersen-hash-function.html
#define STARKNET_PEDERSEN_POINT_0_X \
"049EE3EBA8C1600700EE1B87EB599F16716B0B1022947733551FDE4050CA6804"
#define STARKNET_PEDERSEN_POINT_0_Y \
"03CA0CFE4B3BC6DDF346D49D06EA0ED34E621062C0E056C1D0405D266E10268A"
#define STARKNET_PEDERSEN_POINT_1_X \
"0234287DCBAFFE7F969C748655FCA9E58FA8120B6D56EB0C1080D17957EBE47B"
#define STARKNET_PEDERSEN_POINT_1_Y \
"03B056F100F96FB21E889527D41F4E39940135DD7A6C94CC6ED0268EE89E5615"
#define STARKNET_PEDERSEN_POINT_2_X \
"04FA56F376C83DB33F9DAB2656558F3399099EC1DE5E3018B7A6932DBA8AA378"
#define STARKNET_PEDERSEN_POINT_2_Y \
"03FA0984C931C9E38113E0C0E47E4401562761F92A7A23B45168F4E80FF5B54D"
#define STARKNET_PEDERSEN_POINT_3_X \
"04BA4CC166BE8DEC764910F75B45F74B40C690C74709E90F3AA372F0BD2D6997"
#define STARKNET_PEDERSEN_POINT_3_Y \
"040301CF5C1751F4B971E46C4EDE85FCAC5C59A5CE5AE7C48151F27B24B219C"
#define STARKNET_PEDERSEN_POINT_4_X \
"054302DCB0E6CC1C6E44CCA8F61A63BB2CA65048D53FB325D36FF12C49A58202"
#define STARKNET_PEDERSEN_POINT_4_Y \
"01B77B3E37D13504B348046268D8AE25CE98AD783C25561A879DCC77E99C2426"

// starknet limit
#define STARKNET_LIMIT \
"F80000000000020EFFFFFFFFFFFFFFF738A13B4B920E9411AE6DA5F40B0358B1"
Loading
Loading