I'm trying to call some of the new precompiled contract (ecmul
) from a pure
function but it fails with:
browser/ballot.sol:11:23: TypeError: Function declared as pure, but this expression (potentially) modifies the state and thus requires non-payable (the default) or payable.
if iszero(call(not(0), 0x07, 0, input, 0x60, p, 0x40)) {
^--^
This is the sample contract (requires solc 0.4.19):
pragma solidity ^0.4.19;
contract Ballot {
function ecmul(uint256 x, uint256 y, uint256 scalar) public pure returns (uint256[2] p) {
// With a public key (x, y), this computes p = scalar * (x, y).
uint256[3] memory input;
input[0] = x;
input[1] = y;
input[2] = scalar;
assembly {
// call ecmul precompile
if iszero(call(not(0), 0x07, 0, input, 0x60, p, 0x40)) {
revert(0, 0)
}
}
}
}
Taken from the article precompiles & solidity.
If I declare the function as view
it will work but seems as unnecessary since it is a precompiled contract it should not modify the storage of any contract.
view
seems unnecessary, are there any other specific reasons you want to usepure
instead ofview
?view
forces me to modify all functions that useecmul
to be declared asview
, and this forces any function that calls one of those to also be declared asview
.