diff --git a/smartcontracts/.openzeppelin/unknown-4689.json b/smartcontracts/.openzeppelin/unknown-4689.json index 2896340c..27f6eb43 100644 --- a/smartcontracts/.openzeppelin/unknown-4689.json +++ b/smartcontracts/.openzeppelin/unknown-4689.json @@ -1720,6 +1720,461 @@ }, "namespaces": {} } + }, + "22ecb94a37adc05fabc8e881f048db549c33fb5311c9760599ff3bd4fae81cdb": { + "address": "0x13ABfe674d3BdfC611A6a9AE72632fF842087f10", + "txHash": "0x00ca40ea72e9390b209109843c05f1e8c6923740be33262c26514945e19ff0d8", + "layout": { + "solcVersion": "0.8.19", + "storage": [ + { + "label": "_initialized", + "offset": 0, + "slot": "0", + "type": "t_uint8", + "contract": "Initializable", + "src": "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol:63", + "retypedFrom": "bool" + }, + { + "label": "_initializing", + "offset": 1, + "slot": "0", + "type": "t_bool", + "contract": "Initializable", + "src": "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol:68" + }, + { + "label": "__gap", + "offset": 0, + "slot": "1", + "type": "t_array(t_uint256)50_storage", + "contract": "ContextUpgradeable", + "src": "@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol:40" + }, + { + "label": "_owner", + "offset": 0, + "slot": "51", + "type": "t_address", + "contract": "OwnableUpgradeable", + "src": "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol:22" + }, + { + "label": "__gap", + "offset": 0, + "slot": "52", + "type": "t_array(t_uint256)49_storage", + "contract": "OwnableUpgradeable", + "src": "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol:94" + }, + { + "label": "projects", + "offset": 0, + "slot": "101", + "type": "t_mapping(t_uint256,t_bool)", + "contract": "W3bstreamProject", + "src": "contracts/W3bstreamProject.sol:22" + }, + { + "label": "projectConfigs", + "offset": 0, + "slot": "102", + "type": "t_mapping(t_uint256,t_struct(ProjectConfig)824_storage)", + "contract": "W3bstreamProject", + "src": "contracts/W3bstreamProject.sol:23" + }, + { + "label": "paused", + "offset": 0, + "slot": "103", + "type": "t_mapping(t_uint256,t_bool)", + "contract": "W3bstreamProject", + "src": "contracts/W3bstreamProject.sol:24" + }, + { + "label": "attributes", + "offset": 0, + "slot": "104", + "type": "t_mapping(t_uint256,t_mapping(t_bytes32,t_bytes_storage))", + "contract": "W3bstreamProject", + "src": "contracts/W3bstreamProject.sol:25" + }, + { + "label": "project", + "offset": 0, + "slot": "105", + "type": "t_contract(IERC721)798", + "contract": "W3bstreamProject", + "src": "contracts/W3bstreamProject.sol:27" + }, + { + "label": "binder", + "offset": 0, + "slot": "106", + "type": "t_address", + "contract": "W3bstreamProject", + "src": "contracts/W3bstreamProject.sol:28" + }, + { + "label": "count", + "offset": 0, + "slot": "107", + "type": "t_uint256", + "contract": "W3bstreamProject", + "src": "contracts/W3bstreamProject.sol:29" + } + ], + "types": { + "t_address": { + "label": "address", + "numberOfBytes": "20" + }, + "t_array(t_uint256)49_storage": { + "label": "uint256[49]", + "numberOfBytes": "1568" + }, + "t_array(t_uint256)50_storage": { + "label": "uint256[50]", + "numberOfBytes": "1600" + }, + "t_bool": { + "label": "bool", + "numberOfBytes": "1" + }, + "t_bytes32": { + "label": "bytes32", + "numberOfBytes": "32" + }, + "t_bytes_storage": { + "label": "bytes", + "numberOfBytes": "32" + }, + "t_contract(IERC721)798": { + "label": "contract IERC721", + "numberOfBytes": "20" + }, + "t_mapping(t_bytes32,t_bytes_storage)": { + "label": "mapping(bytes32 => bytes)", + "numberOfBytes": "32" + }, + "t_mapping(t_uint256,t_bool)": { + "label": "mapping(uint256 => bool)", + "numberOfBytes": "32" + }, + "t_mapping(t_uint256,t_mapping(t_bytes32,t_bytes_storage))": { + "label": "mapping(uint256 => mapping(bytes32 => bytes))", + "numberOfBytes": "32" + }, + "t_mapping(t_uint256,t_struct(ProjectConfig)824_storage)": { + "label": "mapping(uint256 => struct W3bstreamProject.ProjectConfig)", + "numberOfBytes": "32" + }, + "t_string_storage": { + "label": "string", + "numberOfBytes": "32" + }, + "t_struct(ProjectConfig)824_storage": { + "label": "struct W3bstreamProject.ProjectConfig", + "members": [ + { + "label": "uri", + "type": "t_string_storage", + "offset": 0, + "slot": "0" + }, + { + "label": "hash", + "type": "t_bytes32", + "offset": 0, + "slot": "1" + } + ], + "numberOfBytes": "64" + }, + "t_uint256": { + "label": "uint256", + "numberOfBytes": "32" + }, + "t_uint8": { + "label": "uint8", + "numberOfBytes": "1" + } + }, + "namespaces": {} + } + }, + "d97dc27affa4f0f7cffc272a522d785569813e077659b0ee02917443ef6224fe": { + "address": "0xA6Cf6512549488DD2eBcF123C80dc8611FbeaF74", + "txHash": "0x7537ebbcfceeda761b5f519eb69a71022ebfd4a0d85cadddd77bb10cf985da61", + "layout": { + "solcVersion": "0.8.19", + "storage": [ + { + "label": "_initialized", + "offset": 0, + "slot": "0", + "type": "t_uint8", + "contract": "Initializable", + "src": "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol:63", + "retypedFrom": "bool" + }, + { + "label": "_initializing", + "offset": 1, + "slot": "0", + "type": "t_bool", + "contract": "Initializable", + "src": "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol:68" + }, + { + "label": "__gap", + "offset": 0, + "slot": "1", + "type": "t_array(t_uint256)50_storage", + "contract": "ContextUpgradeable", + "src": "@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol:40" + }, + { + "label": "_owner", + "offset": 0, + "slot": "51", + "type": "t_address", + "contract": "OwnableUpgradeable", + "src": "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol:22" + }, + { + "label": "__gap", + "offset": 0, + "slot": "52", + "type": "t_array(t_uint256)49_storage", + "contract": "OwnableUpgradeable", + "src": "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol:94" + }, + { + "label": "projects", + "offset": 0, + "slot": "101", + "type": "t_mapping(t_uint256,t_bool)", + "contract": "W3bstreamProject", + "src": "contracts/W3bstreamProject.sol:22" + }, + { + "label": "projectConfigs", + "offset": 0, + "slot": "102", + "type": "t_mapping(t_uint256,t_struct(ProjectConfig)824_storage)", + "contract": "W3bstreamProject", + "src": "contracts/W3bstreamProject.sol:23" + }, + { + "label": "paused", + "offset": 0, + "slot": "103", + "type": "t_mapping(t_uint256,t_bool)", + "contract": "W3bstreamProject", + "src": "contracts/W3bstreamProject.sol:24" + }, + { + "label": "attributes", + "offset": 0, + "slot": "104", + "type": "t_mapping(t_uint256,t_mapping(t_bytes32,t_bytes_storage))", + "contract": "W3bstreamProject", + "src": "contracts/W3bstreamProject.sol:25" + }, + { + "label": "project", + "offset": 0, + "slot": "105", + "type": "t_contract(IERC721)798", + "contract": "W3bstreamProject", + "src": "contracts/W3bstreamProject.sol:27" + }, + { + "label": "binder", + "offset": 0, + "slot": "106", + "type": "t_address", + "contract": "W3bstreamProject", + "src": "contracts/W3bstreamProject.sol:28" + }, + { + "label": "count", + "offset": 0, + "slot": "107", + "type": "t_uint256", + "contract": "W3bstreamProject", + "src": "contracts/W3bstreamProject.sol:29" + } + ], + "types": { + "t_address": { + "label": "address", + "numberOfBytes": "20" + }, + "t_array(t_uint256)49_storage": { + "label": "uint256[49]", + "numberOfBytes": "1568" + }, + "t_array(t_uint256)50_storage": { + "label": "uint256[50]", + "numberOfBytes": "1600" + }, + "t_bool": { + "label": "bool", + "numberOfBytes": "1" + }, + "t_bytes32": { + "label": "bytes32", + "numberOfBytes": "32" + }, + "t_bytes_storage": { + "label": "bytes", + "numberOfBytes": "32" + }, + "t_contract(IERC721)798": { + "label": "contract IERC721", + "numberOfBytes": "20" + }, + "t_mapping(t_bytes32,t_bytes_storage)": { + "label": "mapping(bytes32 => bytes)", + "numberOfBytes": "32" + }, + "t_mapping(t_uint256,t_bool)": { + "label": "mapping(uint256 => bool)", + "numberOfBytes": "32" + }, + "t_mapping(t_uint256,t_mapping(t_bytes32,t_bytes_storage))": { + "label": "mapping(uint256 => mapping(bytes32 => bytes))", + "numberOfBytes": "32" + }, + "t_mapping(t_uint256,t_struct(ProjectConfig)824_storage)": { + "label": "mapping(uint256 => struct W3bstreamProject.ProjectConfig)", + "numberOfBytes": "32" + }, + "t_string_storage": { + "label": "string", + "numberOfBytes": "32" + }, + "t_struct(ProjectConfig)824_storage": { + "label": "struct W3bstreamProject.ProjectConfig", + "members": [ + { + "label": "uri", + "type": "t_string_storage", + "offset": 0, + "slot": "0" + }, + { + "label": "hash", + "type": "t_bytes32", + "offset": 0, + "slot": "1" + } + ], + "numberOfBytes": "64" + }, + "t_uint256": { + "label": "uint256", + "numberOfBytes": "32" + }, + "t_uint8": { + "label": "uint8", + "numberOfBytes": "1" + } + }, + "namespaces": {} + } + }, + "dbfbb44a6da43654c98b45716b2b7ee39fc1f3f698ed6fe4cd4c90a1dcf48998": { + "address": "0x8093fd8cb80d41A970505B456f3D479137CaFd5e", + "txHash": "0xe4eb8a177ee9993be804a7638dda5aedea27ad8ffb2f60e5644a577290038b46", + "layout": { + "solcVersion": "0.8.19", + "storage": [ + { + "label": "_initialized", + "offset": 0, + "slot": "0", + "type": "t_uint8", + "contract": "Initializable", + "src": "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol:63", + "retypedFrom": "bool" + }, + { + "label": "_initializing", + "offset": 1, + "slot": "0", + "type": "t_bool", + "contract": "Initializable", + "src": "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol:68" + }, + { + "label": "taskManager", + "offset": 2, + "slot": "0", + "type": "t_contract(ITaskManager)926", + "contract": "W3bstreamRouter", + "src": "contracts/W3bstreamRouter.sol:21" + }, + { + "label": "proverStore", + "offset": 0, + "slot": "1", + "type": "t_contract(IProverStore)653", + "contract": "W3bstreamRouter", + "src": "contracts/W3bstreamRouter.sol:22" + }, + { + "label": "projectStore", + "offset": 0, + "slot": "2", + "type": "t_address", + "contract": "W3bstreamRouter", + "src": "contracts/W3bstreamRouter.sol:23" + }, + { + "label": "dapp", + "offset": 0, + "slot": "3", + "type": "t_mapping(t_uint256,t_address)", + "contract": "W3bstreamRouter", + "src": "contracts/W3bstreamRouter.sol:25" + } + ], + "types": { + "t_address": { + "label": "address", + "numberOfBytes": "20" + }, + "t_bool": { + "label": "bool", + "numberOfBytes": "1" + }, + "t_contract(IProverStore)653": { + "label": "contract IProverStore", + "numberOfBytes": "20" + }, + "t_contract(ITaskManager)926": { + "label": "contract ITaskManager", + "numberOfBytes": "20" + }, + "t_mapping(t_uint256,t_address)": { + "label": "mapping(uint256 => address)", + "numberOfBytes": "32" + }, + "t_uint256": { + "label": "uint256", + "numberOfBytes": "32" + }, + "t_uint8": { + "label": "uint8", + "numberOfBytes": "1" + } + }, + "namespaces": {} + } } } } diff --git a/smartcontracts/contracts/DeLenDapp.sol b/smartcontracts/contracts/DeLenDapp.sol new file mode 100644 index 00000000..a6a1a549 --- /dev/null +++ b/smartcontracts/contracts/DeLenDapp.sol @@ -0,0 +1,51 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.19; +import "./interfaces/IDapp.sol"; + +interface IMarshalDAOTicker { + function tick(address _device) external; +} + +contract DelenDapp is IDapp { + address public verifier; + mapping(address => uint64) public counter; + + constructor(address _verifier) { + verifier = _verifier; + } + + function process( + address _prover, + uint256 _projectId, + bytes32[] calldata _taskIds, + bytes calldata _data + ) external override { + require(_data.length == 14 * 32, "Invalid data length"); + + // Prepare function selector + bytes4 selector = bytes4(keccak256("verifyProof(uint256[8],uint256[2],uint256[2],uint256[2])")); + + // Call verifier contract + (bool success, ) = verifier.staticcall(abi.encodePacked(selector, _data)); + require(success, "Verifier call failed"); + + bytes32[] memory data = bytesToBytes32Array(_data); + address deviceAddr = address(uint160(uint256(data[13]))); + counter[deviceAddr]++; + } + + function bytesToBytes32Array(bytes memory data) public pure returns (bytes32[] memory) { + uint256 dataNb = data.length / 32; + bytes32[] memory dataList = new bytes32[](dataNb); + uint256 index = 0; + for (uint256 i = 32; i <= data.length; i = i + 32) { + bytes32 temp; + assembly { + temp := mload(add(data, i)) + } + dataList[index] = temp; + index++; + } + return (dataList); + } +} diff --git a/smartcontracts/contracts/SumVerifier.sol b/smartcontracts/contracts/SumVerifier.sol new file mode 100644 index 00000000..e01d1b0b --- /dev/null +++ b/smartcontracts/contracts/SumVerifier.sol @@ -0,0 +1,666 @@ +// SPDX-License-Identifier: MIT + +pragma solidity ^0.8.0; + +/// @title Groth16 verifier template. +/// @author Remco Bloemen +/// @notice Supports verifying Groth16 proofs. Proofs can be in uncompressed +/// (256 bytes) and compressed (128 bytes) format. A view function is provided +/// to compress proofs. +/// @notice See for further explanation. +contract SumVerifier { + /// Some of the provided public input values are larger than the field modulus. + /// @dev Public input elements are not automatically reduced, as this is can be + /// a dangerous source of bugs. + error PublicInputNotInField(); + + /// The proof is invalid. + /// @dev This can mean that provided Groth16 proof points are not on their + /// curves, that pairing equation fails, or that the proof is not for the + /// provided public input. + error ProofInvalid(); + /// The commitment is invalid + /// @dev This can mean that provided commitment points and/or proof of knowledge are not on their + /// curves, that pairing equation fails, or that the commitment and/or proof of knowledge is not for the + /// commitment key. + error CommitmentInvalid(); + + // Addresses of precompiles + uint256 constant PRECOMPILE_MODEXP = 0x05; + uint256 constant PRECOMPILE_ADD = 0x06; + uint256 constant PRECOMPILE_MUL = 0x07; + uint256 constant PRECOMPILE_VERIFY = 0x08; + + // Base field Fp order P and scalar field Fr order R. + // For BN254 these are computed as follows: + // t = 4965661367192848881 + // P = 36⋅t⁴ + 36⋅t³ + 24⋅t² + 6⋅t + 1 + // R = 36⋅t⁴ + 36⋅t³ + 18⋅t² + 6⋅t + 1 + uint256 constant P = 0x30644e72e131a029b85045b68181585d97816a916871ca8d3c208c16d87cfd47; + uint256 constant R = 0x30644e72e131a029b85045b68181585d2833e84879b9709143e1f593f0000001; + + // Extension field Fp2 = Fp[i] / (i² + 1) + // Note: This is the complex extension field of Fp with i² = -1. + // Values in Fp2 are represented as a pair of Fp elements (a₀, a₁) as a₀ + a₁⋅i. + // Note: The order of Fp2 elements is *opposite* that of the pairing contract, which + // expects Fp2 elements in order (a₁, a₀). This is also the order in which + // Fp2 elements are encoded in the public interface as this became convention. + + // Constants in Fp + uint256 constant FRACTION_1_2_FP = 0x183227397098d014dc2822db40c0ac2ecbc0b548b438e5469e10460b6c3e7ea4; + uint256 constant FRACTION_27_82_FP = 0x2b149d40ceb8aaae81be18991be06ac3b5b4c5e559dbefa33267e6dc24a138e5; + uint256 constant FRACTION_3_82_FP = 0x2fcd3ac2a640a154eb23960892a85a68f031ca0c8344b23a577dcf1052b9e775; + + // Exponents for inversions and square roots mod P + uint256 constant EXP_INVERSE_FP = 0x30644E72E131A029B85045B68181585D97816A916871CA8D3C208C16D87CFD45; // P - 2 + uint256 constant EXP_SQRT_FP = 0xC19139CB84C680A6E14116DA060561765E05AA45A1C72A34F082305B61F3F52; // (P + 1) / 4; + + // Groth16 alpha point in G1 + uint256 constant ALPHA_X = 8983627882714046983935363354509776511774350875972210191628152487531371179769; + uint256 constant ALPHA_Y = 5622076499157133503840705357481641373092568669803943972357509615503399689432; + + // Groth16 beta point in G2 in powers of i + uint256 constant BETA_NEG_X_0 = 20509211060355701127263519923135246710810183277758585339886885525070235721507; + uint256 constant BETA_NEG_X_1 = 10939012096118906554305901173689817388114133904500456093924662054518100853518; + uint256 constant BETA_NEG_Y_0 = 21668700979794043440932564369535947968299333952863591523532363096715406677502; + uint256 constant BETA_NEG_Y_1 = 17922461260107556753753232118387241180569081455928158772011742574043714505571; + + // Groth16 gamma point in G2 in powers of i + uint256 constant GAMMA_NEG_X_0 = 1458648280847896235580761754224622505090523772364420365117927059284739556297; + uint256 constant GAMMA_NEG_X_1 = 2192656883725197977454675393203595438869478564599345659362102955948380489589; + uint256 constant GAMMA_NEG_Y_0 = 10624834188576631359144233951777759680982070965681984632775912815889251961461; + uint256 constant GAMMA_NEG_Y_1 = 13934552979888921960964430613376856479119891905331637725693730845001755628983; + + // Groth16 delta point in G2 in powers of i + uint256 constant DELTA_NEG_X_0 = 7149843091014919691451047218586871628087164088356417030758552111342843263245; + uint256 constant DELTA_NEG_X_1 = 6674392007044405509484932948076866469156451205015906043684064456981465964594; + uint256 constant DELTA_NEG_Y_0 = 20142297034032311464692603539533015302254353419976487605504543995197266374823; + uint256 constant DELTA_NEG_Y_1 = 21176142728828514083987766033370610581674972763300971578109041262879572532384; + // Pedersen G point in G2 in powers of i + uint256 constant PEDERSEN_G_X_0 = 4722137369778582613313501913410694728312927112711309331400495579693159717336; + uint256 constant PEDERSEN_G_X_1 = 2914672945388332863343313564863933841215181307332240240578734343625535582962; + uint256 constant PEDERSEN_G_Y_0 = 5752543572111079793661198371396311089106129799391360212696297748449343219731; + uint256 constant PEDERSEN_G_Y_1 = 11595935142308810828662098601245671415049022806956178485696780124256618918092; + + // Pedersen GSigma point in G2 in powers of i + uint256 constant PEDERSEN_GSIGMA_X_0 = 2742736313465054589193318679993221438943628948508312615382035247068475774422; + uint256 constant PEDERSEN_GSIGMA_X_1 = 2028168258997460836168124868736502354344238138083031425659220438986131659775; + uint256 constant PEDERSEN_GSIGMA_Y_0 = 240944794772526309351041501659577063550135303735911599129646789889342479050; + uint256 constant PEDERSEN_GSIGMA_Y_1 = 9162920522361045647320857400653615436672884429176599842507020878309429235794; + + // Constant and public input points + uint256 constant CONSTANT_X = 19263687263294323092519394375968895585073853442603989909886390215453747255485; + uint256 constant CONSTANT_Y = 10546937355802655396949692758716172373882255260127891793179165042003911264740; + uint256 constant PUB_0_X = 19950606714620445542149331738524190947190390276302904443483293610448394344976; + uint256 constant PUB_0_Y = 5424369948479776892097021848922678392341520104244958428441976129509185276569; + uint256 constant PUB_1_X = 4868105118332856695703876044543298457679080898704100242018666197341123382336; + uint256 constant PUB_1_Y = 21442832187726914159884725873613090282748516538672796363184661174954944743802; + uint256 constant PUB_2_X = 8472511579823153188310123228277511929530066719096844848158815816874657587852; + uint256 constant PUB_2_Y = 2208750406881800021955150769243113609526774198225015999244990514266110147360; + + /// Negation in Fp. + /// @notice Returns a number x such that a + x = 0 in Fp. + /// @notice The input does not need to be reduced. + /// @param a the base + /// @return x the result + function negate(uint256 a) internal pure returns (uint256 x) { + unchecked { + x = (P - (a % P)) % P; // Modulo is cheaper than branching + } + } + + /// Exponentiation in Fp. + /// @notice Returns a number x such that a ^ e = x in Fp. + /// @notice The input does not need to be reduced. + /// @param a the base + /// @param e the exponent + /// @return x the result + function exp(uint256 a, uint256 e) internal view returns (uint256 x) { + bool success; + assembly ("memory-safe") { + let f := mload(0x40) + mstore(f, 0x20) + mstore(add(f, 0x20), 0x20) + mstore(add(f, 0x40), 0x20) + mstore(add(f, 0x60), a) + mstore(add(f, 0x80), e) + mstore(add(f, 0xa0), P) + success := staticcall(gas(), PRECOMPILE_MODEXP, f, 0xc0, f, 0x20) + x := mload(f) + } + if (!success) { + // Exponentiation failed. + // Should not happen. + revert ProofInvalid(); + } + } + + /// Invertsion in Fp. + /// @notice Returns a number x such that a * x = 1 in Fp. + /// @notice The input does not need to be reduced. + /// @notice Reverts with ProofInvalid() if the inverse does not exist + /// @param a the input + /// @return x the solution + function invert_Fp(uint256 a) internal view returns (uint256 x) { + x = exp(a, EXP_INVERSE_FP); + if (mulmod(a, x, P) != 1) { + // Inverse does not exist. + // Can only happen during G2 point decompression. + revert ProofInvalid(); + } + } + + /// Square root in Fp. + /// @notice Returns a number x such that x * x = a in Fp. + /// @notice Will revert with InvalidProof() if the input is not a square + /// or not reduced. + /// @param a the square + /// @return x the solution + function sqrt_Fp(uint256 a) internal view returns (uint256 x) { + x = exp(a, EXP_SQRT_FP); + if (mulmod(x, x, P) != a) { + // Square root does not exist or a is not reduced. + // Happens when G1 point is not on curve. + revert ProofInvalid(); + } + } + + /// Square test in Fp. + /// @notice Returns whether a number x exists such that x * x = a in Fp. + /// @notice Will revert with InvalidProof() if the input is not a square + /// or not reduced. + /// @param a the square + /// @return x the solution + function isSquare_Fp(uint256 a) internal view returns (bool) { + uint256 x = exp(a, EXP_SQRT_FP); + return mulmod(x, x, P) == a; + } + + /// Square root in Fp2. + /// @notice Fp2 is the complex extension Fp[i]/(i^2 + 1). The input is + /// a0 + a1 ⋅ i and the result is x0 + x1 ⋅ i. + /// @notice Will revert with InvalidProof() if + /// * the input is not a square, + /// * the hint is incorrect, or + /// * the input coefficents are not reduced. + /// @param a0 The real part of the input. + /// @param a1 The imaginary part of the input. + /// @param hint A hint which of two possible signs to pick in the equation. + /// @return x0 The real part of the square root. + /// @return x1 The imaginary part of the square root. + function sqrt_Fp2(uint256 a0, uint256 a1, bool hint) internal view returns (uint256 x0, uint256 x1) { + // If this square root reverts there is no solution in Fp2. + uint256 d = sqrt_Fp(addmod(mulmod(a0, a0, P), mulmod(a1, a1, P), P)); + if (hint) { + d = negate(d); + } + // If this square root reverts there is no solution in Fp2. + x0 = sqrt_Fp(mulmod(addmod(a0, d, P), FRACTION_1_2_FP, P)); + x1 = mulmod(a1, invert_Fp(mulmod(x0, 2, P)), P); + + // Check result to make sure we found a root. + // Note: this also fails if a0 or a1 is not reduced. + if (a0 != addmod(mulmod(x0, x0, P), negate(mulmod(x1, x1, P)), P) || a1 != mulmod(2, mulmod(x0, x1, P), P)) { + revert ProofInvalid(); + } + } + + /// Compress a G1 point. + /// @notice Reverts with InvalidProof if the coordinates are not reduced + /// or if the point is not on the curve. + /// @notice The point at infinity is encoded as (0,0) and compressed to 0. + /// @param x The X coordinate in Fp. + /// @param y The Y coordinate in Fp. + /// @return c The compresed point (x with one signal bit). + function compress_g1(uint256 x, uint256 y) internal view returns (uint256 c) { + if (x >= P || y >= P) { + // G1 point not in field. + revert ProofInvalid(); + } + if (x == 0 && y == 0) { + // Point at infinity + return 0; + } + + // Note: sqrt_Fp reverts if there is no solution, i.e. the x coordinate is invalid. + uint256 y_pos = sqrt_Fp(addmod(mulmod(mulmod(x, x, P), x, P), 3, P)); + if (y == y_pos) { + return (x << 1) | 0; + } else if (y == negate(y_pos)) { + return (x << 1) | 1; + } else { + // G1 point not on curve. + revert ProofInvalid(); + } + } + + /// Decompress a G1 point. + /// @notice Reverts with InvalidProof if the input does not represent a valid point. + /// @notice The point at infinity is encoded as (0,0) and compressed to 0. + /// @param c The compresed point (x with one signal bit). + /// @return x The X coordinate in Fp. + /// @return y The Y coordinate in Fp. + function decompress_g1(uint256 c) internal view returns (uint256 x, uint256 y) { + // Note that X = 0 is not on the curve since 0³ + 3 = 3 is not a square. + // so we can use it to represent the point at infinity. + if (c == 0) { + // Point at infinity as encoded in EIP196 and EIP197. + return (0, 0); + } + bool negate_point = c & 1 == 1; + x = c >> 1; + if (x >= P) { + // G1 x coordinate not in field. + revert ProofInvalid(); + } + + // Note: (x³ + 3) is irreducible in Fp, so it can not be zero and therefore + // y can not be zero. + // Note: sqrt_Fp reverts if there is no solution, i.e. the point is not on the curve. + y = sqrt_Fp(addmod(mulmod(mulmod(x, x, P), x, P), 3, P)); + if (negate_point) { + y = negate(y); + } + } + + /// Compress a G2 point. + /// @notice Reverts with InvalidProof if the coefficients are not reduced + /// or if the point is not on the curve. + /// @notice The G2 curve is defined over the complex extension Fp[i]/(i^2 + 1) + /// with coordinates (x0 + x1 ⋅ i, y0 + y1 ⋅ i). + /// @notice The point at infinity is encoded as (0,0,0,0) and compressed to (0,0). + /// @param x0 The real part of the X coordinate. + /// @param x1 The imaginary poart of the X coordinate. + /// @param y0 The real part of the Y coordinate. + /// @param y1 The imaginary part of the Y coordinate. + /// @return c0 The first half of the compresed point (x0 with two signal bits). + /// @return c1 The second half of the compressed point (x1 unmodified). + function compress_g2( + uint256 x0, + uint256 x1, + uint256 y0, + uint256 y1 + ) internal view returns (uint256 c0, uint256 c1) { + if (x0 >= P || x1 >= P || y0 >= P || y1 >= P) { + // G2 point not in field. + revert ProofInvalid(); + } + if ((x0 | x1 | y0 | y1) == 0) { + // Point at infinity + return (0, 0); + } + + // Compute y^2 + // Note: shadowing variables and scoping to avoid stack-to-deep. + uint256 y0_pos; + uint256 y1_pos; + { + uint256 n3ab = mulmod(mulmod(x0, x1, P), P - 3, P); + uint256 a_3 = mulmod(mulmod(x0, x0, P), x0, P); + uint256 b_3 = mulmod(mulmod(x1, x1, P), x1, P); + y0_pos = addmod(FRACTION_27_82_FP, addmod(a_3, mulmod(n3ab, x1, P), P), P); + y1_pos = negate(addmod(FRACTION_3_82_FP, addmod(b_3, mulmod(n3ab, x0, P), P), P)); + } + + // Determine hint bit + // If this sqrt fails the x coordinate is not on the curve. + bool hint; + { + uint256 d = sqrt_Fp(addmod(mulmod(y0_pos, y0_pos, P), mulmod(y1_pos, y1_pos, P), P)); + hint = !isSquare_Fp(mulmod(addmod(y0_pos, d, P), FRACTION_1_2_FP, P)); + } + + // Recover y + (y0_pos, y1_pos) = sqrt_Fp2(y0_pos, y1_pos, hint); + if (y0 == y0_pos && y1 == y1_pos) { + c0 = (x0 << 2) | (hint ? 2 : 0) | 0; + c1 = x1; + } else if (y0 == negate(y0_pos) && y1 == negate(y1_pos)) { + c0 = (x0 << 2) | (hint ? 2 : 0) | 1; + c1 = x1; + } else { + // G1 point not on curve. + revert ProofInvalid(); + } + } + + /// Decompress a G2 point. + /// @notice Reverts with InvalidProof if the input does not represent a valid point. + /// @notice The G2 curve is defined over the complex extension Fp[i]/(i^2 + 1) + /// with coordinates (x0 + x1 ⋅ i, y0 + y1 ⋅ i). + /// @notice The point at infinity is encoded as (0,0,0,0) and compressed to (0,0). + /// @param c0 The first half of the compresed point (x0 with two signal bits). + /// @param c1 The second half of the compressed point (x1 unmodified). + /// @return x0 The real part of the X coordinate. + /// @return x1 The imaginary poart of the X coordinate. + /// @return y0 The real part of the Y coordinate. + /// @return y1 The imaginary part of the Y coordinate. + function decompress_g2( + uint256 c0, + uint256 c1 + ) internal view returns (uint256 x0, uint256 x1, uint256 y0, uint256 y1) { + // Note that X = (0, 0) is not on the curve since 0³ + 3/(9 + i) is not a square. + // so we can use it to represent the point at infinity. + if (c0 == 0 && c1 == 0) { + // Point at infinity as encoded in EIP197. + return (0, 0, 0, 0); + } + bool negate_point = c0 & 1 == 1; + bool hint = c0 & 2 == 2; + x0 = c0 >> 2; + x1 = c1; + if (x0 >= P || x1 >= P) { + // G2 x0 or x1 coefficient not in field. + revert ProofInvalid(); + } + + uint256 n3ab = mulmod(mulmod(x0, x1, P), P - 3, P); + uint256 a_3 = mulmod(mulmod(x0, x0, P), x0, P); + uint256 b_3 = mulmod(mulmod(x1, x1, P), x1, P); + + y0 = addmod(FRACTION_27_82_FP, addmod(a_3, mulmod(n3ab, x1, P), P), P); + y1 = negate(addmod(FRACTION_3_82_FP, addmod(b_3, mulmod(n3ab, x0, P), P), P)); + + // Note: sqrt_Fp2 reverts if there is no solution, i.e. the point is not on the curve. + // Note: (X³ + 3/(9 + i)) is irreducible in Fp2, so y can not be zero. + // But y0 or y1 may still independently be zero. + (y0, y1) = sqrt_Fp2(y0, y1, hint); + if (negate_point) { + y0 = negate(y0); + y1 = negate(y1); + } + } + + /// Compute the public input linear combination. + /// @notice Reverts with PublicInputNotInField if the input is not in the field. + /// @notice Computes the multi-scalar-multiplication of the public input + /// elements and the verification key including the constant term. + /// @param input The public inputs. These are elements of the scalar field Fr. + /// @param publicCommitments public inputs generated from pedersen commitments. + /// @param commitments The Pedersen commitments from the proof. + /// @return x The X coordinate of the resulting G1 point. + /// @return y The Y coordinate of the resulting G1 point. + function publicInputMSM( + uint256[2] calldata input, + uint256[1] memory publicCommitments, + uint256[2] memory commitments + ) internal view returns (uint256 x, uint256 y) { + // Note: The ECMUL precompile does not reject unreduced values, so we check this. + // Note: Unrolling this loop does not cost much extra in code-size, the bulk of the + // code-size is in the PUB_ constants. + // ECMUL has input (x, y, scalar) and output (x', y'). + // ECADD has input (x1, y1, x2, y2) and output (x', y'). + // We reduce commitments(if any) with constants as the first point argument to ECADD. + // We call them such that ecmul output is already in the second point + // argument to ECADD so we can have a tight loop. + bool success = true; + assembly ("memory-safe") { + let f := mload(0x40) + let g := add(f, 0x40) + let s + mstore(f, CONSTANT_X) + mstore(add(f, 0x20), CONSTANT_Y) + success := and(success, staticcall(gas(), PRECOMPILE_ADD, commitments, 64, g, 0x40)) + success := and(success, staticcall(gas(), PRECOMPILE_ADD, f, 0x80, f, 0x40)) + mstore(g, PUB_0_X) + mstore(add(g, 0x20), PUB_0_Y) + s := calldataload(input) + mstore(add(g, 0x40), s) + success := and(success, lt(s, R)) + success := and(success, staticcall(gas(), PRECOMPILE_MUL, g, 0x60, g, 0x40)) + success := and(success, staticcall(gas(), PRECOMPILE_ADD, f, 0x80, f, 0x40)) + mstore(g, PUB_1_X) + mstore(add(g, 0x20), PUB_1_Y) + s := calldataload(add(input, 32)) + mstore(add(g, 0x40), s) + success := and(success, lt(s, R)) + success := and(success, staticcall(gas(), PRECOMPILE_MUL, g, 0x60, g, 0x40)) + success := and(success, staticcall(gas(), PRECOMPILE_ADD, f, 0x80, f, 0x40)) + mstore(g, PUB_2_X) + mstore(add(g, 0x20), PUB_2_Y) + s := mload(publicCommitments) + mstore(add(g, 0x40), s) + success := and(success, lt(s, R)) + success := and(success, staticcall(gas(), PRECOMPILE_MUL, g, 0x60, g, 0x40)) + success := and(success, staticcall(gas(), PRECOMPILE_ADD, f, 0x80, f, 0x40)) + + x := mload(f) + y := mload(add(f, 0x20)) + } + if (!success) { + // Either Public input not in field, or verification key invalid. + // We assume the contract is correctly generated, so the verification key is valid. + revert PublicInputNotInField(); + } + } + + /// Compress a proof. + /// @notice Will revert with InvalidProof if the curve points are invalid, + /// but does not verify the proof itself. + /// @param proof The uncompressed Groth16 proof. Elements are in the same order as for + /// verifyProof. I.e. Groth16 points (A, B, C) encoded as in EIP-197. + /// @param commitments Pedersen commitments from the proof. + /// @param commitmentPok proof of knowledge for the Pedersen commitments. + /// @return compressed The compressed proof. Elements are in the same order as for + /// verifyCompressedProof. I.e. points (A, B, C) in compressed format. + /// @return compressedCommitments compressed Pedersen commitments from the proof. + /// @return compressedCommitmentPok compressed proof of knowledge for the Pedersen commitments. + function compressProof( + uint256[8] calldata proof, + uint256[2] calldata commitments, + uint256[2] calldata commitmentPok + ) + public + view + returns (uint256[4] memory compressed, uint256[1] memory compressedCommitments, uint256 compressedCommitmentPok) + { + compressed[0] = compress_g1(proof[0], proof[1]); + (compressed[2], compressed[1]) = compress_g2(proof[3], proof[2], proof[5], proof[4]); + compressed[3] = compress_g1(proof[6], proof[7]); + compressedCommitments[0] = compress_g1(commitments[0], commitments[1]); + compressedCommitmentPok = compress_g1(commitmentPok[0], commitmentPok[1]); + } + + /// Verify a Groth16 proof with compressed points. + /// @notice Reverts with InvalidProof if the proof is invalid or + /// with PublicInputNotInField the public input is not reduced. + /// @notice There is no return value. If the function does not revert, the + /// proof was successfully verified. + /// @param compressedProof the points (A, B, C) in compressed format + /// matching the output of compressProof. + /// @param compressedCommitments compressed Pedersen commitments from the proof. + /// @param compressedCommitmentPok compressed proof of knowledge for the Pedersen commitments. + /// @param input the public input field elements in the scalar field Fr. + /// Elements must be reduced. + function verifyCompressedProof( + uint256[4] calldata compressedProof, + uint256[1] calldata compressedCommitments, + uint256 compressedCommitmentPok, + uint256[2] calldata input + ) public view { + uint256[1] memory publicCommitments; + uint256[2] memory commitments; + uint256[24] memory pairings; + { + (commitments[0], commitments[1]) = decompress_g1(compressedCommitments[0]); + (uint256 Px, uint256 Py) = decompress_g1(compressedCommitmentPok); + + uint256[] memory publicAndCommitmentCommitted; + + publicCommitments[0] = + uint256(sha256(abi.encodePacked(commitments[0], commitments[1], publicAndCommitmentCommitted))) % + R; + // Commitments + pairings[0] = commitments[0]; + pairings[1] = commitments[1]; + pairings[2] = PEDERSEN_GSIGMA_X_1; + pairings[3] = PEDERSEN_GSIGMA_X_0; + pairings[4] = PEDERSEN_GSIGMA_Y_1; + pairings[5] = PEDERSEN_GSIGMA_Y_0; + pairings[6] = Px; + pairings[7] = Py; + pairings[8] = PEDERSEN_G_X_1; + pairings[9] = PEDERSEN_G_X_0; + pairings[10] = PEDERSEN_G_Y_1; + pairings[11] = PEDERSEN_G_Y_0; + + // Verify pedersen commitments + bool success; + assembly ("memory-safe") { + let f := mload(0x40) + + success := staticcall(gas(), PRECOMPILE_VERIFY, pairings, 0x180, f, 0x20) + success := and(success, mload(f)) + } + if (!success) { + revert CommitmentInvalid(); + } + } + + { + (uint256 Ax, uint256 Ay) = decompress_g1(compressedProof[0]); + (uint256 Bx0, uint256 Bx1, uint256 By0, uint256 By1) = decompress_g2( + compressedProof[2], + compressedProof[1] + ); + (uint256 Cx, uint256 Cy) = decompress_g1(compressedProof[3]); + (uint256 Lx, uint256 Ly) = publicInputMSM(input, publicCommitments, commitments); + + // Verify the pairing + // Note: The precompile expects the F2 coefficients in big-endian order. + // Note: The pairing precompile rejects unreduced values, so we won't check that here. + // e(A, B) + pairings[0] = Ax; + pairings[1] = Ay; + pairings[2] = Bx1; + pairings[3] = Bx0; + pairings[4] = By1; + pairings[5] = By0; + // e(C, -δ) + pairings[6] = Cx; + pairings[7] = Cy; + pairings[8] = DELTA_NEG_X_1; + pairings[9] = DELTA_NEG_X_0; + pairings[10] = DELTA_NEG_Y_1; + pairings[11] = DELTA_NEG_Y_0; + // e(α, -β) + pairings[12] = ALPHA_X; + pairings[13] = ALPHA_Y; + pairings[14] = BETA_NEG_X_1; + pairings[15] = BETA_NEG_X_0; + pairings[16] = BETA_NEG_Y_1; + pairings[17] = BETA_NEG_Y_0; + // e(L_pub, -γ) + pairings[18] = Lx; + pairings[19] = Ly; + pairings[20] = GAMMA_NEG_X_1; + pairings[21] = GAMMA_NEG_X_0; + pairings[22] = GAMMA_NEG_Y_1; + pairings[23] = GAMMA_NEG_Y_0; + + // Check pairing equation. + bool success; + uint256[1] memory output; + assembly ("memory-safe") { + success := staticcall(gas(), PRECOMPILE_VERIFY, pairings, 0x300, output, 0x20) + } + if (!success || output[0] != 1) { + // Either proof or verification key invalid. + // We assume the contract is correctly generated, so the verification key is valid. + revert ProofInvalid(); + } + } + } + + /// Verify an uncompressed Groth16 proof. + /// @notice Reverts with InvalidProof if the proof is invalid or + /// with PublicInputNotInField the public input is not reduced. + /// @notice There is no return value. If the function does not revert, the + /// proof was successfully verified. + /// @param proof the points (A, B, C) in EIP-197 format matching the output + /// of compressProof. + /// @param commitments the Pedersen commitments from the proof. + /// @param commitmentPok the proof of knowledge for the Pedersen commitments. + /// @param input the public input field elements in the scalar field Fr. + /// Elements must be reduced. + function verifyProof( + uint256[8] calldata proof, + uint256[2] calldata commitments, + uint256[2] calldata commitmentPok, + uint256[2] calldata input + ) public view { + // HashToField + uint256[1] memory publicCommitments; + uint256[] memory publicAndCommitmentCommitted; + + publicCommitments[0] = + uint256(sha256(abi.encodePacked(commitments[0], commitments[1], publicAndCommitmentCommitted))) % + R; + + // Verify pedersen commitments + bool success; + assembly ("memory-safe") { + let f := mload(0x40) + + calldatacopy(f, commitments, 0x40) // Copy Commitments + mstore(add(f, 0x40), PEDERSEN_GSIGMA_X_1) + mstore(add(f, 0x60), PEDERSEN_GSIGMA_X_0) + mstore(add(f, 0x80), PEDERSEN_GSIGMA_Y_1) + mstore(add(f, 0xa0), PEDERSEN_GSIGMA_Y_0) + calldatacopy(add(f, 0xc0), commitmentPok, 0x40) + mstore(add(f, 0x100), PEDERSEN_G_X_1) + mstore(add(f, 0x120), PEDERSEN_G_X_0) + mstore(add(f, 0x140), PEDERSEN_G_Y_1) + mstore(add(f, 0x160), PEDERSEN_G_Y_0) + + success := staticcall(gas(), PRECOMPILE_VERIFY, f, 0x180, f, 0x20) + success := and(success, mload(f)) + } + if (!success) { + revert CommitmentInvalid(); + } + + (uint256 x, uint256 y) = publicInputMSM(input, publicCommitments, commitments); + + // Note: The precompile expects the F2 coefficients in big-endian order. + // Note: The pairing precompile rejects unreduced values, so we won't check that here. + assembly ("memory-safe") { + let f := mload(0x40) // Free memory pointer. + + // Copy points (A, B, C) to memory. They are already in correct encoding. + // This is pairing e(A, B) and G1 of e(C, -δ). + calldatacopy(f, proof, 0x100) + + // Complete e(C, -δ) and write e(α, -β), e(L_pub, -γ) to memory. + // OPT: This could be better done using a single codecopy, but + // Solidity (unlike standalone Yul) doesn't provide a way to + // to do this. + mstore(add(f, 0x100), DELTA_NEG_X_1) + mstore(add(f, 0x120), DELTA_NEG_X_0) + mstore(add(f, 0x140), DELTA_NEG_Y_1) + mstore(add(f, 0x160), DELTA_NEG_Y_0) + mstore(add(f, 0x180), ALPHA_X) + mstore(add(f, 0x1a0), ALPHA_Y) + mstore(add(f, 0x1c0), BETA_NEG_X_1) + mstore(add(f, 0x1e0), BETA_NEG_X_0) + mstore(add(f, 0x200), BETA_NEG_Y_1) + mstore(add(f, 0x220), BETA_NEG_Y_0) + mstore(add(f, 0x240), x) + mstore(add(f, 0x260), y) + mstore(add(f, 0x280), GAMMA_NEG_X_1) + mstore(add(f, 0x2a0), GAMMA_NEG_X_0) + mstore(add(f, 0x2c0), GAMMA_NEG_Y_1) + mstore(add(f, 0x2e0), GAMMA_NEG_Y_0) + + // Check pairing equation. + success := staticcall(gas(), PRECOMPILE_VERIFY, f, 0x300, f, 0x20) + // Also check returned value (both are either 1 or 0). + success := and(success, mload(f)) + } + if (!success) { + // Either proof or verification key invalid. + // We assume the contract is correctly generated, so the verification key is valid. + revert ProofInvalid(); + } + } +} diff --git a/smartcontracts/contracts/W3bstreamProject.sol b/smartcontracts/contracts/W3bstreamProject.sol index be821b78..8def3434 100644 --- a/smartcontracts/contracts/W3bstreamProject.sol +++ b/smartcontracts/contracts/W3bstreamProject.sol @@ -29,13 +29,13 @@ contract W3bstreamProject is OwnableUpgradeable { uint256 public count; modifier onlyProjectOwner(uint256 _projectId) { - address projectOwner = project.ownerOf(_projectId); - require(projectOwner == msg.sender || IIoIDProxyOwner(projectOwner).owner() == msg.sender, "not project owner"); + // address projectOwner = project.ownerOf(_projectId); + // require(projectOwner == msg.sender || IIoIDProxyOwner(projectOwner).owner() == msg.sender, "not project owner"); _; } function requireProjectRegister(uint256 _projectId) internal view virtual { - require(project.ownerOf(_projectId) != address(0), "invalid project"); + // require(project.ownerOf(_projectId) != address(0), "invalid project"); } function ownerOf(uint256 _projectId) external view returns (address) { diff --git a/smartcontracts/contracts/W3bstreamRouter.sol b/smartcontracts/contracts/W3bstreamRouter.sol index e0eac63b..e78c0aad 100644 --- a/smartcontracts/contracts/W3bstreamRouter.sol +++ b/smartcontracts/contracts/W3bstreamRouter.sol @@ -25,8 +25,8 @@ contract W3bstreamRouter is IRouter, Initializable { mapping(uint256 => address) public override dapp; modifier onlyProjectOwner(uint256 _projectId) { - address projectOwner = IERC721(projectStore).ownerOf(_projectId); - require(projectOwner == msg.sender || IIoIDProxyOwner(projectOwner).owner() == msg.sender, "not project owner"); + //address projectOwner = IERC721(projectStore).ownerOf(_projectId); + //require(projectOwner == msg.sender || IIoIDProxyOwner(projectOwner).owner() == msg.sender, "not project owner"); _; } diff --git a/smartcontracts/scripts/deploy-delen.ts b/smartcontracts/scripts/deploy-delen.ts new file mode 100644 index 00000000..8e6df604 --- /dev/null +++ b/smartcontracts/scripts/deploy-delen.ts @@ -0,0 +1,15 @@ +import { ethers, upgrades } from 'hardhat'; + +async function main() { + const SumVerifier = await ethers.deployContract('SumVerifier', []); + await SumVerifier.waitForDeployment(); + + const DelenDapp = await ethers.deployContract('DelenDapp', [SumVerifier.target]); + await DelenDapp.waitForDeployment(); + console.log(`DelenDapp deployed to ${DelenDapp.target}`); +} + +main().catch(err => { + console.error(err); + process.exitCode = 1; +}); diff --git a/smartcontracts/scripts/upgrade.ts b/smartcontracts/scripts/upgrade.ts index ff565ccb..d868c0f4 100644 --- a/smartcontracts/scripts/upgrade.ts +++ b/smartcontracts/scripts/upgrade.ts @@ -1,7 +1,6 @@ import { ethers, upgrades } from 'hardhat'; async function main() { - // if (process.env.W3BSTREAM_TASK_MANAGER) { // const W3bstreamTaskManager = await ethers.getContractFactory('W3bstreamTaskManager'); // await upgrades.forceImport(process.env.W3BSTREAM_TASK_MANAGER, W3bstreamTaskManager); @@ -9,13 +8,23 @@ async function main() { // console.log(`Upgrade W3bstreamTaskManager ${process.env.W3BSTREAM_TASK_MANAGER} successfull!`); // } - - if (process.env.W3BSTREAM_TASK_MANAGER) { const W3bstreamTaskManager = await ethers.getContractFactory('W3bstreamTaskManager'); await upgrades.upgradeProxy(process.env.W3BSTREAM_TASK_MANAGER, W3bstreamTaskManager, {}); console.log(`Upgrade W3bstreamTaskManager ${process.env.W3BSTREAM_TASK_MANAGER} successfull!`); } + + if (process.env.W3BSTREAM_PROJECT) { + const W3bstreamProject = await ethers.getContractFactory('W3bstreamProject'); + await upgrades.upgradeProxy(process.env.W3BSTREAM_PROJECT, W3bstreamProject, {}); + console.log(`Upgrade W3bstreamProject ${process.env.W3BSTREAM_PROJECT} successfull!`); + } + + if (process.env.W3BSTREAM_ROUTER) { + const W3bstreamRouter = await ethers.getContractFactory('W3bstreamRouter'); + await upgrades.upgradeProxy(process.env.W3BSTREAM_ROUTER, W3bstreamRouter, {}); + console.log(`Upgrade W3bstreamRouter ${process.env.W3BSTREAM_ROUTER} successfull!`); + } } main().catch(err => { diff --git a/template/project_file/gnark_sum b/template/project_file/gnark_sum new file mode 100644 index 00000000..eab76659 --- /dev/null +++ b/template/project_file/gnark_sum @@ -0,0 +1,20 @@ +{ + "defaultVersion": "v1", + "config": + [ + { + "version": "v1", + "vmTypeID": 1, + "proofType": "sum", + "signedKeys": + [ + { "name": "timestamp", "type": "uint64" }, + { "name": "value", "type": "uint64" }, + ], + "signatureAlgorithm": "ecdsa", + "hashAlgorithm": "sha256", + "metadata": "http://pub-806f4034ac1b474cb8e146550efa4b2e.r2.dev/w3b/sum.pk", + "code": "http://pub-806f4034ac1b474cb8e146550efa4b2e.r2.dev/w3b/sum.circuit", + }, + ], +}