Skip to content

Instantly share code, notes, and snippets.

@roshanrags
Created October 23, 2024 10:08
Show Gist options
  • Save roshanrags/8d79dd282f71e76e613cbf4e0093f6cc to your computer and use it in GitHub Desktop.
Save roshanrags/8d79dd282f71e76e613cbf4e0093f6cc to your computer and use it in GitHub Desktop.
ICICLE bug repro
#include <icicle/api/bn254.h>
#include <icicle/backend/msm_config.h>
#include <icicle/device.h>
#include <icicle/errors.h>
#include <icicle/msm.h>
#include <icicle/runtime.h>
#include <filesystem>
#include <fstream>
std::vector<char> read_file(const char *filename) {
std::ifstream file(filename, std::ios::binary);
const auto file_size = std::filesystem::file_size(filename);
std::vector<char> bytes(file_size);
file.read(bytes.data(), file_size);
return bytes;
}
int main() {
eIcicleError result = icicle_load_backend_from_env_or_default();
if (result != eIcicleError::SUCCESS) {
std::cout << "backend load failed" << std::endl;
return -1;
}
// NOTE: toggle here
// icicle::Device device = "CPU";
icicle::Device device = {"CUDA", 0};
result = icicle_set_device(device);
if (result != eIcicleError::SUCCESS) {
std::cout << "device set failed" << std::endl;
return -1;
}
auto scalars = read_file("./scalars");
auto points = read_file("./points");
MSMConfig config = default_msm_config();
config.are_scalars_montgomery_form = true;
config.are_points_montgomery_form = false;
ConfigExtension ext;
ext.set(CudaBackendConfig::CUDA_MSM_NOF_CHUNKS, 1);
config.ext = &ext;
bn254::projective_t msm_result;
result =
msm((bn254::scalar_t *)scalars.data(), (bn254::affine_t *)points.data(),
scalars.size() / sizeof(bn254::scalar_t), config, &msm_result);
if (result != eIcicleError::SUCCESS) {
std::cout << "msm failed" << std::endl;
return -1;
}
bn254::affine_t apoint;
bn254_to_affine(&msm_result, &apoint);
std::cout << msm_result << std::endl;
std::cout << apoint << std::endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment