fluidex / circuits Goto Github PK
View Code? Open in Web Editor NEWLicense: GNU Affero General Public License v3.0
License: GNU Affero General Public License v3.0
plonkit analyse -c ./testdata/Block_2_2_2_2/circuit.r1cs
before reuse https://github.com/Fluidex/circuits/tree/af124e57ca6f4c259999b83a18884e24124addb3
"num_constraints": 78813,
"num_gates": 265703,
after reuse https://github.com/Fluidex/circuits/tree/3c0cdae0bbccf4593a89f07c6f127172aa1a48f7
"num_constraints": 52555,
"num_gates": 161903,
use camelCase
Maybe we wrote something badly? Rescue is not faster inside circuit.
On the other hand, I remember poseidon is faster when doing offline cpu computing...
Rescue needs pow5/invpow5 on field, which is slower than simple multiply on field
By sha256 all the tx data
// do it later
in fact this repo contains following parts:
class TestPlaceOrder implements SimpleTest
this function will be auto run when the wasm module is loaded?
# finished orders can never be used again
order_leaf_to_overwrite = `select order_leaf where state = 'finished' order by id asc limit 1;`
if order_leaf_to_overwrite is None:
# oldest open order is less probable to be used later? heuristic
order_leaf_to_overwrite = `select order_leaf order by id asc limit 1;`
When testing block.circom in #31
[CompileError: WebAssembly.compile(): data segments count of 104626 exceeds internal limit of 100000 @+650474]
It seems that there are too data segments being used
helpers will be used in both this repo's tests and Fluidex's frontend. We should use a "commonjs" repo in the future.
gates profile result of Block(4, 2, 2)
:
main.processTransfer.newSenderHash.hash.mimcs.invpow.pow5 1716.28
main.processTransfer.oldReceiverHash.hash.mimcs.invpow.pow5 1716.28
main.processTransfer.newReceiverHash.hash.mimcs.invpow.pow5 1716.28
main.processWithdraw.oldAccountHash.hash.mimcs.invpow.pow5 1716.28
main.processWithdraw.newAccountHash.hash.mimcs.invpow.pow5 1716.28
main.processDepositToNew.newAccountHash.hash.mimcs.invpow.pow5 1716.57
main.processTransfer.sigVerifier.mulFix.segments.adders 2354.35
main.processWithdraw.sigVerifier.mulFix.segments.adders 2354.35
main.processTransfer.sigVerifier.hash.mimcs.pow 2415.89
main.processWithdraw.sigVerifier.hash.mimcs.pow 2415.89
main.processTransfer.sigVerifier.hash.mimcs.invpow.pow5 2589.78
main.processWithdraw.sigVerifier.hash.mimcs.invpow.pow5 2589.78
main.processTransfer.sigVerifier.mulAny.segments.bits.selector 3870.84
main.processWithdraw.sigVerifier.mulAny.segments.bits.selector 3870.84
main.processTransfer.sigVerifier.mulFix.segments.windows.mux 4332.03
main.processWithdraw.sigVerifier.mulFix.segments.windows.mux 4332.03
main.processTransfer.sigVerifier.mulAny.segments.bits 5329.30
main.processWithdraw.sigVerifier.mulAny.segments.bits 5329.30
main.processTransfer.sigVerifier.mulAny.segments.bits.doubler 5440.06
main.processWithdraw.sigVerifier.mulAny.segments.bits.doubler 5440.06
main.processTransfer.sigVerifier.mulAny.segments.bits.adder 5616.06
main.processWithdraw.sigVerifier.mulAny.segments.bits.adder 5616.06
one 34781.95
total_gates 274159.00
TODO: check whether the gate cost of sigVerifier is reasonable.
wasm tester will be helper for debugging
Add test/circuits & test/global_state to requitred status checks.
We may need 1 more weeks until github recognize them...
The meaning of 'data availability' is to enable proving account
has balance
of token
in the tree. So order details are not needed.
SpotTrade:
AccountID1 4bytes
AccountID2 4bytes
tokenID_1to2 2bytes
tokenID_2to1 2bytes
Amount1to2 3bytes
Amount2to1 3bytes
// NewAccount1OrderRoot
// NewAccount2OrderRoot
// although hash root is only 1 field element, it consumes many bytes in fact. So we prefer use original data
Order1Pos 2bytes
Order1ID 4bytes
Order1BuyAmount 3bytes
Order1SellAmount 3bytes
// Order1SellFilled
// Order1BuyFilled
.. and for order2 ..
So total 42 bytes.
DepositToOld:
AccountID1 4bytes
tokenID1 2bytes
Amount1 3bytes
DepositToNew
AccountID1 4bytes
tokenID1 2bytes
Amount1 3bytes
ethAddr: 20bytes
sign 1bit
ay field: 32 bytes
total: 61bytes
Transfer
AccountID1 4bytes
AccountID2 4bytes
tokenID2bytes
Amount 3bytes
Withdraw
AccountID1 4bytes
tokenID1 2bytes
Amount1 3bytes
eth_address is handled in contract level
ERROR: 6 Signal assigned twice 0 0 0 0
Error: Signal assigned twice 0 0 0 0
at error (/home/chris/gitfiles/Fluidex/circuits/node_modules/circom_runtime/js/witness_calculator.js:51:23)
at setSignal (wasm://wasm/000f95ca:0:27522)
at null.<anonymous> (wasm://wasm/000f95ca:0:28963)
at null.<anonymous> (wasm://wasm/000f95ca:0:26916)
at init (wasm://wasm/000f95ca:0:27116)
at WitnessCalculator._doCalculateWitness (/home/chris/gitfiles/Fluidex/circuits/node_modules/circom_runtime/js/witness_calculator.js:130:31)
at WitnessCalculator.calculateWitness (/home/chris/gitfiles/Fluidex/circuits/node_modules/circom_runtime/js/witness_calculator.js:158:20)
at WasmTester.calculateWitness (/home/chris/gitfiles/Fluidex/circuits/node_modules/circom/ports/wasm/tester.js:57:45)
at Object.testWithInputOutput (/home/chris/gitfiles/Fluidex/circuits/test/tester/wasm.ts:31:33)
at main (/home/chris/gitfiles/Fluidex/circuits/test/test_all.ts:23:5)
c_tester works good
Choose a circuit ( either spotTrade or Block including spotTrade ), get a table with following schema:
Both one core and multi core ( 4 core or 8 core ) ( or real time
/ user time
) results are useful :
time | groth16-zkutil | groth16-rapidsnark | plonk-plonkit |
---|---|---|---|
rescue hash | ?? | ?? | ?? |
poseidon hash | ?? | ?? | ?? |
plonkit should be upgraded to bellman beta branch ( If fully upgrading including solidity stuff costs much time, we can create a branch rather than push unfinished code to plonkit master )
The bench script code may be executed later so it is needed to be commited into the repo. ( We don't need a full auto script. Some manual operations are ok )
https://github.com/Fluidex/circuits/blob/master/tools/replace_hash.sh may be useful.
rapidsnark need a zkey, we may have to generate it.
we should encode amount to Scientific notation (Mantisa & Exponent) for compression
https://github.com/Fluidex/circuits/runs/1892280300
fails but it doesn't report error correctly.
Seems we can fix this following https://github.com/Fluidex/dingir-exchange/blob/94b673330395ef655f933728e025ca4e55ded0df/examples/js/print_orders.js#L35-L39
TODO: create zkey from zkutil output
add a template CalculateRootFromDefaultLeaf(n_levels, leaf)
Order id is like nonce, always incremental. User signed this id.
Meanwhile trade circuit uses idx of order merkle tree to fetch the order info then check trade price/amount against order info.
They are not same thing. After decoupling these two items, we can implement this #104
These are the only valid transition methods:
id
is newer.The above two can be combined if we assume order_id:0 means empty order, real order starts with order id 1.
when testing TestBlock
or TestEmptyBlock
seems we may have infinite recursive loop
also depends on #35
Our recent goal is to run a 300tps rollup test on testnet ( for 1 hour? ), including matching engine, witness generation, proving, contract verification.
here I list some must-to-do for this goal:
Better to do:
Depedency of other repo:
For all things above, we can support 'SpotTrade' first. Implement 'Withdraw/DepositToNew' etc later.
if we want to fit current spot_trade circuit into block circuit, block circuit will be too complicated and tedious
We have different types of op DepositToNew DepositToOld Transfer etc.
As we all know the if else
in circuits is not same to if else
in common programming languages where either if
branch or else
branch will run. if else
in circuits run both branch. It will take more resources ( constraints/gates here ).
So there may be a method to split the op by type then combine them using recursion... More research is needed here.
atm we use exsiting path_elements for "whatever" path_elements
if we can generate empty path_elements, it will benefit nop tx
https://github.com/Fluidex/circuits/runs/2431804240
Seems processTransfer.sigVerifier has some problems...
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.