Created
October 22, 2024 08:23
-
-
Save roshanrags/6456e1ba99c8a218ad591cdad9acb371 to your computer and use it in GitHub Desktop.
ICICLE bug repro
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <icicle/api/bn254.h> | |
// FIXME: This uses std::string but does not import | |
#include <icicle/device.h> | |
#include <icicle/errors.h> | |
#include <icicle/msm.h> | |
#include <icicle/runtime.h> | |
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; | |
} | |
// big endian scalar: | |
// 0x0ff916bf4e3a6153e2c411e63d933f9420ed9e3c57be5e977630a706c8297c29 | |
// montgomery: | |
// 0x341f438a9e031c5c1932bdf48ee7961d53bd3371ec6904da947ae296d9a2e9eb | |
bn254::scalar_t scalar; | |
scalar.limbs_storage.limbs64[3] = 0x0ff916bf4e3a6153; | |
scalar.limbs_storage.limbs64[2] = 0xe2c411e63d933f94; | |
scalar.limbs_storage.limbs64[1] = 0x20ed9e3c57be5e97; | |
scalar.limbs_storage.limbs64[0] = 0x7630a706c8297c29; | |
// point is 1,2 | |
bn254::affine_t point; | |
point.x.limbs_storage.limbs64[3] = 0; | |
point.x.limbs_storage.limbs64[2] = 0; | |
point.x.limbs_storage.limbs64[1] = 0; | |
point.x.limbs_storage.limbs64[0] = 1; | |
point.y.limbs_storage.limbs64[3] = 0; | |
point.y.limbs_storage.limbs64[2] = 0; | |
point.y.limbs_storage.limbs64[1] = 0; | |
point.y.limbs_storage.limbs64[0] = 2; | |
MSMConfig config = default_msm_config(); | |
config.are_scalars_montgomery_form = false; | |
config.are_points_montgomery_form = false; | |
bn254::projective_t msm_result; | |
result = msm(&scalar, &point, 1, 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