` // SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract ImageShareCommitments {
uint256 public g;
uint256 public h;
uint256 public p;
uint256 public check;
constructor() {
// Generating random numbers
uint256 randomSeed = uint256(keccak256(abi.encodePacked(block.timestamp, block.basefee, msg.sender)));
g = (randomSeed % 49) + 1; // Random between 1 and 50
h = (randomSeed % 49) + 3; // Random between 1 and 50
// Assigning a prime number
p = 17;
}
struct Commitment {
uint256 commitmentValue;
// uint256 timestamp;
}
mapping(uint256 => Commitment) public commitments;
function calculate(uint256 index, uint256 shares, uint256 xValue) public{
uint256 g_fx = calculateModularExp(g, shares, p);
uint256 h_x = calculateModularExp(h, xValue, p);
check = (g_fx * h_x) % p;
commitments[index] = Commitment(check);
//return commitments[index].commitmentValue;
}
function verifyShare(uint256 share, uint256 xValue, uint256 index) public view returns (bool) {
// Commitment memory storedCommitment = commitments[index];
uint256 g_fx = calculateModularExp(g, share, p);
uint256 h_x = calculateModularExp(h, xValue, p);
uint256 calculatedValue = (g_fx * h_x) % p;
if(calculatedValue != commitments[index].commitmentValue){
return false;
}
return true;
}
function calculateModularExp(uint256 base, uint256 exp, uint256 modulus) public pure returns (uint256) {
base = base % modulus; // Ensure base is within the modulus range
uint256 result = 1;
while (exp > 0) {
if (exp % 2 == 1) { // Current exponent bit is 1
result = (result * base) % modulus;
}
exp = exp >> 1; // Shift exponent to the right
base = (base * base) % modulus;
}
return result;
}
function findPrime() public pure returns (uint256) {
uint256 num = 2;
while (true) {
if (isPrime(num)) {
return num;
}
num++;
}
return 0; // Default return if no prime is found (indicates an issue)
}
function isPrime(uint256 num) public pure returns (bool) {
if (num <= 1) {
return false;
}
for (uint256 i = 2; i * i <= num; i++) {
if (num % i == 0) {
return false;
}
}
return true;
}
function q8() public view returns (bool) {
calculate
(1, 557509, 8);
return verifyShare(557509, 8, 1);
}
} `
In the remix IDE, I have the problem that I have to give all the inputs for the calculate and verifyshare functions manually, in the deploy window which takes quite a lot of time. I want to be able to run the q8 function directly, as all the required parameters for calculate and verifyshare are already mentioned in the function. So, basically I want to be able to press the q8 function button and directly get the true/false answer I need.