mirror of
https://github.com/status-im/codex-contracts-eth.git
synced 2025-02-12 08:26:46 +00:00
Submit proof as field elements, not bytes
This commit is contained in:
parent
534f8cbf51
commit
ae03690d51
@ -100,7 +100,7 @@ contract Marketplace is Proofs, StateRetrieval {
|
|||||||
function fillSlot(
|
function fillSlot(
|
||||||
RequestId requestId,
|
RequestId requestId,
|
||||||
uint256 slotIndex,
|
uint256 slotIndex,
|
||||||
bytes calldata proof
|
uint256[8] calldata proof
|
||||||
) public requestIsKnown(requestId) {
|
) public requestIsKnown(requestId) {
|
||||||
Request storage request = _requests[requestId];
|
Request storage request = _requests[requestId];
|
||||||
require(slotIndex < request.ask.slots, "Invalid slot");
|
require(slotIndex < request.ask.slots, "Invalid slot");
|
||||||
|
@ -108,20 +108,19 @@ abstract contract Proofs is Periods {
|
|||||||
return isRequired && pointer < _config.downtime;
|
return isRequired && pointer < _config.downtime;
|
||||||
}
|
}
|
||||||
|
|
||||||
function submitProof(SlotId id, bytes calldata proof) public {
|
function submitProof(SlotId id, uint256[8] calldata proof) public {
|
||||||
require(!_received[id][_blockPeriod()], "Proof already submitted");
|
require(!_received[id][_blockPeriod()], "Proof already submitted");
|
||||||
require(proof.length == 256, "invalid proof length");
|
|
||||||
uint256[2] memory a;
|
uint256[2] memory a;
|
||||||
uint256[2][2] memory b;
|
uint256[2][2] memory b;
|
||||||
uint256[2] memory c;
|
uint256[2] memory c;
|
||||||
a[0] = uint256(bytes32(proof[0:32]));
|
a[0] = proof[0];
|
||||||
a[1] = uint256(bytes32(proof[32:64]));
|
a[1] = proof[1];
|
||||||
b[0][0] = uint256(bytes32(proof[64:96]));
|
b[0][0] = proof[2];
|
||||||
b[0][1] = uint256(bytes32(proof[96:128]));
|
b[0][1] = proof[3];
|
||||||
b[1][0] = uint256(bytes32(proof[128:160]));
|
b[1][0] = proof[4];
|
||||||
b[1][1] = uint256(bytes32(proof[160:192]));
|
b[1][1] = proof[5];
|
||||||
c[0] = uint256(bytes32(proof[192:224]));
|
c[0] = proof[6];
|
||||||
c[1] = uint256(bytes32(proof[224:256]));
|
c[1] = proof[7];
|
||||||
|
|
||||||
// TODO: The `pubSignals` should be constructed from information that we already know:
|
// TODO: The `pubSignals` should be constructed from information that we already know:
|
||||||
// - external entropy (for example some fresh ethereum block header) - this gives us the unbiased randomness we use to sample which cells to prove
|
// - external entropy (for example some fresh ethereum block header) - this gives us the unbiased randomness we use to sample which cells to prove
|
||||||
|
@ -1,9 +1,12 @@
|
|||||||
const { ethers } = require("hardhat")
|
const { ethers } = require("hardhat")
|
||||||
const { hexlify, randomBytes } = ethers.utils
|
|
||||||
const { AddressZero } = ethers.constants
|
const { AddressZero } = ethers.constants
|
||||||
const { BigNumber } = ethers
|
const { BigNumber } = ethers
|
||||||
const { expect } = require("chai")
|
const { expect } = require("chai")
|
||||||
const { exampleConfiguration, exampleRequest } = require("./examples")
|
const {
|
||||||
|
exampleConfiguration,
|
||||||
|
exampleRequest,
|
||||||
|
exampleProof,
|
||||||
|
} = require("./examples")
|
||||||
const { periodic, hours } = require("./time")
|
const { periodic, hours } = require("./time")
|
||||||
const { requestId, slotId, askToArray } = require("./ids")
|
const { requestId, slotId, askToArray } = require("./ids")
|
||||||
const {
|
const {
|
||||||
@ -76,7 +79,7 @@ describe("Marketplace constructor", function () {
|
|||||||
})
|
})
|
||||||
|
|
||||||
describe("Marketplace", function () {
|
describe("Marketplace", function () {
|
||||||
const proof = hexlify(randomBytes(256))
|
const proof = exampleProof()
|
||||||
const config = exampleConfiguration()
|
const config = exampleConfiguration()
|
||||||
|
|
||||||
let marketplace
|
let marketplace
|
||||||
|
@ -39,4 +39,6 @@ const exampleRequest = async () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = { exampleConfiguration, exampleRequest }
|
const exampleProof = () => ([1, 2, 3, 4, 5, 6, 7, 8])
|
||||||
|
|
||||||
|
module.exports = { exampleConfiguration, exampleRequest, exampleProof }
|
||||||
|
@ -1,40 +1,34 @@
|
|||||||
const fs = require("fs")
|
const fs = require("fs")
|
||||||
const ethers = require("ethers")
|
const ethers = require("ethers")
|
||||||
const { arrayify, concat } = ethers.utils
|
|
||||||
const { BigNumber } = ethers
|
const { BigNumber } = ethers
|
||||||
|
|
||||||
const BASE_PATH = __dirname + "/../verifier/networks"
|
const BASE_PATH = __dirname + "/../verifier/networks"
|
||||||
const PROOF_FILE_NAME = "example-proof/proof.json"
|
const PROOF_FILE_NAME = "example-proof/proof.json"
|
||||||
|
|
||||||
function decimalToBytes(decimal) {
|
function G1ToUInts(point) {
|
||||||
return arrayify(BigNumber.from(decimal).toHexString())
|
return [
|
||||||
|
point[0],
|
||||||
|
point[1]
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
function G1ToBytes(point) {
|
function G2ToUInts(point) {
|
||||||
return concat([
|
return [
|
||||||
decimalToBytes(point[0]),
|
point[0][1],
|
||||||
decimalToBytes(point[1])
|
point[0][0],
|
||||||
])
|
point[1][1],
|
||||||
}
|
point[1][0]
|
||||||
|
]
|
||||||
function G2ToBytes(point) {
|
|
||||||
return concat([
|
|
||||||
decimalToBytes(point[0][1]),
|
|
||||||
decimalToBytes(point[0][0]),
|
|
||||||
decimalToBytes(point[1][1]),
|
|
||||||
decimalToBytes(point[1][0])
|
|
||||||
])
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function loadProof(name) {
|
function loadProof(name) {
|
||||||
const proof = JSON.parse(
|
const proof = JSON.parse(
|
||||||
fs.readFileSync(`${BASE_PATH}/${name}/${PROOF_FILE_NAME}`)
|
fs.readFileSync(`${BASE_PATH}/${name}/${PROOF_FILE_NAME}`)
|
||||||
)
|
)
|
||||||
return concat([
|
return []
|
||||||
G1ToBytes(proof['pi_a']),
|
.concat(G1ToUInts(proof['pi_a']))
|
||||||
G2ToBytes(proof['pi_b']),
|
.concat(G2ToUInts(proof['pi_b']))
|
||||||
G1ToBytes(proof['pi_c'])
|
.concat(G1ToUInts(proof['pi_c']))
|
||||||
])
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = { loadProof }
|
module.exports = { loadProof }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user