Smart contract safety, programming languages, formal verification and related topics
function add(G1Point p1, G1Point p2) internal returns (G1Point r) {
uint[4] memory input;
input[0] = p1.X;
input[1] = p1.Y;
input[2] = p2.X;
input[3] = p2.Y;
bool success;
assembly {
success := call(sub(gas, 2000), 6, 0, input, 0xc0, r, 0x60)
// Use "invalid" to make gas estimation work
switch success case 0 { invalid }
}
require(success);
}
It might be that you run into Out-of-Gas for sha256, ripemd160 or ecrecover on a private blockchain. The reason for this is that those are implemented as so-called precompiled contracts and these contracts only really exist after they received the first message (although their contract code is hardcoded). Messages to non-existing contracts are more expensive and thus the execution runs into an Out-of-Gas error. A workaround for this problem is to first send e.g. 1 Wei to each of the contracts before you use them in your actual contracts. This is not an issue on the official or test net.
Hello, can anybody here help with libsnark (is there another place where I could ask?)? What I want to do is make a circuit which verifies the knowledge of the preimage of a sha256 hash, and then verify the proof for that on Ethereum. I took this from libsnark
https://github.com/scipr-lab/libsnark/blob/f7c87b88744ecfd008126d415494d9b34c4c1b20/libsnark/gadgetlib1/gadgets/hashes/sha256/tests/test_sha256_gadget.cpp
and tried to adapt it to match the structure of the examples in Christian Lundkvist's libsnark-tutorial. The result is this:
mariogemoll/libsnark-tutorial@d6cb832
The C++ code seems to be halfway right, the verification works and when I change any of the inputs it (correctly) fails. However this is the output:
Number of R1CS constraints: 27280
Primary (public) input: 1
1
Auxiliary (private) input: 25559
1
1
0
1
... many numbers ...
2567855114
3460354877
185690065
0
1
1
1
0
1
0
1
Verification status: 1
I think the public input is wrong. What do I need to do to hook up the gadget correctly? Also the Ethereum test fails; I guess I need to convert the input somehow? Any help would be very much appreciated!