Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion .github/workflows/clang-linux-nix-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
jobs:
build-and-test:
name: "Build and test Linux with clang"
runs-on: [self-hosted, Linux, X64, aws_autoscaling]
runs-on: [self-hosted, Linux, X64]
steps:
# https://github.com/actions/checkout/issues/1552
- name: Clean up after previous checkout
Expand Down
26 changes: 13 additions & 13 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ concurrency:
cancel-in-progress: true

jobs:
test-linux-gcc:
name: Gcc release full Linux testing
uses: ./.github/workflows/gcc-linux-nix-check.yml
if: |
always() && !cancelled()
secrets: inherit
# test-linux-gcc:
# name: Gcc release full Linux testing
# uses: ./.github/workflows/gcc-linux-nix-check.yml
# if: |
# always() && !cancelled()
# secrets: inherit

test-linux-clang:
name: Clang release full Linux testing
Expand All @@ -45,10 +45,10 @@ jobs:
always() && !cancelled()
secrets: inherit

build-linux-proof-producer-deb-package:
name: Build and upload deb package
uses: ./.github/workflows/deb-package-proof-producer-bundler.yaml
if: |
always() && !cancelled()
# TODO add if it's a merge to master
secrets: inherit
# build-linux-proof-producer-deb-package:
# name: Build and upload deb package
# uses: ./.github/workflows/deb-package-proof-producer-bundler.yaml
# if: |
# always() && !cancelled()
# # TODO add if it's a merge to master
# secrets: inherit
2 changes: 1 addition & 1 deletion .github/workflows/verify-hardhat-proofs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
jobs:
build-and-test:
name: "Verify hardhat proofs"
runs-on: [self-hosted, Linux, X64, aws_autoscaling]
runs-on: [self-hosted, Linux, X64]
steps:
# https://github.com/actions/checkout/issues/1552
- name: Clean up after previous checkout
Expand Down
180 changes: 180 additions & 0 deletions crypto3/libs/algebra/include/nil/crypto3/algebra/matrix/dmatrix.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@

//---------------------------------------------------------------------------//
// Copyright (c) 2025 Elena Tatuzova <elena@allocinit.xyz>
//
// MIT License
//
// 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.
//---------------------------------------------------------------------------//

#pragma once

#include <array>
#include <vector>
#include <tuple>
#include <execution>

#include <nil/crypto3/algebra/vector/utility.hpp>
#include <nil/crypto3/algebra/vector/dvector.hpp>

/** Dynamic size matrix class */

namespace nil::crypto3::algebra {
/** @brief A container representing a matrix
* @tparam T scalar type to contain
*
* `dmatrix` is a container representing a matrix.
*/
template<typename T>
class dmatrix: public dvector<dvector<T>> {
public:
using value_type = T;
using size_type = std::size_t;
using row_type = dvector<T>;
using data_type = dvector<dvector<T>>;

size_type column_size; ///< Number of rows
size_type row_size; ///< Number of columns

// Constructor
dmatrix(size_type N, size_type M) : column_size(N), row_size(M), dvector<dvector<T>>(N, dvector<T>(M)) {}

// Constructor with initialization
dmatrix(std::size_t N, std::size_t M, const data_type &init_data)
: column_size(N), row_size(M), dvector<dvector<T>>(init_data) {}


dvector<T> row(std::size_t i) const {
dvector<T> result = (*this)[i];
return result;
}

dvector<T> column(std::size_t j) const{
dvector<T> result(column_size);
for (std::size_t i = 0; i < column_size; ++i) {
result[i] = (*this)[i][j];
}
return result;
}

dmatrix<T> operator+(const dmatrix<T> &other) const {
assert (column_size == other.column_size && row_size == other.row_size);
dmatrix<T> result(column_size, row_size, dvector<dvector<T>>::operator+(other));
return result;
}

dmatrix<T> operator-(const dmatrix<T> &other) const {
assert (column_size == other.column_size && row_size == other.row_size);
dmatrix<T> result(column_size, row_size, dvector<dvector<T>>::operator-(other));
return result;
}

dmatrix<T> operator*(const dmatrix<T> &other) const {
assert (row_size == other.column_size);
dmatrix<T> result(column_size, other.row_size);
for (std::size_t i = 0; i < column_size; ++i) {
for (std::size_t j = 0; j < other.row_size; ++j) {
result[i][j] = 0;
for (std::size_t k = 0; k < row_size; ++k) {
result[i][j] += (*this)[i][k] * other[k][j];
}
}
}
return result;
}

T determinant() const {
assert (column_size == row_size);
T det = 1;
if (column_size == 0) return 1;
T sign = 1; // Check!

dvector<dvector<T>> tmp = *this; // Make a copy to perform row operations
for( std::size_t i = 0; i < column_size; i++ ){
// Find pivot
std::size_t pivot = i;
while( pivot < column_size && tmp[pivot][i] == 0 ) pivot++;
if( pivot == column_size ) return 0; // Singular matrix

if( pivot != i ){
std::swap( tmp[i], tmp[pivot] );
sign = -sign;
}

det *= tmp[i][i];
// Eliminate below
for( std::size_t j = i + 1; j < column_size; j++ ){
T factor = tmp[j][i] / tmp[i][i];
for( std::size_t k = i; k < row_size; k++ ){
tmp[j][k] -= factor * tmp[i][k];
}
}

if (sign != 1) det = -det;
}
return det;
}

std::size_t rank() const {
dvector<dvector<T>> tmp = *this; // Make a copy to perform row operations
std::size_t rank = 0;
std::size_t min_size = std::min(column_size, row_size);

for (std::size_t i = 0; i < min_size; ++i) {
// Find pivot
std::size_t pivot = i;
while (pivot < column_size && tmp[pivot][i] == 0) pivot++;
if (pivot == column_size) continue; // No pivot in this column

if (pivot != i) {
std::swap(tmp[i], tmp[pivot]);
}

// Eliminate below
for (std::size_t j = i + 1; j < column_size; ++j) {
T factor = tmp[j][i] / tmp[i][i];
for (std::size_t k = i; k < row_size; ++k) {
tmp[j][k] -= factor * tmp[i][k];
}
}
rank++;
}
return rank;
}
};

template<typename T>
dmatrix<T> identity_dmatrix(std::size_t N) {
dmatrix<T> result(N, N);
for (std::size_t i = 0; i < N; ++i) {
result[i][i] = 1;
}
return result;
}

template<typename T>
dmatrix<T> identity_dmatrix(std::size_t N, std::size_t M) {
dmatrix<T> result(N, M);
std::size_t min_size = std::min(N, M);
for (std::size_t i = 0; i < min_size; ++i) {
result[i][i] = 1;
}
return result;
}
} // namespace nil::crypto3::algebra
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@

//---------------------------------------------------------------------------//
// Copyright (c) 2025 Elena Tatuzova <elena@allocinit.xyz>
//
// MIT License
//
// 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.
//---------------------------------------------------------------------------//

#pragma once

#include <array>
#include <vector>
#include <tuple>
#include <execution>

#include <nil/crypto3/algebra/vector/utility.hpp>
#include <nil/crypto3/algebra/vector/vector.hpp>

/** Dynamic size vector class */

namespace nil::crypto3::algebra {
/** @brief A container representing a matrix
* @tparam T scalar type to contain
*
* `matrix` is a container representing a matrix.
* It is an aggregate type containing a single member array of type
* `T[N][M]` which can be initialized with aggregate initialization.
*/
template<typename T>
class dvector :public std::vector<T> {
public:
using value_type = T;
using size_type = std::size_t;

// Constructor
dvector() : std::vector<T>() {}
dvector(size_type N) : std::vector<T>(N) {}
dvector(size_type N, const T &value) : std::vector<T>(N, value) {}
dvector(std::initializer_list<T> init) : std::vector<T>(init) {}

// Addition operator
dvector<T> operator+(const dvector<T> &other) const {
assert (this->size() == other.size());
dvector<T> result(this->size());
std::transform(
this->begin(), this->end(),
other.begin(),
result.begin(),
[](const T &a, const T &b) { return a + b; }
);
return result;
}

// Subtraction operator
dvector<T> operator-(const dvector<T> &other) const {
assert (this->size() == other.size());
dvector<T> result(this->size());
std::transform(
this->begin(), this->end(),
other.begin(),
result.begin(),
[](const T &a, const T &b) { return a - b; }
);
return result;
}

dvector<T> operator*(const T &scalar) const {
dvector<T> result(this->size());
std::transform(
this->begin(), this->end(),
result.begin(),
[scalar](const T &a) { return a * scalar; }
);
return result;
}
};
} // namespace nil::crypto3::algebra
22 changes: 10 additions & 12 deletions crypto3/libs/algebra/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,18 @@ macro(define_compile_time_algebra_test name)
endmacro()

set(RUNTIME_TESTS_NAMES
"curves"
"short_weierstrass_coordinates"
"curves_static"
"fields"
"fields_static"
"pairing"
"type_traits"
"multiexp"
"curves"
"short_weierstrass_coordinates"
"curves_static"
"fields"
"fields_static"
"pairing"
"type_traits"
"multiexp"
"matrix"
"vector"
)

set(COMPILE_TIME_TESTS_NAMES
"matrix"
"vector")

foreach(TEST_NAME ${RUNTIME_TESTS_NAMES})
define_runtime_algebra_test(${TEST_NAME})
endforeach()
Expand Down
Loading
Loading