I want to calculate the average of the Millionaires based on this article. https://blog.enigma.co/getting-started-with-the-enigma-protocol-a-complete-developers-guide-170b7dfa5c0f
And this is my code.
// CALLABLE FUNCTION to calculate the average assets
function computeAverage(address[] _addresses, uint[] _netWorths)
public
pure
returns (uint)
{
uint average;
uint sum = 0;
for (uint i = 0; i < _netWorths.length; i++) {
sum += _netWorths[i];
}
average = sum / _netWorths.length;
return average;
}
// CALLBACK FUNCTION to change contract state
function averageAssets(uint _uint) public onlyEnigma() {
averageAssetsResult = _uint;
emit CallbackFinished();
}
This average becomes some big number like 52576064 (when the actual number is 125), 52573696 (when the actual number is 100).
I think this is natural because in secret contract we need to hide the actual number. Is there some built-in average function?
computeAverage
? I see nothing obviously wrong._addresses
and_netWorths
, encrypted? On the page that you cited they use the functiongetEncryptedValue(value)
to encrypt any unencrypted input.handleSubmit()
in the example? Did you try the original example and did it return therichestAddress
correctly?