diff --git a/README.md b/README.md index d0c5ed429..ba14d0ad0 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ ``` -cd legend/circuit/bn254/solidity; +cd circuit/solidity; go test -run TestExportSolGroth16 -count=1 -timeout 99999s ``` @@ -18,7 +18,7 @@ After this command is finished, there will be 3 generated files: `zkbnb.pk_groth ### Exporting plonk proving/verifying key, verifier contract ``` -cd legend/circuit/bn254/solidity; +cd circuit/solidity; go test -run TestExportSolPlonk -count=1 -timeout 99999s ``` diff --git a/accumulators/merkleTree/constants.go b/accumulators/merkleTree/constants.go deleted file mode 100644 index 11b3aaf16..000000000 --- a/accumulators/merkleTree/constants.go +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright © 2021 Zecrey Protocol - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package merkleTree - -import ( - "github.com/ethereum/go-ethereum/common" -) - -var ( - NilHash = common.FromHex("01ef55cdf3b9b0d65e6fb6317f79627534d971fd96c811281af618c0028d5e7a") -) diff --git a/accumulators/merkleTree/errors.go b/accumulators/merkleTree/errors.go deleted file mode 100644 index 883756324..000000000 --- a/accumulators/merkleTree/errors.go +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright © 2021 Zecrey Protocol - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package merkleTree - -import ( - "errors" -) - -var ( - ErrInvalidLeavesSize = errors.New("err: invalid leaves size, should be power of 2") - ErrInvalidIndex = errors.New("err: invalid index") - ErrInvalidMerkleTree = errors.New("err: invalid merkle tree") -) diff --git a/accumulators/merkleTree/utils.go b/accumulators/merkleTree/utils.go deleted file mode 100644 index bf2ad57f3..000000000 --- a/accumulators/merkleTree/utils.go +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright © 2021 Zecrey Protocol - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package merkleTree - -import ( - "github.com/bnb-chain/zkbnb-crypto/hash/bn254/zmimc" -) - -/* -IsPowerOfTwo returns true for arguments that are a power of 2, false otherwise. -https://stackoverflow.com/a/600306/844313 -*/ -func IsPowerOfTwo(x int64) bool { - return (x != 0) && ((x & (x - 1)) == 0) -} - -/* - CopyMerkleProofs: deep copy for merkle proofs -*/ -func CopyMerkleProofs(a [][]byte) [][]byte { - res := make([][]byte, len(a)) - for i := 0; i < len(a); i++ { - res[i] = make([]byte, len(a[i])) - copy(res[i], a[i]) - } - return res -} - -func MockNilHashState(size int) [][]byte { - var hashState [][]byte - h := zmimc.Hmimc - for i := 0; i < size; i++ { - h.Reset() - hashState = append(hashState, h.Sum([]byte{})) - } - return hashState -} diff --git a/legend/circuit/bn254/block/assetDelta.go b/circuit/asset_delta.go similarity index 81% rename from legend/circuit/bn254/block/assetDelta.go rename to circuit/asset_delta.go index 71977f50d..f267622e8 100644 --- a/legend/circuit/bn254/block/assetDelta.go +++ b/circuit/asset_delta.go @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Zecrey Protocol + * Copyright © 2022 ZkBNB Protocol * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,12 +15,12 @@ * */ -package block +package circuit import ( "github.com/consensys/gnark/std/signature/eddsa" - "github.com/bnb-chain/zkbnb-crypto/legend/circuit/bn254/std" + "github.com/bnb-chain/zkbnb-crypto/circuit/types" ) type AccountDeltaConstraints struct { @@ -36,17 +36,17 @@ type AccountAssetDeltaConstraints struct { func EmptyAccountAssetDeltaConstraints() AccountAssetDeltaConstraints { return AccountAssetDeltaConstraints{ - BalanceDelta: std.ZeroInt, - LpDelta: std.ZeroInt, - OfferCanceledOrFinalized: std.ZeroInt, + BalanceDelta: types.ZeroInt, + LpDelta: types.ZeroInt, + OfferCanceledOrFinalized: types.ZeroInt, } } func UpdateAccounts( api API, - accountInfos [NbAccountsPerTx]std.AccountConstraints, + accountInfos [NbAccountsPerTx]types.AccountConstraints, accountDeltas [NbAccountsPerTx][NbAccountAssetsPerAccount]AccountAssetDeltaConstraints, -) (AccountsInfoAfter [NbAccountsPerTx]std.AccountConstraints) { +) (AccountsInfoAfter [NbAccountsPerTx]types.AccountConstraints) { AccountsInfoAfter = accountInfos for i := 0; i < NbAccountsPerTx; i++ { for j := 0; j < NbAccountAssetsPerAccount; j++ { @@ -84,10 +84,10 @@ func GetLiquidityDeltaFromCreatePair( liquidityDelta = LiquidityDeltaConstraints{ AssetAId: txInfo.AssetAId, AssetBId: txInfo.AssetBId, - AssetADelta: std.ZeroInt, - AssetBDelta: std.ZeroInt, - LpDelta: std.ZeroInt, - KLast: std.ZeroInt, + AssetADelta: types.ZeroInt, + AssetBDelta: types.ZeroInt, + LpDelta: types.ZeroInt, + KLast: types.ZeroInt, FeeRate: txInfo.FeeRate, TreasuryAccountIndex: txInfo.TreasuryAccountIndex, TreasuryRate: txInfo.TreasuryRate, @@ -102,9 +102,9 @@ func GetLiquidityDeltaFromUpdatePairRate( liquidityDelta = LiquidityDeltaConstraints{ AssetAId: liquidityBefore.AssetAId, AssetBId: liquidityBefore.AssetBId, - AssetADelta: std.ZeroInt, - AssetBDelta: std.ZeroInt, - LpDelta: std.ZeroInt, + AssetADelta: types.ZeroInt, + AssetBDelta: types.ZeroInt, + LpDelta: types.ZeroInt, KLast: liquidityBefore.KLast, FeeRate: txInfo.FeeRate, TreasuryAccountIndex: txInfo.TreasuryAccountIndex, @@ -119,8 +119,8 @@ func GetAssetDeltasFromDeposit( deltas[0] = [NbAccountAssetsPerAccount]AccountAssetDeltaConstraints{ { BalanceDelta: txInfo.AssetAmount, - LpDelta: std.ZeroInt, - OfferCanceledOrFinalized: std.ZeroInt, + LpDelta: types.ZeroInt, + OfferCanceledOrFinalized: types.ZeroInt, }, EmptyAccountAssetDeltaConstraints(), EmptyAccountAssetDeltaConstraints(), @@ -145,8 +145,8 @@ func GetAssetDeltasFromCreateCollection( deltas[0] = [NbAccountAssetsPerAccount]AccountAssetDeltaConstraints{ { BalanceDelta: api.Neg(txInfo.GasFeeAssetAmount), - LpDelta: std.ZeroInt, - OfferCanceledOrFinalized: std.ZeroInt, + LpDelta: types.ZeroInt, + OfferCanceledOrFinalized: types.ZeroInt, }, EmptyAccountAssetDeltaConstraints(), EmptyAccountAssetDeltaConstraints(), @@ -156,8 +156,8 @@ func GetAssetDeltasFromCreateCollection( deltas[1] = [NbAccountAssetsPerAccount]AccountAssetDeltaConstraints{ { BalanceDelta: txInfo.GasFeeAssetAmount, - LpDelta: std.ZeroInt, - OfferCanceledOrFinalized: std.ZeroInt, + LpDelta: types.ZeroInt, + OfferCanceledOrFinalized: types.ZeroInt, }, EmptyAccountAssetDeltaConstraints(), EmptyAccountAssetDeltaConstraints(), @@ -198,14 +198,14 @@ func GetAssetDeltasFromTransfer( // asset A { BalanceDelta: api.Neg(txInfo.AssetAmount), - LpDelta: std.ZeroInt, - OfferCanceledOrFinalized: std.ZeroInt, + LpDelta: types.ZeroInt, + OfferCanceledOrFinalized: types.ZeroInt, }, // asset Gas { BalanceDelta: api.Neg(txInfo.GasFeeAssetAmount), - LpDelta: std.ZeroInt, - OfferCanceledOrFinalized: std.ZeroInt, + LpDelta: types.ZeroInt, + OfferCanceledOrFinalized: types.ZeroInt, }, EmptyAccountAssetDeltaConstraints(), EmptyAccountAssetDeltaConstraints(), @@ -214,8 +214,8 @@ func GetAssetDeltasFromTransfer( deltas[1] = [NbAccountAssetsPerAccount]AccountAssetDeltaConstraints{ { BalanceDelta: txInfo.AssetAmount, - LpDelta: std.ZeroInt, - OfferCanceledOrFinalized: std.ZeroInt, + LpDelta: types.ZeroInt, + OfferCanceledOrFinalized: types.ZeroInt, }, EmptyAccountAssetDeltaConstraints(), EmptyAccountAssetDeltaConstraints(), @@ -225,8 +225,8 @@ func GetAssetDeltasFromTransfer( deltas[2] = [NbAccountAssetsPerAccount]AccountAssetDeltaConstraints{ { BalanceDelta: txInfo.GasFeeAssetAmount, - LpDelta: std.ZeroInt, - OfferCanceledOrFinalized: std.ZeroInt, + LpDelta: types.ZeroInt, + OfferCanceledOrFinalized: types.ZeroInt, }, EmptyAccountAssetDeltaConstraints(), EmptyAccountAssetDeltaConstraints(), @@ -254,20 +254,20 @@ func GetAssetDeltasAndLiquidityDeltaFromSwap( // asset A { BalanceDelta: api.Neg(txInfo.AssetAAmount), - LpDelta: std.ZeroInt, - OfferCanceledOrFinalized: std.ZeroInt, + LpDelta: types.ZeroInt, + OfferCanceledOrFinalized: types.ZeroInt, }, // asset B { BalanceDelta: txInfo.AssetBAmountDelta, - LpDelta: std.ZeroInt, - OfferCanceledOrFinalized: std.ZeroInt, + LpDelta: types.ZeroInt, + OfferCanceledOrFinalized: types.ZeroInt, }, // asset gas { BalanceDelta: api.Neg(txInfo.GasFeeAssetAmount), - LpDelta: std.ZeroInt, - OfferCanceledOrFinalized: std.ZeroInt, + LpDelta: types.ZeroInt, + OfferCanceledOrFinalized: types.ZeroInt, }, EmptyAccountAssetDeltaConstraints(), } @@ -276,8 +276,8 @@ func GetAssetDeltasAndLiquidityDeltaFromSwap( // asset gas { BalanceDelta: txInfo.GasFeeAssetAmount, - LpDelta: std.ZeroInt, - OfferCanceledOrFinalized: std.ZeroInt, + LpDelta: types.ZeroInt, + OfferCanceledOrFinalized: types.ZeroInt, }, EmptyAccountAssetDeltaConstraints(), EmptyAccountAssetDeltaConstraints(), @@ -300,7 +300,7 @@ func GetAssetDeltasAndLiquidityDeltaFromSwap( AssetBId: liquidityBefore.AssetBId, AssetADelta: assetADelta, AssetBDelta: assetBDelta, - LpDelta: std.ZeroInt, + LpDelta: types.ZeroInt, KLast: liquidityBefore.KLast, FeeRate: liquidityBefore.FeeRate, TreasuryAccountIndex: liquidityBefore.TreasuryAccountIndex, @@ -309,7 +309,6 @@ func GetAssetDeltasAndLiquidityDeltaFromSwap( return deltas, liquidityDelta } -// TODO treasury lp func GetAssetDeltasAndLiquidityDeltaFromAddLiquidity( api API, txInfo AddLiquidityTxConstraints, @@ -320,34 +319,34 @@ func GetAssetDeltasAndLiquidityDeltaFromAddLiquidity( // asset A { BalanceDelta: api.Neg(txInfo.AssetAAmount), - LpDelta: std.ZeroInt, - OfferCanceledOrFinalized: std.ZeroInt, + LpDelta: types.ZeroInt, + OfferCanceledOrFinalized: types.ZeroInt, }, // asset B { BalanceDelta: api.Neg(txInfo.AssetBAmount), - LpDelta: std.ZeroInt, - OfferCanceledOrFinalized: std.ZeroInt, + LpDelta: types.ZeroInt, + OfferCanceledOrFinalized: types.ZeroInt, }, // asset gas { BalanceDelta: api.Neg(txInfo.GasFeeAssetAmount), - LpDelta: std.ZeroInt, - OfferCanceledOrFinalized: std.ZeroInt, + LpDelta: types.ZeroInt, + OfferCanceledOrFinalized: types.ZeroInt, }, // asset lp { - BalanceDelta: std.ZeroInt, + BalanceDelta: types.ZeroInt, LpDelta: txInfo.LpAmount, - OfferCanceledOrFinalized: std.ZeroInt, + OfferCanceledOrFinalized: types.ZeroInt, }, } // treasury account deltas[1] = [NbAccountAssetsPerAccount]AccountAssetDeltaConstraints{ { - BalanceDelta: std.ZeroInt, + BalanceDelta: types.ZeroInt, LpDelta: txInfo.TreasuryAmount, - OfferCanceledOrFinalized: std.ZeroInt, + OfferCanceledOrFinalized: types.ZeroInt, }, EmptyAccountAssetDeltaConstraints(), EmptyAccountAssetDeltaConstraints(), @@ -357,8 +356,8 @@ func GetAssetDeltasAndLiquidityDeltaFromAddLiquidity( deltas[2] = [NbAccountAssetsPerAccount]AccountAssetDeltaConstraints{ { BalanceDelta: txInfo.GasFeeAssetAmount, - LpDelta: std.ZeroInt, - OfferCanceledOrFinalized: std.ZeroInt, + LpDelta: types.ZeroInt, + OfferCanceledOrFinalized: types.ZeroInt, }, EmptyAccountAssetDeltaConstraints(), EmptyAccountAssetDeltaConstraints(), @@ -388,7 +387,6 @@ func GetAssetDeltasAndLiquidityDeltaFromAddLiquidity( return deltas, liquidityDelta } -// TODO treasury lp func GetAssetDeltasAndLiquidityDeltaFromRemoveLiquidity( api API, txInfo RemoveLiquidityTxConstraints, @@ -399,34 +397,34 @@ func GetAssetDeltasAndLiquidityDeltaFromRemoveLiquidity( // asset A { BalanceDelta: txInfo.AssetAAmountDelta, - LpDelta: std.ZeroInt, - OfferCanceledOrFinalized: std.ZeroInt, + LpDelta: types.ZeroInt, + OfferCanceledOrFinalized: types.ZeroInt, }, // asset B { BalanceDelta: txInfo.AssetBAmountDelta, - LpDelta: std.ZeroInt, - OfferCanceledOrFinalized: std.ZeroInt, + LpDelta: types.ZeroInt, + OfferCanceledOrFinalized: types.ZeroInt, }, // asset gas { BalanceDelta: api.Neg(txInfo.GasFeeAssetAmount), - LpDelta: std.ZeroInt, - OfferCanceledOrFinalized: std.ZeroInt, + LpDelta: types.ZeroInt, + OfferCanceledOrFinalized: types.ZeroInt, }, // asset lp { - BalanceDelta: std.ZeroInt, + BalanceDelta: types.ZeroInt, LpDelta: api.Neg(txInfo.LpAmount), - OfferCanceledOrFinalized: std.ZeroInt, + OfferCanceledOrFinalized: types.ZeroInt, }, } // treasury account deltas[1] = [NbAccountAssetsPerAccount]AccountAssetDeltaConstraints{ { - BalanceDelta: std.ZeroInt, + BalanceDelta: types.ZeroInt, LpDelta: txInfo.TreasuryAmount, - OfferCanceledOrFinalized: std.ZeroInt, + OfferCanceledOrFinalized: types.ZeroInt, }, EmptyAccountAssetDeltaConstraints(), EmptyAccountAssetDeltaConstraints(), @@ -436,8 +434,8 @@ func GetAssetDeltasAndLiquidityDeltaFromRemoveLiquidity( deltas[2] = [NbAccountAssetsPerAccount]AccountAssetDeltaConstraints{ { BalanceDelta: txInfo.GasFeeAssetAmount, - LpDelta: std.ZeroInt, - OfferCanceledOrFinalized: std.ZeroInt, + LpDelta: types.ZeroInt, + OfferCanceledOrFinalized: types.ZeroInt, }, EmptyAccountAssetDeltaConstraints(), EmptyAccountAssetDeltaConstraints(), @@ -476,14 +474,14 @@ func GetAssetDeltasFromWithdraw( // asset A { BalanceDelta: api.Neg(txInfo.AssetAmount), - LpDelta: std.ZeroInt, - OfferCanceledOrFinalized: std.ZeroInt, + LpDelta: types.ZeroInt, + OfferCanceledOrFinalized: types.ZeroInt, }, // asset gas { BalanceDelta: api.Neg(txInfo.GasFeeAssetAmount), - LpDelta: std.ZeroInt, - OfferCanceledOrFinalized: std.ZeroInt, + LpDelta: types.ZeroInt, + OfferCanceledOrFinalized: types.ZeroInt, }, EmptyAccountAssetDeltaConstraints(), EmptyAccountAssetDeltaConstraints(), @@ -492,8 +490,8 @@ func GetAssetDeltasFromWithdraw( deltas[1] = [NbAccountAssetsPerAccount]AccountAssetDeltaConstraints{ { BalanceDelta: txInfo.GasFeeAssetAmount, - LpDelta: std.ZeroInt, - OfferCanceledOrFinalized: std.ZeroInt, + LpDelta: types.ZeroInt, + OfferCanceledOrFinalized: types.ZeroInt, }, EmptyAccountAssetDeltaConstraints(), EmptyAccountAssetDeltaConstraints(), @@ -518,8 +516,8 @@ func GetAssetDeltasAndNftDeltaFromMintNft( deltas[0] = [NbAccountAssetsPerAccount]AccountAssetDeltaConstraints{ { BalanceDelta: api.Neg(txInfo.GasFeeAssetAmount), - LpDelta: std.ZeroInt, - OfferCanceledOrFinalized: std.ZeroInt, + LpDelta: types.ZeroInt, + OfferCanceledOrFinalized: types.ZeroInt, }, EmptyAccountAssetDeltaConstraints(), EmptyAccountAssetDeltaConstraints(), @@ -534,8 +532,8 @@ func GetAssetDeltasAndNftDeltaFromMintNft( deltas[2] = [NbAccountAssetsPerAccount]AccountAssetDeltaConstraints{ { BalanceDelta: txInfo.GasFeeAssetAmount, - LpDelta: std.ZeroInt, - OfferCanceledOrFinalized: std.ZeroInt, + LpDelta: types.ZeroInt, + OfferCanceledOrFinalized: types.ZeroInt, }, EmptyAccountAssetDeltaConstraints(), EmptyAccountAssetDeltaConstraints(), @@ -553,8 +551,8 @@ func GetAssetDeltasAndNftDeltaFromMintNft( CreatorAccountIndex: txInfo.CreatorAccountIndex, OwnerAccountIndex: txInfo.ToAccountIndex, NftContentHash: txInfo.NftContentHash, - NftL1Address: std.ZeroInt, - NftL1TokenId: std.ZeroInt, + NftL1Address: types.ZeroInt, + NftL1TokenId: types.ZeroInt, CreatorTreasuryRate: txInfo.CreatorTreasuryRate, CollectionId: txInfo.CollectionId, } @@ -570,8 +568,8 @@ func GetAssetDeltasAndNftDeltaFromTransferNft( deltas[0] = [NbAccountAssetsPerAccount]AccountAssetDeltaConstraints{ { BalanceDelta: api.Neg(txInfo.GasFeeAssetAmount), - LpDelta: std.ZeroInt, - OfferCanceledOrFinalized: std.ZeroInt, + LpDelta: types.ZeroInt, + OfferCanceledOrFinalized: types.ZeroInt, }, EmptyAccountAssetDeltaConstraints(), EmptyAccountAssetDeltaConstraints(), @@ -587,8 +585,8 @@ func GetAssetDeltasAndNftDeltaFromTransferNft( deltas[2] = [NbAccountAssetsPerAccount]AccountAssetDeltaConstraints{ { BalanceDelta: txInfo.GasFeeAssetAmount, - LpDelta: std.ZeroInt, - OfferCanceledOrFinalized: std.ZeroInt, + LpDelta: types.ZeroInt, + OfferCanceledOrFinalized: types.ZeroInt, }, EmptyAccountAssetDeltaConstraints(), EmptyAccountAssetDeltaConstraints(), @@ -614,20 +612,19 @@ func GetAssetDeltasAndNftDeltaFromTransferNft( return deltas, nftDelta } -// TODO creator & treasury fee func GetAssetDeltasAndNftDeltaFromAtomicMatch( api API, flag Variable, txInfo AtomicMatchTxConstraints, - accountsBefore [NbAccountsPerTx]std.AccountConstraints, + accountsBefore [NbAccountsPerTx]types.AccountConstraints, nftBefore NftConstraints, ) (deltas [NbAccountsPerTx][NbAccountAssetsPerAccount]AccountAssetDeltaConstraints, nftDelta NftDeltaConstraints) { // submitter deltas[0] = [NbAccountAssetsPerAccount]AccountAssetDeltaConstraints{ { BalanceDelta: api.Neg(txInfo.GasFeeAssetAmount), - LpDelta: std.ZeroInt, - OfferCanceledOrFinalized: std.ZeroInt, + LpDelta: types.ZeroInt, + OfferCanceledOrFinalized: types.ZeroInt, }, EmptyAccountAssetDeltaConstraints(), EmptyAccountAssetDeltaConstraints(), @@ -642,10 +639,10 @@ func GetAssetDeltasAndNftDeltaFromAtomicMatch( buyerDelta := api.Neg(txInfo.BuyOffer.AssetAmount) sellerDelta := sellerAmount // buyer - buyOfferIdBits := api.ToBinary(txInfo.BuyOffer.OfferId, 24) + buyOfferIdBits := api.ToBinary(txInfo.BuyOffer.OfferId, 23) buyAssetId := api.FromBinary(buyOfferIdBits[7:]...) buyOfferIndex := api.Sub(txInfo.BuyOffer.OfferId, api.Mul(buyAssetId, OfferSizePerAsset)) - buyOfferBits := api.ToBinary(accountsBefore[1].AssetsInfo[0].OfferCanceledOrFinalized) + buyOfferBits := api.ToBinary(accountsBefore[1].AssetsInfo[1].OfferCanceledOrFinalized) // TODO need to optimize here for i := 0; i < OfferSizePerAsset; i++ { isZero := api.IsZero(api.Sub(buyOfferIndex, i)) @@ -656,22 +653,22 @@ func GetAssetDeltasAndNftDeltaFromAtomicMatch( deltas[1] = [NbAccountAssetsPerAccount]AccountAssetDeltaConstraints{ { BalanceDelta: buyerDelta, - LpDelta: std.ZeroInt, - OfferCanceledOrFinalized: std.ZeroInt, + LpDelta: types.ZeroInt, + OfferCanceledOrFinalized: types.ZeroInt, }, { - BalanceDelta: std.ZeroInt, - LpDelta: std.ZeroInt, + BalanceDelta: types.ZeroInt, + LpDelta: types.ZeroInt, OfferCanceledOrFinalized: buyOfferCanceledOrFinalized, }, EmptyAccountAssetDeltaConstraints(), EmptyAccountAssetDeltaConstraints(), } // sell - sellOfferIdBits := api.ToBinary(txInfo.SellOffer.OfferId, 24) + sellOfferIdBits := api.ToBinary(txInfo.SellOffer.OfferId, 23) sellAssetId := api.FromBinary(sellOfferIdBits[7:]...) sellOfferIndex := api.Sub(txInfo.SellOffer.OfferId, api.Mul(sellAssetId, OfferSizePerAsset)) - sellOfferBits := api.ToBinary(accountsBefore[2].AssetsInfo[0].OfferCanceledOrFinalized) + sellOfferBits := api.ToBinary(accountsBefore[2].AssetsInfo[1].OfferCanceledOrFinalized) // TODO need to optimize here for i := 0; i < OfferSizePerAsset; i++ { isZero := api.IsZero(api.Sub(sellOfferIndex, i)) @@ -682,12 +679,12 @@ func GetAssetDeltasAndNftDeltaFromAtomicMatch( deltas[2] = [NbAccountAssetsPerAccount]AccountAssetDeltaConstraints{ { BalanceDelta: sellerDelta, - LpDelta: std.ZeroInt, - OfferCanceledOrFinalized: std.ZeroInt, + LpDelta: types.ZeroInt, + OfferCanceledOrFinalized: types.ZeroInt, }, { - BalanceDelta: std.ZeroInt, - LpDelta: std.ZeroInt, + BalanceDelta: types.ZeroInt, + LpDelta: types.ZeroInt, OfferCanceledOrFinalized: sellOfferCanceledOrFinalized, }, EmptyAccountAssetDeltaConstraints(), @@ -698,8 +695,8 @@ func GetAssetDeltasAndNftDeltaFromAtomicMatch( // asset A { BalanceDelta: creatorAmountVar, - LpDelta: std.ZeroInt, - OfferCanceledOrFinalized: std.ZeroInt, + LpDelta: types.ZeroInt, + OfferCanceledOrFinalized: types.ZeroInt, }, EmptyAccountAssetDeltaConstraints(), EmptyAccountAssetDeltaConstraints(), @@ -710,14 +707,14 @@ func GetAssetDeltasAndNftDeltaFromAtomicMatch( // asset A { BalanceDelta: treasuryAmountVar, - LpDelta: std.ZeroInt, - OfferCanceledOrFinalized: std.ZeroInt, + LpDelta: types.ZeroInt, + OfferCanceledOrFinalized: types.ZeroInt, }, // asset Gas { BalanceDelta: txInfo.GasFeeAssetAmount, - LpDelta: std.ZeroInt, - OfferCanceledOrFinalized: std.ZeroInt, + LpDelta: types.ZeroInt, + OfferCanceledOrFinalized: types.ZeroInt, }, EmptyAccountAssetDeltaConstraints(), EmptyAccountAssetDeltaConstraints(), @@ -738,7 +735,7 @@ func GetAssetDeltasFromCancelOffer( api API, flag Variable, txInfo CancelOfferTxConstraints, - accountsBefore [NbAccountsPerTx]std.AccountConstraints, + accountsBefore [NbAccountsPerTx]types.AccountConstraints, ) (deltas [NbAccountsPerTx][NbAccountAssetsPerAccount]AccountAssetDeltaConstraints) { // from account offerIdBits := api.ToBinary(txInfo.OfferId, 24) @@ -756,12 +753,12 @@ func GetAssetDeltasFromCancelOffer( // asset Gas { BalanceDelta: api.Neg(txInfo.GasFeeAssetAmount), - LpDelta: std.ZeroInt, - OfferCanceledOrFinalized: std.ZeroInt, + LpDelta: types.ZeroInt, + OfferCanceledOrFinalized: types.ZeroInt, }, { - BalanceDelta: std.ZeroInt, - LpDelta: std.ZeroInt, + BalanceDelta: types.ZeroInt, + LpDelta: types.ZeroInt, OfferCanceledOrFinalized: fromOfferCanceledOrFinalized, }, EmptyAccountAssetDeltaConstraints(), @@ -771,8 +768,8 @@ func GetAssetDeltasFromCancelOffer( deltas[1] = [NbAccountAssetsPerAccount]AccountAssetDeltaConstraints{ { BalanceDelta: txInfo.GasFeeAssetAmount, - LpDelta: std.ZeroInt, - OfferCanceledOrFinalized: std.ZeroInt, + LpDelta: types.ZeroInt, + OfferCanceledOrFinalized: types.ZeroInt, }, EmptyAccountAssetDeltaConstraints(), EmptyAccountAssetDeltaConstraints(), @@ -797,8 +794,8 @@ func GetAssetDeltasAndNftDeltaFromWithdrawNft( deltas[0] = [NbAccountAssetsPerAccount]AccountAssetDeltaConstraints{ { BalanceDelta: api.Neg(txInfo.GasFeeAssetAmount), - LpDelta: std.ZeroInt, - OfferCanceledOrFinalized: std.ZeroInt, + LpDelta: types.ZeroInt, + OfferCanceledOrFinalized: types.ZeroInt, }, EmptyAccountAssetDeltaConstraints(), EmptyAccountAssetDeltaConstraints(), @@ -815,8 +812,8 @@ func GetAssetDeltasAndNftDeltaFromWithdrawNft( deltas[2] = [NbAccountAssetsPerAccount]AccountAssetDeltaConstraints{ { BalanceDelta: txInfo.GasFeeAssetAmount, - LpDelta: std.ZeroInt, - OfferCanceledOrFinalized: std.ZeroInt, + LpDelta: types.ZeroInt, + OfferCanceledOrFinalized: types.ZeroInt, }, EmptyAccountAssetDeltaConstraints(), EmptyAccountAssetDeltaConstraints(), @@ -831,13 +828,13 @@ func GetAssetDeltasAndNftDeltaFromWithdrawNft( } } nftDelta = NftDeltaConstraints{ - CreatorAccountIndex: std.ZeroInt, - OwnerAccountIndex: std.ZeroInt, - NftContentHash: std.ZeroInt, - NftL1Address: std.ZeroInt, - NftL1TokenId: std.ZeroInt, - CreatorTreasuryRate: std.ZeroInt, - CollectionId: std.ZeroInt, + CreatorAccountIndex: types.ZeroInt, + OwnerAccountIndex: types.ZeroInt, + NftContentHash: types.ZeroInt, + NftL1Address: types.ZeroInt, + NftL1TokenId: types.ZeroInt, + CreatorTreasuryRate: types.ZeroInt, + CollectionId: types.ZeroInt, } return deltas, nftDelta } @@ -850,8 +847,8 @@ func GetAssetDeltasFromFullExit( deltas[0] = [NbAccountAssetsPerAccount]AccountAssetDeltaConstraints{ { BalanceDelta: api.Neg(txInfo.AssetAmount), - LpDelta: std.ZeroInt, - OfferCanceledOrFinalized: std.ZeroInt, + LpDelta: types.ZeroInt, + OfferCanceledOrFinalized: types.ZeroInt, }, EmptyAccountAssetDeltaConstraints(), EmptyAccountAssetDeltaConstraints(), @@ -870,13 +867,13 @@ func GetAssetDeltasFromFullExit( func GetNftDeltaFromFullExitNft() (nftDelta NftDeltaConstraints) { nftDelta = NftDeltaConstraints{ - CreatorAccountIndex: std.ZeroInt, - OwnerAccountIndex: std.ZeroInt, - NftContentHash: std.ZeroInt, - NftL1Address: std.ZeroInt, - NftL1TokenId: std.ZeroInt, - CreatorTreasuryRate: std.ZeroInt, - CollectionId: std.ZeroInt, + CreatorAccountIndex: types.ZeroInt, + OwnerAccountIndex: types.ZeroInt, + NftContentHash: types.ZeroInt, + NftL1Address: types.ZeroInt, + NftL1TokenId: types.ZeroInt, + CreatorTreasuryRate: types.ZeroInt, + CollectionId: types.ZeroInt, } return nftDelta } diff --git a/legend/circuit/bn254/block/block.go b/circuit/block.go similarity index 93% rename from legend/circuit/bn254/block/block.go rename to circuit/block.go index 02233aa78..2bdf73b63 100644 --- a/legend/circuit/bn254/block/block.go +++ b/circuit/block.go @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Zecrey Protocol + * Copyright © 2022 ZkBNB Protocol * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,7 +15,7 @@ * */ -package block +package circuit type Block struct { BlockNumber int64 diff --git a/legend/circuit/bn254/block/block_addLiquidity_test.go b/circuit/block_add_liquidity_test.go similarity index 99% rename from legend/circuit/bn254/block/block_addLiquidity_test.go rename to circuit/block_add_liquidity_test.go index e76f54114..d1d1b9482 100644 --- a/legend/circuit/bn254/block/block_addLiquidity_test.go +++ b/circuit/block_add_liquidity_test.go @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Zecrey Protocol + * Copyright © 2022 ZkBNB Protocol * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,7 +15,7 @@ * */ -package block +package circuit import ( "encoding/json" @@ -26,7 +26,7 @@ import ( "github.com/consensys/gnark/frontend" "github.com/consensys/gnark/test" - "github.com/bnb-chain/zkbnb-crypto/legend/circuit/bn254/std" + "github.com/bnb-chain/zkbnb-crypto/circuit/types" ) func TestVerifyBlock_AddLiquidity(t *testing.T) { @@ -45,6 +45,6 @@ func TestVerifyBlock_AddLiquidity(t *testing.T) { assert.SolvingSucceeded( &circuit, &witness, test.WithBackends(backend.GROTH16), test.WithCurves(ecc.BN254), - test.WithProverOpts(backend.WithHints(std.Keccak256, std.ComputeSLp)), + test.WithProverOpts(backend.WithHints(types.Keccak256, types.ComputeSLp)), test.WithCompileOpts(frontend.IgnoreUnconstrainedInputs())) } diff --git a/legend/circuit/bn254/block/block_atomicMatch_test.go b/circuit/block_atomic_match_test.go similarity index 99% rename from legend/circuit/bn254/block/block_atomicMatch_test.go rename to circuit/block_atomic_match_test.go index 19f82823c..041defab4 100644 --- a/legend/circuit/bn254/block/block_atomicMatch_test.go +++ b/circuit/block_atomic_match_test.go @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Zecrey Protocol + * Copyright © 2022 ZkBNB Protocol * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,7 +15,7 @@ * */ -package block +package circuit import ( "encoding/json" @@ -26,7 +26,7 @@ import ( "github.com/consensys/gnark/frontend" "github.com/consensys/gnark/test" - "github.com/bnb-chain/zkbnb-crypto/legend/circuit/bn254/std" + "github.com/bnb-chain/zkbnb-crypto/circuit/types" ) func TestVerifyBlock_AtomicMatch(t *testing.T) { @@ -45,6 +45,6 @@ func TestVerifyBlock_AtomicMatch(t *testing.T) { assert.SolvingSucceeded( &circuit, &witness, test.WithBackends(backend.GROTH16), test.WithCurves(ecc.BN254), - test.WithProverOpts(backend.WithHints(std.Keccak256, std.ComputeSLp)), + test.WithProverOpts(backend.WithHints(types.Keccak256, types.ComputeSLp)), test.WithCompileOpts(frontend.IgnoreUnconstrainedInputs())) } diff --git a/legend/circuit/bn254/block/block_cancelOffer_test.go b/circuit/block_cancel_offer_test.go similarity index 99% rename from legend/circuit/bn254/block/block_cancelOffer_test.go rename to circuit/block_cancel_offer_test.go index dffdf6af5..464f93777 100644 --- a/legend/circuit/bn254/block/block_cancelOffer_test.go +++ b/circuit/block_cancel_offer_test.go @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Zecrey Protocol + * Copyright © 2022 ZkBNB Protocol * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,7 +15,7 @@ * */ -package block +package circuit import ( "encoding/json" @@ -26,7 +26,7 @@ import ( "github.com/consensys/gnark/frontend" "github.com/consensys/gnark/test" - "github.com/bnb-chain/zkbnb-crypto/legend/circuit/bn254/std" + "github.com/bnb-chain/zkbnb-crypto/circuit/types" ) func TestVerifyBlock_CancelOffer(t *testing.T) { @@ -45,6 +45,6 @@ func TestVerifyBlock_CancelOffer(t *testing.T) { assert.SolvingSucceeded( &circuit, &witness, test.WithBackends(backend.GROTH16), test.WithCurves(ecc.BN254), - test.WithProverOpts(backend.WithHints(std.Keccak256, std.ComputeSLp)), + test.WithProverOpts(backend.WithHints(types.Keccak256, types.ComputeSLp)), test.WithCompileOpts(frontend.IgnoreUnconstrainedInputs())) } diff --git a/legend/circuit/bn254/block/blockConstraints.go b/circuit/block_constraints.go similarity index 72% rename from legend/circuit/bn254/block/blockConstraints.go rename to circuit/block_constraints.go index 7913476d9..1b04b5a1d 100644 --- a/legend/circuit/bn254/block/blockConstraints.go +++ b/circuit/block_constraints.go @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Zecrey Protocol + * Copyright © 2022 ZkBNB Protocol * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,14 +15,14 @@ * */ -package block +package circuit import ( "log" "github.com/consensys/gnark/std/hash/mimc" - "github.com/bnb-chain/zkbnb-crypto/legend/circuit/bn254/std" + "github.com/bnb-chain/zkbnb-crypto/circuit/types" ) type BlockConstraints struct { @@ -66,38 +66,38 @@ func VerifyBlock( // pendingCommitmentData [std.PubDataSizePerTx*block.TxsCount + 5]Variable count = 4 ) - pendingCommitmentData := make([]Variable, std.PubDataSizePerTx*block.TxsCount+5) + pendingCommitmentData := make([]Variable, types.PubDataSizePerTx*block.TxsCount+5) // write basic info into hFunc pendingCommitmentData[0] = block.BlockNumber pendingCommitmentData[1] = block.CreatedAt pendingCommitmentData[2] = block.OldStateRoot pendingCommitmentData[3] = block.NewStateRoot api.AssertIsEqual(block.OldStateRoot, block.Txs[0].StateRootBefore) - isEmptyTx := api.IsZero(api.Sub(block.Txs[block.TxsCount-1].TxType, std.TxTypeEmptyTx)) + isEmptyTx := api.IsZero(api.Sub(block.Txs[block.TxsCount-1].TxType, types.TxTypeEmptyTx)) notEmptyTx := api.IsZero(isEmptyTx) - std.IsVariableEqual(api, notEmptyTx, block.NewStateRoot, block.Txs[block.TxsCount-1].StateRootAfter) + types.IsVariableEqual(api, notEmptyTx, block.NewStateRoot, block.Txs[block.TxsCount-1].StateRootAfter) onChainOpsCount = 0 isOnChainOp, pendingPubData, err := VerifyTransaction(api, block.Txs[0], hFunc, block.CreatedAt) if err != nil { log.Println("[VerifyBlock] unable to verify block:", err) return err } - for i := 0; i < std.PubDataSizePerTx; i++ { + for i := 0; i < types.PubDataSizePerTx; i++ { pendingCommitmentData[count] = pendingPubData[i] count++ } onChainOpsCount = api.Add(onChainOpsCount, isOnChainOp) - for i := 1; i < int(block.TxsCount); i++ { - isEmptyTx := api.IsZero(api.Sub(block.Txs[i].TxType, std.TxTypeEmptyTx)) + for i := 1; i < block.TxsCount; i++ { + isEmptyTx := api.IsZero(api.Sub(block.Txs[i].TxType, types.TxTypeEmptyTx)) notEmptyTx := api.IsZero(isEmptyTx) - std.IsVariableEqual(api, notEmptyTx, block.Txs[i-1].StateRootAfter, block.Txs[i].StateRootBefore) + types.IsVariableEqual(api, notEmptyTx, block.Txs[i-1].StateRootAfter, block.Txs[i].StateRootBefore) hFunc.Reset() isOnChainOp, pendingPubData, err = VerifyTransaction(api, block.Txs[i], hFunc, block.CreatedAt) if err != nil { log.Println("[VerifyBlock] unable to verify block:", err) return err } - for j := 0; j < std.PubDataSizePerTx; j++ { + for j := 0; j < types.PubDataSizePerTx; j++ { pendingCommitmentData[count] = pendingPubData[j] count++ } @@ -105,7 +105,7 @@ func VerifyBlock( } pendingCommitmentData[count] = onChainOpsCount //commitment := pubdataHashFunc.Sum() - commitments, _ := api.Compiler().NewHint(std.Keccak256, 1, pendingCommitmentData[:]...) + commitments, _ := api.Compiler().NewHint(types.Keccak256, 1, pendingCommitmentData[:]...) api.AssertIsEqual(commitments[0], block.BlockCommitment) return nil } @@ -132,24 +132,24 @@ func SetBlockWitness(oBlock *Block) (witness BlockConstraints, err error) { func GetZeroTxConstraint() TxConstraints { var zeroTxConstraint TxConstraints zeroTxConstraint.TxType = 0 - zeroTxConstraint.RegisterZnsTxInfo = std.EmptyRegisterZnsTxWitness() - zeroTxConstraint.CreatePairTxInfo = std.EmptyCreatePairTxWitness() - zeroTxConstraint.UpdatePairRateTxInfo = std.EmptyUpdatePairRateTxWitness() - zeroTxConstraint.DepositTxInfo = std.EmptyDepositTxWitness() - zeroTxConstraint.DepositNftTxInfo = std.EmptyDepositNftTxWitness() - zeroTxConstraint.TransferTxInfo = std.EmptyTransferTxWitness() - zeroTxConstraint.SwapTxInfo = std.EmptySwapTxWitness() - zeroTxConstraint.AddLiquidityTxInfo = std.EmptyAddLiquidityTxWitness() - zeroTxConstraint.RemoveLiquidityTxInfo = std.EmptyRemoveLiquidityTxWitness() - zeroTxConstraint.CreateCollectionTxInfo = std.EmptyCreateCollectionTxWitness() - zeroTxConstraint.MintNftTxInfo = std.EmptyMintNftTxWitness() - zeroTxConstraint.TransferNftTxInfo = std.EmptyTransferNftTxWitness() - zeroTxConstraint.AtomicMatchTxInfo = std.EmptyAtomicMatchTxWitness() - zeroTxConstraint.CancelOfferTxInfo = std.EmptyCancelOfferTxWitness() - zeroTxConstraint.WithdrawTxInfo = std.EmptyWithdrawTxWitness() - zeroTxConstraint.WithdrawNftTxInfo = std.EmptyWithdrawNftTxWitness() - zeroTxConstraint.FullExitTxInfo = std.EmptyFullExitTxWitness() - zeroTxConstraint.FullExitNftTxInfo = std.EmptyFullExitNftTxWitness() + zeroTxConstraint.RegisterZnsTxInfo = types.EmptyRegisterZnsTxWitness() + zeroTxConstraint.CreatePairTxInfo = types.EmptyCreatePairTxWitness() + zeroTxConstraint.UpdatePairRateTxInfo = types.EmptyUpdatePairRateTxWitness() + zeroTxConstraint.DepositTxInfo = types.EmptyDepositTxWitness() + zeroTxConstraint.DepositNftTxInfo = types.EmptyDepositNftTxWitness() + zeroTxConstraint.TransferTxInfo = types.EmptyTransferTxWitness() + zeroTxConstraint.SwapTxInfo = types.EmptySwapTxWitness() + zeroTxConstraint.AddLiquidityTxInfo = types.EmptyAddLiquidityTxWitness() + zeroTxConstraint.RemoveLiquidityTxInfo = types.EmptyRemoveLiquidityTxWitness() + zeroTxConstraint.CreateCollectionTxInfo = types.EmptyCreateCollectionTxWitness() + zeroTxConstraint.MintNftTxInfo = types.EmptyMintNftTxWitness() + zeroTxConstraint.TransferNftTxInfo = types.EmptyTransferNftTxWitness() + zeroTxConstraint.AtomicMatchTxInfo = types.EmptyAtomicMatchTxWitness() + zeroTxConstraint.CancelOfferTxInfo = types.EmptyCancelOfferTxWitness() + zeroTxConstraint.WithdrawTxInfo = types.EmptyWithdrawTxWitness() + zeroTxConstraint.WithdrawNftTxInfo = types.EmptyWithdrawNftTxWitness() + zeroTxConstraint.FullExitTxInfo = types.EmptyFullExitTxWitness() + zeroTxConstraint.FullExitNftTxInfo = types.EmptyFullExitNftTxWitness() zeroTxConstraint.Signature = EmptySignatureWitness() zeroTxConstraint.Nonce = 0 zeroTxConstraint.ExpiredAt = 0 @@ -189,17 +189,17 @@ func GetZeroTxConstraint() TxConstraints { // account before info, size is 4 for i := 0; i < NbAccountsPerTx; i++ { // set witness - zeroAccountConstraint := std.AccountConstraints{ + zeroAccountConstraint := types.AccountConstraints{ AccountIndex: 0, AccountNameHash: 0, - AccountPk: std.EmptyPublicKeyWitness(), + AccountPk: types.EmptyPublicKeyWitness(), Nonce: 0, CollectionNonce: 0, AssetRoot: 0, } // set assets witness for i := 0; i < NbAccountAssetsPerAccount; i++ { - zeroAccountConstraint.AssetsInfo[i] = std.AccountAssetConstraints{ + zeroAccountConstraint.AssetsInfo[i] = types.AccountAssetConstraints{ AssetId: 0, Balance: 0, LpAmount: 0, diff --git a/legend/circuit/bn254/block/block_createCollection_test.go b/circuit/block_create_collection_test.go similarity index 99% rename from legend/circuit/bn254/block/block_createCollection_test.go rename to circuit/block_create_collection_test.go index 6730ca9c2..b4a1986d0 100644 --- a/legend/circuit/bn254/block/block_createCollection_test.go +++ b/circuit/block_create_collection_test.go @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Zecrey Protocol + * Copyright © 2022 ZkBNB Protocol * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,7 +15,7 @@ * */ -package block +package circuit import ( "encoding/json" @@ -26,7 +26,7 @@ import ( "github.com/consensys/gnark/frontend" "github.com/consensys/gnark/test" - "github.com/bnb-chain/zkbnb-crypto/legend/circuit/bn254/std" + "github.com/bnb-chain/zkbnb-crypto/circuit/types" ) func TestVerifyBlock_CreateCollection(t *testing.T) { @@ -45,6 +45,6 @@ func TestVerifyBlock_CreateCollection(t *testing.T) { assert.SolvingSucceeded( &circuit, &witness, test.WithBackends(backend.GROTH16), test.WithCurves(ecc.BN254), - test.WithProverOpts(backend.WithHints(std.Keccak256, std.ComputeSLp)), + test.WithProverOpts(backend.WithHints(types.Keccak256, types.ComputeSLp)), test.WithCompileOpts(frontend.IgnoreUnconstrainedInputs())) } diff --git a/legend/circuit/bn254/block/block_createPair_test.go b/circuit/block_create_pair_test.go similarity index 99% rename from legend/circuit/bn254/block/block_createPair_test.go rename to circuit/block_create_pair_test.go index 567d59098..75369feef 100644 --- a/legend/circuit/bn254/block/block_createPair_test.go +++ b/circuit/block_create_pair_test.go @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Zecrey Protocol + * Copyright © 2022 ZkBNB Protocol * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,7 +15,7 @@ * */ -package block +package circuit import ( "encoding/json" @@ -26,7 +26,7 @@ import ( "github.com/consensys/gnark/frontend" "github.com/consensys/gnark/test" - "github.com/bnb-chain/zkbnb-crypto/legend/circuit/bn254/std" + "github.com/bnb-chain/zkbnb-crypto/circuit/types" ) func TestVerifyBlock_CreatePair(t *testing.T) { @@ -45,6 +45,6 @@ func TestVerifyBlock_CreatePair(t *testing.T) { assert.SolvingSucceeded( &circuit, &witness, test.WithBackends(backend.GROTH16), test.WithCurves(ecc.BN254), - test.WithProverOpts(backend.WithHints(std.Keccak256, std.ComputeSLp)), + test.WithProverOpts(backend.WithHints(types.Keccak256, types.ComputeSLp)), test.WithCompileOpts(frontend.IgnoreUnconstrainedInputs())) } diff --git a/legend/circuit/bn254/block/block_depositNft_test.go b/circuit/block_deposit_nft_test.go similarity index 99% rename from legend/circuit/bn254/block/block_depositNft_test.go rename to circuit/block_deposit_nft_test.go index c5896e268..7c9f4bbff 100644 --- a/legend/circuit/bn254/block/block_depositNft_test.go +++ b/circuit/block_deposit_nft_test.go @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Zecrey Protocol + * Copyright © 2022 ZkBNB Protocol * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,7 +15,7 @@ * */ -package block +package circuit import ( "encoding/json" @@ -26,7 +26,7 @@ import ( "github.com/consensys/gnark/frontend" "github.com/consensys/gnark/test" - "github.com/bnb-chain/zkbnb-crypto/legend/circuit/bn254/std" + "github.com/bnb-chain/zkbnb-crypto/circuit/types" ) func TestVerifyBlock_DepositNft(t *testing.T) { @@ -45,6 +45,6 @@ func TestVerifyBlock_DepositNft(t *testing.T) { assert.SolvingSucceeded( &circuit, &witness, test.WithBackends(backend.GROTH16), test.WithCurves(ecc.BN254), - test.WithProverOpts(backend.WithHints(std.Keccak256, std.ComputeSLp)), + test.WithProverOpts(backend.WithHints(types.Keccak256, types.ComputeSLp)), test.WithCompileOpts(frontend.IgnoreUnconstrainedInputs())) } diff --git a/legend/circuit/bn254/block/block_deposit_test.go b/circuit/block_deposit_test.go similarity index 99% rename from legend/circuit/bn254/block/block_deposit_test.go rename to circuit/block_deposit_test.go index 23fb905cf..1af2ad6ee 100644 --- a/legend/circuit/bn254/block/block_deposit_test.go +++ b/circuit/block_deposit_test.go @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Zecrey Protocol + * Copyright © 2022 ZkBNB Protocol * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,7 +15,7 @@ * */ -package block +package circuit import ( "encoding/json" @@ -26,7 +26,7 @@ import ( "github.com/consensys/gnark/frontend" "github.com/consensys/gnark/test" - "github.com/bnb-chain/zkbnb-crypto/legend/circuit/bn254/std" + "github.com/bnb-chain/zkbnb-crypto/circuit/types" ) func TestVerifyBlock_Deposit(t *testing.T) { @@ -46,6 +46,6 @@ func TestVerifyBlock_Deposit(t *testing.T) { assert.SolvingSucceeded( &circuit, &witness, test.WithBackends(backend.GROTH16), test.WithCurves(ecc.BN254), - test.WithProverOpts(backend.WithHints(std.Keccak256, std.ComputeSLp)), + test.WithProverOpts(backend.WithHints(types.Keccak256, types.ComputeSLp)), test.WithCompileOpts(frontend.IgnoreUnconstrainedInputs())) } diff --git a/legend/circuit/bn254/block/block_fullExitNft_test.go b/circuit/block_fullexit_nft_test.go similarity index 99% rename from legend/circuit/bn254/block/block_fullExitNft_test.go rename to circuit/block_fullexit_nft_test.go index a42624076..2e8084362 100644 --- a/legend/circuit/bn254/block/block_fullExitNft_test.go +++ b/circuit/block_fullexit_nft_test.go @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Zecrey Protocol + * Copyright © 2022 ZkBNB Protocol * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,7 +15,7 @@ * */ -package block +package circuit import ( "encoding/json" @@ -26,7 +26,7 @@ import ( "github.com/consensys/gnark/frontend" "github.com/consensys/gnark/test" - "github.com/bnb-chain/zkbnb-crypto/legend/circuit/bn254/std" + "github.com/bnb-chain/zkbnb-crypto/circuit/types" ) func TestVerifyBlock_FullExitNft(t *testing.T) { @@ -45,6 +45,6 @@ func TestVerifyBlock_FullExitNft(t *testing.T) { assert.SolvingSucceeded( &circuit, &witness, test.WithBackends(backend.GROTH16), test.WithCurves(ecc.BN254), - test.WithProverOpts(backend.WithHints(std.Keccak256, std.ComputeSLp)), + test.WithProverOpts(backend.WithHints(types.Keccak256, types.ComputeSLp)), test.WithCompileOpts(frontend.IgnoreUnconstrainedInputs())) } diff --git a/legend/circuit/bn254/block/block_fullExit_test.go b/circuit/block_fullexit_test.go similarity index 99% rename from legend/circuit/bn254/block/block_fullExit_test.go rename to circuit/block_fullexit_test.go index a574e5b50..d2a044b5d 100644 --- a/legend/circuit/bn254/block/block_fullExit_test.go +++ b/circuit/block_fullexit_test.go @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Zecrey Protocol + * Copyright © 2022 ZkBNB Protocol * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,7 +15,7 @@ * */ -package block +package circuit import ( "encoding/json" @@ -26,7 +26,7 @@ import ( "github.com/consensys/gnark/frontend" "github.com/consensys/gnark/test" - "github.com/bnb-chain/zkbnb-crypto/legend/circuit/bn254/std" + "github.com/bnb-chain/zkbnb-crypto/circuit/types" ) func TestVerifyBlock_FullExit(t *testing.T) { @@ -45,6 +45,6 @@ func TestVerifyBlock_FullExit(t *testing.T) { assert.SolvingSucceeded( &circuit, &witness, test.WithBackends(backend.GROTH16), test.WithCurves(ecc.BN254), - test.WithProverOpts(backend.WithHints(std.Keccak256, std.ComputeSLp)), + test.WithProverOpts(backend.WithHints(types.Keccak256, types.ComputeSLp)), test.WithCompileOpts(frontend.IgnoreUnconstrainedInputs())) } diff --git a/legend/circuit/bn254/block/block_mintNft_test.go b/circuit/block_mint_nft_test.go similarity index 99% rename from legend/circuit/bn254/block/block_mintNft_test.go rename to circuit/block_mint_nft_test.go index 2bffdfb2f..c10a11dfa 100644 --- a/legend/circuit/bn254/block/block_mintNft_test.go +++ b/circuit/block_mint_nft_test.go @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Zecrey Protocol + * Copyright © 2022 ZkBNB Protocol * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,7 +15,7 @@ * */ -package block +package circuit import ( "encoding/json" @@ -26,7 +26,7 @@ import ( "github.com/consensys/gnark/frontend" "github.com/consensys/gnark/test" - "github.com/bnb-chain/zkbnb-crypto/legend/circuit/bn254/std" + "github.com/bnb-chain/zkbnb-crypto/circuit/types" ) func TestVerifyBlock_MintNft(t *testing.T) { @@ -45,6 +45,6 @@ func TestVerifyBlock_MintNft(t *testing.T) { assert.SolvingSucceeded( &circuit, &witness, test.WithBackends(backend.GROTH16), test.WithCurves(ecc.BN254), - test.WithProverOpts(backend.WithHints(std.Keccak256, std.ComputeSLp)), + test.WithProverOpts(backend.WithHints(types.Keccak256, types.ComputeSLp)), test.WithCompileOpts(frontend.IgnoreUnconstrainedInputs())) } diff --git a/legend/circuit/bn254/block/block_registerZNS2_test.go b/circuit/block_register_zns2_test.go similarity index 99% rename from legend/circuit/bn254/block/block_registerZNS2_test.go rename to circuit/block_register_zns2_test.go index b5c45aff6..b8bc8b9f5 100644 --- a/legend/circuit/bn254/block/block_registerZNS2_test.go +++ b/circuit/block_register_zns2_test.go @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Zecrey Protocol + * Copyright © 2022 ZkBNB Protocol * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,7 +15,7 @@ * */ -package block +package circuit import ( "encoding/json" @@ -26,7 +26,7 @@ import ( "github.com/consensys/gnark/frontend" "github.com/consensys/gnark/test" - "github.com/bnb-chain/zkbnb-crypto/legend/circuit/bn254/std" + "github.com/bnb-chain/zkbnb-crypto/circuit/types" ) func TestVerifyBlock_RegisterZNS2(t *testing.T) { @@ -46,6 +46,6 @@ func TestVerifyBlock_RegisterZNS2(t *testing.T) { assert.SolvingSucceeded( &circuit, &witness, test.WithBackends(backend.GROTH16), test.WithCurves(ecc.BN254), - test.WithProverOpts(backend.WithHints(std.Keccak256, std.ComputeSLp)), + test.WithProverOpts(backend.WithHints(types.Keccak256, types.ComputeSLp)), test.WithCompileOpts(frontend.IgnoreUnconstrainedInputs())) } diff --git a/legend/circuit/bn254/block/block_registerZNS_test.go b/circuit/block_register_zns_test.go similarity index 99% rename from legend/circuit/bn254/block/block_registerZNS_test.go rename to circuit/block_register_zns_test.go index 699c510b2..11f13214b 100644 --- a/legend/circuit/bn254/block/block_registerZNS_test.go +++ b/circuit/block_register_zns_test.go @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Zecrey Protocol + * Copyright © 2022 ZkBNB Protocol * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,7 +15,7 @@ * */ -package block +package circuit import ( "bytes" @@ -32,9 +32,9 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/crypto" + "github.com/bnb-chain/zkbnb-crypto/circuit/types" curve "github.com/bnb-chain/zkbnb-crypto/ecc/ztwistededwards/tebn254" "github.com/bnb-chain/zkbnb-crypto/ffmath" - "github.com/bnb-chain/zkbnb-crypto/legend/circuit/bn254/std" ) func CleanAndPaddingByteByModulus(buf []byte) []byte { @@ -103,6 +103,6 @@ func TestVerifyBlock_RegisterZNS(t *testing.T) { assert.SolvingSucceeded( &circuit, &witness, test.WithBackends(backend.GROTH16), test.WithCurves(ecc.BN254), - test.WithProverOpts(backend.WithHints(std.Keccak256, std.ComputeSLp)), + test.WithProverOpts(backend.WithHints(types.Keccak256, types.ComputeSLp)), test.WithCompileOpts(frontend.IgnoreUnconstrainedInputs())) } diff --git a/legend/circuit/bn254/block/block_removeLiquidity_test.go b/circuit/block_remove_liquidity_test.go similarity index 99% rename from legend/circuit/bn254/block/block_removeLiquidity_test.go rename to circuit/block_remove_liquidity_test.go index d5459603c..4ab762cce 100644 --- a/legend/circuit/bn254/block/block_removeLiquidity_test.go +++ b/circuit/block_remove_liquidity_test.go @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Zecrey Protocol + * Copyright © 2022 ZkBNB Protocol * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,7 +15,7 @@ * */ -package block +package circuit import ( "encoding/json" @@ -26,7 +26,7 @@ import ( "github.com/consensys/gnark/frontend" "github.com/consensys/gnark/test" - "github.com/bnb-chain/zkbnb-crypto/legend/circuit/bn254/std" + "github.com/bnb-chain/zkbnb-crypto/circuit/types" ) func TestVerifyBlock_RemoveLiquidity(t *testing.T) { @@ -45,6 +45,6 @@ func TestVerifyBlock_RemoveLiquidity(t *testing.T) { assert.SolvingSucceeded( &circuit, &witness, test.WithBackends(backend.GROTH16), test.WithCurves(ecc.BN254), - test.WithProverOpts(backend.WithHints(std.Keccak256, std.ComputeSLp)), + test.WithProverOpts(backend.WithHints(types.Keccak256, types.ComputeSLp)), test.WithCompileOpts(frontend.IgnoreUnconstrainedInputs())) } diff --git a/legend/circuit/bn254/block/block_swap_test.go b/circuit/block_swap_test.go similarity index 99% rename from legend/circuit/bn254/block/block_swap_test.go rename to circuit/block_swap_test.go index 73621e4fa..1d0ad2d66 100644 --- a/legend/circuit/bn254/block/block_swap_test.go +++ b/circuit/block_swap_test.go @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Zecrey Protocol + * Copyright © 2022 ZkBNB Protocol * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,7 +15,7 @@ * */ -package block +package circuit import ( "encoding/json" @@ -26,7 +26,7 @@ import ( "github.com/consensys/gnark/frontend" "github.com/consensys/gnark/test" - "github.com/bnb-chain/zkbnb-crypto/legend/circuit/bn254/std" + "github.com/bnb-chain/zkbnb-crypto/circuit/types" ) func TestVerifyBlock_Swap(t *testing.T) { @@ -45,6 +45,6 @@ func TestVerifyBlock_Swap(t *testing.T) { assert.SolvingSucceeded( &circuit, &witness, test.WithBackends(backend.GROTH16), test.WithCurves(ecc.BN254), - test.WithProverOpts(backend.WithHints(std.Keccak256, std.ComputeSLp)), + test.WithProverOpts(backend.WithHints(types.Keccak256, types.ComputeSLp)), test.WithCompileOpts(frontend.IgnoreUnconstrainedInputs())) } diff --git a/legend/circuit/bn254/block/block_transferNft_test.go b/circuit/block_transfer_nft_test.go similarity index 99% rename from legend/circuit/bn254/block/block_transferNft_test.go rename to circuit/block_transfer_nft_test.go index bd5320da9..4a974a6c4 100644 --- a/legend/circuit/bn254/block/block_transferNft_test.go +++ b/circuit/block_transfer_nft_test.go @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Zecrey Protocol + * Copyright © 2022 ZkBNB Protocol * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,7 +15,7 @@ * */ -package block +package circuit import ( "encoding/json" @@ -26,7 +26,7 @@ import ( "github.com/consensys/gnark/frontend" "github.com/consensys/gnark/test" - "github.com/bnb-chain/zkbnb-crypto/legend/circuit/bn254/std" + "github.com/bnb-chain/zkbnb-crypto/circuit/types" ) func TestVerifyBlock_TransferNft(t *testing.T) { @@ -45,6 +45,6 @@ func TestVerifyBlock_TransferNft(t *testing.T) { assert.SolvingSucceeded( &circuit, &witness, test.WithBackends(backend.GROTH16), test.WithCurves(ecc.BN254), - test.WithProverOpts(backend.WithHints(std.Keccak256, std.ComputeSLp)), + test.WithProverOpts(backend.WithHints(types.Keccak256, types.ComputeSLp)), test.WithCompileOpts(frontend.IgnoreUnconstrainedInputs())) } diff --git a/legend/circuit/bn254/block/block_transfer_test.go b/circuit/block_transfer_test.go similarity index 99% rename from legend/circuit/bn254/block/block_transfer_test.go rename to circuit/block_transfer_test.go index f857aeccd..f2d805851 100644 --- a/legend/circuit/bn254/block/block_transfer_test.go +++ b/circuit/block_transfer_test.go @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Zecrey Protocol + * Copyright © 2022 ZkBNB Protocol * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,7 +15,7 @@ * */ -package block +package circuit import ( "encoding/json" @@ -26,7 +26,7 @@ import ( "github.com/consensys/gnark/frontend" "github.com/consensys/gnark/test" - "github.com/bnb-chain/zkbnb-crypto/legend/circuit/bn254/std" + "github.com/bnb-chain/zkbnb-crypto/circuit/types" ) func TestVerifyBlock_Transfer(t *testing.T) { @@ -45,6 +45,6 @@ func TestVerifyBlock_Transfer(t *testing.T) { assert.SolvingSucceeded( &circuit, &witness, test.WithBackends(backend.GROTH16), test.WithCurves(ecc.BN254), - test.WithProverOpts(backend.WithHints(std.Keccak256, std.ComputeSLp)), + test.WithProverOpts(backend.WithHints(types.Keccak256, types.ComputeSLp)), test.WithCompileOpts(frontend.IgnoreUnconstrainedInputs())) } diff --git a/legend/circuit/bn254/block/block_updatePairRate_test.go b/circuit/block_update_pair_rate_test.go similarity index 99% rename from legend/circuit/bn254/block/block_updatePairRate_test.go rename to circuit/block_update_pair_rate_test.go index f4cea384d..757fd8e21 100644 --- a/legend/circuit/bn254/block/block_updatePairRate_test.go +++ b/circuit/block_update_pair_rate_test.go @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Zecrey Protocol + * Copyright © 2022 ZkBNB Protocol * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,7 +15,7 @@ * */ -package block +package circuit import ( "encoding/json" @@ -26,7 +26,7 @@ import ( "github.com/consensys/gnark/frontend" "github.com/consensys/gnark/test" - "github.com/bnb-chain/zkbnb-crypto/legend/circuit/bn254/std" + "github.com/bnb-chain/zkbnb-crypto/circuit/types" ) func TestVerifyBlock_UpdatePairRate(t *testing.T) { @@ -45,6 +45,6 @@ func TestVerifyBlock_UpdatePairRate(t *testing.T) { assert.SolvingSucceeded( &circuit, &witness, test.WithBackends(backend.GROTH16), test.WithCurves(ecc.BN254), - test.WithProverOpts(backend.WithHints(std.Keccak256, std.ComputeSLp)), + test.WithProverOpts(backend.WithHints(types.Keccak256, types.ComputeSLp)), test.WithCompileOpts(frontend.IgnoreUnconstrainedInputs())) } diff --git a/legend/circuit/bn254/block/block_updatePair_test.go b/circuit/block_update_pair_test.go similarity index 99% rename from legend/circuit/bn254/block/block_updatePair_test.go rename to circuit/block_update_pair_test.go index f18830a71..2478793e8 100644 --- a/legend/circuit/bn254/block/block_updatePair_test.go +++ b/circuit/block_update_pair_test.go @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Zecrey Protocol + * Copyright © 2022 ZkBNB Protocol * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,7 +15,7 @@ * */ -package block +package circuit import ( "encoding/json" @@ -26,7 +26,7 @@ import ( "github.com/consensys/gnark/frontend" "github.com/consensys/gnark/test" - "github.com/bnb-chain/zkbnb-crypto/legend/circuit/bn254/std" + "github.com/bnb-chain/zkbnb-crypto/circuit/types" ) func TestVerifyBlock_UpdatePair(t *testing.T) { @@ -45,6 +45,6 @@ func TestVerifyBlock_UpdatePair(t *testing.T) { assert.SolvingSucceeded( &circuit, &witness, test.WithBackends(backend.GROTH16), test.WithCurves(ecc.BN254), - test.WithProverOpts(backend.WithHints(std.Keccak256, std.ComputeSLp)), + test.WithProverOpts(backend.WithHints(types.Keccak256, types.ComputeSLp)), test.WithCompileOpts(frontend.IgnoreUnconstrainedInputs())) } diff --git a/legend/circuit/bn254/block/block_withdrawNft_test.go b/circuit/block_withdraw_nft_test.go similarity index 99% rename from legend/circuit/bn254/block/block_withdrawNft_test.go rename to circuit/block_withdraw_nft_test.go index 810f5b333..933153407 100644 --- a/legend/circuit/bn254/block/block_withdrawNft_test.go +++ b/circuit/block_withdraw_nft_test.go @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Zecrey Protocol + * Copyright © 2022 ZkBNB Protocol * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,7 +15,7 @@ * */ -package block +package circuit import ( "encoding/json" @@ -26,7 +26,7 @@ import ( "github.com/consensys/gnark/frontend" "github.com/consensys/gnark/test" - "github.com/bnb-chain/zkbnb-crypto/legend/circuit/bn254/std" + "github.com/bnb-chain/zkbnb-crypto/circuit/types" ) func TestVerifyBlock_WithdrawNft(t *testing.T) { @@ -45,6 +45,6 @@ func TestVerifyBlock_WithdrawNft(t *testing.T) { assert.SolvingSucceeded( &circuit, &witness, test.WithBackends(backend.GROTH16), test.WithCurves(ecc.BN254), - test.WithProverOpts(backend.WithHints(std.Keccak256, std.ComputeSLp)), + test.WithProverOpts(backend.WithHints(types.Keccak256, types.ComputeSLp)), test.WithCompileOpts(frontend.IgnoreUnconstrainedInputs())) } diff --git a/legend/circuit/bn254/block/block_withdraw_test.go b/circuit/block_withdraw_test.go similarity index 99% rename from legend/circuit/bn254/block/block_withdraw_test.go rename to circuit/block_withdraw_test.go index 4b3b63364..dcda38cf6 100644 --- a/legend/circuit/bn254/block/block_withdraw_test.go +++ b/circuit/block_withdraw_test.go @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Zecrey Protocol + * Copyright © 2022 ZkBNB Protocol * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,7 +15,7 @@ * */ -package block +package circuit import ( "encoding/json" @@ -26,7 +26,7 @@ import ( "github.com/consensys/gnark/frontend" "github.com/consensys/gnark/test" - "github.com/bnb-chain/zkbnb-crypto/legend/circuit/bn254/std" + "github.com/bnb-chain/zkbnb-crypto/circuit/types" ) func TestVerifyBlock_Withdraw(t *testing.T) { @@ -45,6 +45,6 @@ func TestVerifyBlock_Withdraw(t *testing.T) { assert.SolvingSucceeded( &circuit, &witness, test.WithBackends(backend.GROTH16), test.WithCurves(ecc.BN254), - test.WithProverOpts(backend.WithHints(std.Keccak256, std.ComputeSLp)), + test.WithProverOpts(backend.WithHints(types.Keccak256, types.ComputeSLp)), test.WithCompileOpts(frontend.IgnoreUnconstrainedInputs())) } diff --git a/legend/circuit/bn254/encode/abi/abi.go b/circuit/encode/abi/abi.go similarity index 100% rename from legend/circuit/bn254/encode/abi/abi.go rename to circuit/encode/abi/abi.go diff --git a/legend/circuit/bn254/encode/abi/constant.go b/circuit/encode/abi/constant.go similarity index 98% rename from legend/circuit/bn254/encode/abi/constant.go rename to circuit/encode/abi/constant.go index 9259c8c98..103284ef0 100644 --- a/legend/circuit/bn254/encode/abi/constant.go +++ b/circuit/encode/abi/constant.go @@ -10,10 +10,8 @@ func (abiId AbiId) ToBigIntRegular(res *big.Int) *big.Int { return new(big.Int).SetUint64(uint64(abiId)) } -// PairingABI is the input ABI used to generate the binding from. -const PairingABI = "[]" const GeneralABIJSON = "[{\"inputs\":[{\"internalType\":\"uint32\",\"name\":\"FromAccountIndex\",\"type\":\"uint32\"},{\"internalType\":\"uint16\",\"name\":\"PairIndex\",\"type\":\"uint16\"},{\"internalType\":\"uint40\",\"name\":\"packedAAmount\",\"type\":\"uint40\"},{\"internalType\":\"uint40\",\"name\":\"packedBAmount\",\"type\":\"uint40\"},{\"internalType\":\"uint32\",\"name\":\"GasAccountIndex\",\"type\":\"uint32\"},{\"internalType\":\"uint16\",\"name\":\"GasFeeAssetId\",\"type\":\"uint16\"},{\"internalType\":\"uint16\",\"name\":\"packedFee\",\"type\":\"uint16\"},{\"internalType\":\"uint64\",\"name\":\"ExpireAt\",\"type\":\"uint64\"},{\"internalType\":\"uint32\",\"name\":\"Nonce\",\"type\":\"uint32\"},{\"internalType\":\"uint32\",\"name\":\"ChainId\",\"type\":\"uint32\"}],\"name\":\"AddLiquidity\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint32\",\"name\":\"AccountIndex\",\"type\":\"uint32\"},{\"components\":[{\"internalType\":\"uint8\",\"name\":\"OfferType\",\"type\":\"uint8\"},{\"internalType\":\"uint24\",\"name\":\"OfferId\",\"type\":\"uint24\"},{\"internalType\":\"uint32\",\"name\":\"AccountIndex\",\"type\":\"uint32\"},{\"internalType\":\"uint32\",\"name\":\"NftIndex\",\"type\":\"uint32\"},{\"internalType\":\"uint40\",\"name\":\"packedAmount\",\"type\":\"uint40\"},{\"internalType\":\"uint64\",\"name\":\"OfferListedAt\",\"type\":\"uint64\"},{\"internalType\":\"uint64\",\"name\":\"OfferExpiredAt\",\"type\":\"uint64\"},{\"internalType\":\"bytes16\",\"name\":\"SigRx\",\"type\":\"bytes16\"},{\"internalType\":\"bytes16\",\"name\":\"SigRy\",\"type\":\"bytes16\"},{\"internalType\":\"bytes32\",\"name\":\"SigS\",\"type\":\"bytes32\"}],\"internalType\":\"struct Storage.Offer\",\"name\":\"BuyerOffer\",\"type\":\"tuple\"},{\"components\":[{\"internalType\":\"uint8\",\"name\":\"OfferType\",\"type\":\"uint8\"},{\"internalType\":\"uint24\",\"name\":\"OfferId\",\"type\":\"uint24\"},{\"internalType\":\"uint32\",\"name\":\"AccountIndex\",\"type\":\"uint32\"},{\"internalType\":\"uint32\",\"name\":\"NftIndex\",\"type\":\"uint32\"},{\"internalType\":\"uint40\",\"name\":\"packedAmount\",\"type\":\"uint40\"},{\"internalType\":\"uint64\",\"name\":\"OfferListedAt\",\"type\":\"uint64\"},{\"internalType\":\"uint64\",\"name\":\"OfferExpiredAt\",\"type\":\"uint64\"},{\"internalType\":\"bytes16\",\"name\":\"SigRx\",\"type\":\"bytes16\"},{\"internalType\":\"bytes16\",\"name\":\"SigRy\",\"type\":\"bytes16\"},{\"internalType\":\"bytes32\",\"name\":\"SigS\",\"type\":\"bytes32\"}],\"internalType\":\"struct Storage.Offer\",\"name\":\"SellerOffer\",\"type\":\"tuple\"},{\"internalType\":\"uint32\",\"name\":\"GasAccountIndex\",\"type\":\"uint32\"},{\"internalType\":\"uint16\",\"name\":\"GasFeeAssetId\",\"type\":\"uint16\"},{\"internalType\":\"uint16\",\"name\":\"packedFee\",\"type\":\"uint16\"},{\"internalType\":\"uint64\",\"name\":\"ExpireAt\",\"type\":\"uint64\"},{\"internalType\":\"uint32\",\"name\":\"Nonce\",\"type\":\"uint32\"},{\"internalType\":\"uint32\",\"name\":\"ChainId\",\"type\":\"uint32\"}],\"name\":\"AtomicMatch\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint32\",\"name\":\"AccountIndex\",\"type\":\"uint32\"},{\"internalType\":\"uint24\",\"name\":\"OfferId\",\"type\":\"uint24\"},{\"internalType\":\"uint32\",\"name\":\"GasAccountIndex\",\"type\":\"uint32\"},{\"internalType\":\"uint16\",\"name\":\"GasFeeAssetId\",\"type\":\"uint16\"},{\"internalType\":\"uint16\",\"name\":\"packedFee\",\"type\":\"uint16\"},{\"internalType\":\"uint64\",\"name\":\"ExpireAt\",\"type\":\"uint64\"},{\"internalType\":\"uint32\",\"name\":\"Nonce\",\"type\":\"uint32\"},{\"internalType\":\"uint32\",\"name\":\"ChainId\",\"type\":\"uint32\"}],\"name\":\"CancelOffer\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint32\",\"name\":\"AccountIndex\",\"type\":\"uint32\"},{\"internalType\":\"uint32\",\"name\":\"GasAccountIndex\",\"type\":\"uint32\"},{\"internalType\":\"uint16\",\"name\":\"GasFeeAssetId\",\"type\":\"uint16\"},{\"internalType\":\"uint16\",\"name\":\"packedFee\",\"type\":\"uint16\"},{\"internalType\":\"uint64\",\"name\":\"ExpireAt\",\"type\":\"uint64\"},{\"internalType\":\"uint32\",\"name\":\"Nonce\",\"type\":\"uint32\"},{\"internalType\":\"uint32\",\"name\":\"ChainId\",\"type\":\"uint32\"}],\"name\":\"CreateCollection\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint32\",\"name\":\"CreatorAccountIndex\",\"type\":\"uint32\"},{\"internalType\":\"uint32\",\"name\":\"ToAccountIndex\",\"type\":\"uint32\"},{\"internalType\":\"bytes32\",\"name\":\"ToAccountNameHash\",\"type\":\"bytes32\"},{\"internalType\":\"bytes32\",\"name\":\"NftContentHash\",\"type\":\"bytes32\"},{\"internalType\":\"uint32\",\"name\":\"GasAccountIndex\",\"type\":\"uint32\"},{\"internalType\":\"uint16\",\"name\":\"GasFeeAssetId\",\"type\":\"uint16\"},{\"internalType\":\"uint16\",\"name\":\"packedFee\",\"type\":\"uint16\"},{\"internalType\":\"uint32\",\"name\":\"CreatorTreasureRate\",\"type\":\"uint32\"},{\"internalType\":\"uint32\",\"name\":\"NftCollectionId\",\"type\":\"uint32\"},{\"internalType\":\"uint64\",\"name\":\"ExpireAt\",\"type\":\"uint64\"},{\"internalType\":\"uint32\",\"name\":\"Nonce\",\"type\":\"uint32\"},{\"internalType\":\"uint32\",\"name\":\"ChainId\",\"type\":\"uint32\"}],\"name\":\"MintNft\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint32\",\"name\":\"FromAccountIndex\",\"type\":\"uint32\"},{\"internalType\":\"uint16\",\"name\":\"PairIndex\",\"type\":\"uint16\"},{\"internalType\":\"uint40\",\"name\":\"packedAAmount\",\"type\":\"uint40\"},{\"internalType\":\"uint40\",\"name\":\"packedBAmount\",\"type\":\"uint40\"},{\"internalType\":\"uint40\",\"name\":\"lpAmount\",\"type\":\"uint40\"},{\"internalType\":\"uint32\",\"name\":\"GasAccountIndex\",\"type\":\"uint32\"},{\"internalType\":\"uint16\",\"name\":\"GasFeeAssetId\",\"type\":\"uint16\"},{\"internalType\":\"uint16\",\"name\":\"packedFee\",\"type\":\"uint16\"},{\"internalType\":\"uint64\",\"name\":\"ExpireAt\",\"type\":\"uint64\"},{\"internalType\":\"uint32\",\"name\":\"Nonce\",\"type\":\"uint32\"},{\"internalType\":\"uint32\",\"name\":\"ChainId\",\"type\":\"uint32\"}],\"name\":\"RemoveLiquidity\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint32\",\"name\":\"FromAccountIndex\",\"type\":\"uint32\"},{\"internalType\":\"uint16\",\"name\":\"PairIndex\",\"type\":\"uint16\"},{\"internalType\":\"uint40\",\"name\":\"packedAAmount\",\"type\":\"uint40\"},{\"internalType\":\"uint40\",\"name\":\"packedBAmount\",\"type\":\"uint40\"},{\"internalType\":\"uint32\",\"name\":\"GasAccountIndex\",\"type\":\"uint32\"},{\"internalType\":\"uint16\",\"name\":\"GasFeeAssetId\",\"type\":\"uint16\"},{\"internalType\":\"uint16\",\"name\":\"packedFee\",\"type\":\"uint16\"},{\"internalType\":\"uint64\",\"name\":\"ExpireAt\",\"type\":\"uint64\"},{\"internalType\":\"uint32\",\"name\":\"Nonce\",\"type\":\"uint32\"},{\"internalType\":\"uint32\",\"name\":\"ChainId\",\"type\":\"uint32\"}],\"name\":\"Swap\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint32\",\"name\":\"FromAccountIndex\",\"type\":\"uint32\"},{\"internalType\":\"uint32\",\"name\":\"ToAccountIndex\",\"type\":\"uint32\"},{\"internalType\":\"bytes32\",\"name\":\"ToAccountNameHash\",\"type\":\"bytes32\"},{\"internalType\":\"uint16\",\"name\":\"AssetId\",\"type\":\"uint16\"},{\"internalType\":\"uint40\",\"name\":\"packedAmount\",\"type\":\"uint40\"},{\"internalType\":\"uint32\",\"name\":\"GasAccountIndex\",\"type\":\"uint32\"},{\"internalType\":\"uint16\",\"name\":\"GasFeeAssetId\",\"type\":\"uint16\"},{\"internalType\":\"uint16\",\"name\":\"packedFee\",\"type\":\"uint16\"},{\"internalType\":\"bytes32\",\"name\":\"CallDataHash\",\"type\":\"bytes32\"},{\"internalType\":\"uint64\",\"name\":\"ExpireAt\",\"type\":\"uint64\"},{\"internalType\":\"uint32\",\"name\":\"Nonce\",\"type\":\"uint32\"},{\"internalType\":\"uint32\",\"name\":\"ChainId\",\"type\":\"uint32\"}],\"name\":\"Transfer\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint32\",\"name\":\"FromAccountIndex\",\"type\":\"uint32\"},{\"internalType\":\"uint32\",\"name\":\"ToAccountIndex\",\"type\":\"uint32\"},{\"internalType\":\"bytes32\",\"name\":\"ToAccountNameHash\",\"type\":\"bytes32\"},{\"internalType\":\"uint40\",\"name\":\"NftIndex\",\"type\":\"uint40\"},{\"internalType\":\"uint32\",\"name\":\"GasAccountIndex\",\"type\":\"uint32\"},{\"internalType\":\"uint16\",\"name\":\"GasFeeAssetId\",\"type\":\"uint16\"},{\"internalType\":\"uint16\",\"name\":\"packedFee\",\"type\":\"uint16\"},{\"internalType\":\"bytes32\",\"name\":\"CallDataHash\",\"type\":\"bytes32\"},{\"internalType\":\"uint64\",\"name\":\"ExpireAt\",\"type\":\"uint64\"},{\"internalType\":\"uint32\",\"name\":\"Nonce\",\"type\":\"uint32\"},{\"internalType\":\"uint32\",\"name\":\"ChainId\",\"type\":\"uint32\"}],\"name\":\"TransferNft\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint32\",\"name\":\"FromAccountIndex\",\"type\":\"uint32\"},{\"internalType\":\"uint16\",\"name\":\"AssetId\",\"type\":\"uint16\"},{\"internalType\":\"bytes16\",\"name\":\"AssetAmount\",\"type\":\"bytes16\"},{\"internalType\":\"uint32\",\"name\":\"GasAccountIndex\",\"type\":\"uint32\"},{\"internalType\":\"uint16\",\"name\":\"GasFeeAssetId\",\"type\":\"uint16\"},{\"internalType\":\"uint16\",\"name\":\"packedFee\",\"type\":\"uint16\"},{\"internalType\":\"bytes20\",\"name\":\"ToAddress\",\"type\":\"bytes20\"},{\"internalType\":\"uint64\",\"name\":\"ExpireAt\",\"type\":\"uint64\"},{\"internalType\":\"uint32\",\"name\":\"Nonce\",\"type\":\"uint32\"},{\"internalType\":\"uint32\",\"name\":\"ChainId\",\"type\":\"uint32\"}],\"name\":\"Withdraw\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint32\",\"name\":\"AccountIndex\",\"type\":\"uint32\"},{\"internalType\":\"uint40\",\"name\":\"NftIndex\",\"type\":\"uint40\"},{\"internalType\":\"bytes20\",\"name\":\"ToAddress\",\"type\":\"bytes20\"},{\"internalType\":\"uint32\",\"name\":\"GasAccountIndex\",\"type\":\"uint32\"},{\"internalType\":\"uint16\",\"name\":\"GasFeeAssetId\",\"type\":\"uint16\"},{\"internalType\":\"uint16\",\"name\":\"packedFee\",\"type\":\"uint16\"},{\"internalType\":\"uint64\",\"name\":\"ExpireAt\",\"type\":\"uint64\"},{\"internalType\":\"uint32\",\"name\":\"Nonce\",\"type\":\"uint32\"},{\"internalType\":\"uint32\",\"name\":\"ChainId\",\"type\":\"uint32\"}],\"name\":\"WithdrawNft\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"}]" -const ABI_ENCODE_EMPTY_BYTE = 0xffff +const AbiEncodeEmptyByte = 0xffff const ( DefaultAbi AbiId = iota @@ -31,7 +29,3 @@ const ( ) const StaticArgsOutput = 1024 -const StaticArgsLengthOutput = 1025 - -func init() { -} diff --git a/legend/circuit/bn254/encode/abi/encode.go b/circuit/encode/abi/encode.go similarity index 100% rename from legend/circuit/bn254/encode/abi/encode.go rename to circuit/encode/abi/encode.go diff --git a/legend/circuit/bn254/encode/abi/encode_test.go b/circuit/encode/abi/encode_test.go similarity index 99% rename from legend/circuit/bn254/encode/abi/encode_test.go rename to circuit/encode/abi/encode_test.go index 90ecb658f..33e26c31c 100644 --- a/legend/circuit/bn254/encode/abi/encode_test.go +++ b/circuit/encode/abi/encode_test.go @@ -694,10 +694,10 @@ func TestAbiEncodeAtomicMatch(t *testing.T) { SigS: s, } offerArray := offer.DecomposeConstraintArrays() - for i, _ := range offerArray { + for i := range offerArray { w.Values[1+i] = offerArray[i] } - for i, _ := range offerArray { + for i := range offerArray { w.Values[72+i] = offerArray[i] } w.Values[143] = uint32(1) diff --git a/legend/circuit/bn254/encode/abi/encoder.go b/circuit/encode/abi/encoder.go similarity index 97% rename from legend/circuit/bn254/encode/abi/encoder.go rename to circuit/encode/abi/encoder.go index 3ebe40298..ade2e4612 100644 --- a/legend/circuit/bn254/encode/abi/encoder.go +++ b/circuit/encode/abi/encoder.go @@ -100,7 +100,7 @@ func (e *pureAbiEncoder) Pack(api frontend.API, name frontend.Variable, args ... if err != nil { return nil, err } - var shouldSelectBytes []frontend.Variable = make([]frontend.Variable, StaticArgsOutput) + var shouldSelectBytes = make([]frontend.Variable, StaticArgsOutput) for i := 0; i < StaticArgsOutput; i++ { shouldSelectBytes[i] = 0 shouldSelectBytes[i] = api.Select(e.context.flags.defaultApiFlag, defaultAbiBytes[i], shouldSelectBytes[i]) @@ -153,7 +153,7 @@ func (e *pureHintAbiEncoder) HintTransferAbi(curveId ecc.ID, inputs []*big.Int, copy(bs32[:], bs) copy(nh32[:], nh) - bytes, err := e.ABI.Pack("Transfer", uint32(inputs[0].Uint64()), uint32(inputs[1].Uint64()), nh32, uint16(inputs[34].Uint64()), inputs[35], uint32(inputs[36].Uint64()), uint16(inputs[37].Uint64()), uint16(inputs[38].Uint64()), bs32, uint64(inputs[71].Uint64()), uint32(inputs[72].Uint64()), uint32(inputs[73].Uint64())) + bytes, err := e.ABI.Pack("Transfer", uint32(inputs[0].Uint64()), uint32(inputs[1].Uint64()), nh32, uint16(inputs[34].Uint64()), inputs[35], uint32(inputs[36].Uint64()), uint16(inputs[37].Uint64()), uint16(inputs[38].Uint64()), bs32, inputs[71].Uint64(), uint32(inputs[72].Uint64()), uint32(inputs[73].Uint64())) if err != nil { return err } @@ -188,7 +188,7 @@ func (e *pureHintAbiEncoder) HintWithdrawAbi(curveId ecc.ID, inputs []*big.Int, copy(aa16[:], aa) copy(ta20[:], ta) - bytes, err := e.ABI.Pack("Withdraw", (uint32)(inputs[0].Uint64()), (uint16)(inputs[1].Uint64()), aa16, (uint32)(inputs[18].Uint64()), (uint16)(inputs[19].Uint64()), (uint16)(inputs[20].Uint64()), ta20, (uint64)(inputs[41].Uint64()), (uint32)(inputs[42].Uint64()), (uint32)(inputs[43].Uint64())) + bytes, err := e.ABI.Pack("Withdraw", (uint32)(inputs[0].Uint64()), (uint16)(inputs[1].Uint64()), aa16, (uint32)(inputs[18].Uint64()), (uint16)(inputs[19].Uint64()), (uint16)(inputs[20].Uint64()), ta20, inputs[41].Uint64(), (uint32)(inputs[42].Uint64()), (uint32)(inputs[43].Uint64())) if err != nil { return err diff --git a/legend/circuit/bn254/encode/abi/flags.go b/circuit/encode/abi/flags.go similarity index 100% rename from legend/circuit/bn254/encode/abi/flags.go rename to circuit/encode/abi/flags.go diff --git a/legend/circuit/bn254/encode/abi/offer.go b/circuit/encode/abi/offer.go similarity index 100% rename from legend/circuit/bn254/encode/abi/offer.go rename to circuit/encode/abi/offer.go diff --git a/legend/circuit/bn254/encode/abi/utils.go b/circuit/encode/abi/utils.go similarity index 96% rename from legend/circuit/bn254/encode/abi/utils.go rename to circuit/encode/abi/utils.go index cace77cdb..d94afdf12 100644 --- a/legend/circuit/bn254/encode/abi/utils.go +++ b/circuit/encode/abi/utils.go @@ -13,7 +13,7 @@ func WrapToAbiString(wrap string, wraplen int) []frontend.Variable { ret := make([]frontend.Variable, wraplen) for i := range ret { - ret[i] = ABI_ENCODE_EMPTY_BYTE + ret[i] = AbiEncodeEmptyByte } for i := range bs { diff --git a/legend/circuit/bn254/encode/keccak/encode.go b/circuit/encode/keccak/encode.go similarity index 95% rename from legend/circuit/bn254/encode/keccak/encode.go rename to circuit/encode/keccak/encode.go index 382e2181e..47a53f1a4 100644 --- a/legend/circuit/bn254/encode/keccak/encode.go +++ b/circuit/encode/keccak/encode.go @@ -8,7 +8,7 @@ import ( "github.com/consensys/gnark/frontend" "github.com/ethereum/go-ethereum/crypto" - "github.com/bnb-chain/zkbnb-crypto/legend/circuit/bn254/encode/abi" + "github.com/bnb-chain/zkbnb-crypto/circuit/encode/abi" ) type KeccakCircuit struct { diff --git a/legend/circuit/bn254/encode/keccak/encode_test.go b/circuit/encode/keccak/encode_test.go similarity index 99% rename from legend/circuit/bn254/encode/keccak/encode_test.go rename to circuit/encode/keccak/encode_test.go index 8f0929f8c..dab36d082 100644 --- a/legend/circuit/bn254/encode/keccak/encode_test.go +++ b/circuit/encode/keccak/encode_test.go @@ -15,7 +15,7 @@ import ( "github.com/ethereum/go-ethereum/crypto" "github.com/stretchr/testify/assert" - abi "github.com/bnb-chain/zkbnb-crypto/legend/circuit/bn254/encode/abi" + "github.com/bnb-chain/zkbnb-crypto/circuit/encode/abi" ) func TestAbiEncodeTransfer(t *testing.T) { @@ -661,10 +661,10 @@ func TestAbiEncodeAtomicMatch(t *testing.T) { SigS: s, } offerArray := offer.DecomposeConstraintArrays() - for i, _ := range offerArray { + for i := range offerArray { w.Values[1+i] = offerArray[i] } - for i, _ := range offerArray { + for i := range offerArray { w.Values[72+i] = offerArray[i] } w.Values[143] = uint32(1) diff --git a/legend/circuit/bn254/block/indexHelper.go b/circuit/index_helper.go similarity index 96% rename from legend/circuit/bn254/block/indexHelper.go rename to circuit/index_helper.go index ef2358707..04aaa8367 100644 --- a/legend/circuit/bn254/block/indexHelper.go +++ b/circuit/index_helper.go @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Zecrey Protocol + * Copyright © 2022 ZkBNB Protocol * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,7 +15,7 @@ * */ -package block +package circuit func AccountIndexToMerkleHelper(api API, accountIndex Variable) (merkleHelpers []Variable) { merkleHelpers = api.ToBinary(accountIndex, AccountMerkleLevels) diff --git a/legend/circuit/bn254/block/liquidityDelta.go b/circuit/liquidity_delta.go similarity index 79% rename from legend/circuit/bn254/block/liquidityDelta.go rename to circuit/liquidity_delta.go index dc18ef401..7db6cf350 100644 --- a/legend/circuit/bn254/block/liquidityDelta.go +++ b/circuit/liquidity_delta.go @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Zecrey Protocol + * Copyright © 2022 ZkBNB Protocol * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,10 +15,10 @@ * */ -package block +package circuit import ( - "github.com/bnb-chain/zkbnb-crypto/legend/circuit/bn254/std" + "github.com/bnb-chain/zkbnb-crypto/circuit/types" ) type LiquidityDeltaConstraints struct { @@ -35,15 +35,15 @@ type LiquidityDeltaConstraints struct { func EmptyLiquidityDeltaConstraints() LiquidityDeltaConstraints { return LiquidityDeltaConstraints{ - AssetAId: std.ZeroInt, - AssetBId: std.ZeroInt, - AssetADelta: std.ZeroInt, - AssetBDelta: std.ZeroInt, - LpDelta: std.ZeroInt, - KLast: std.ZeroInt, - FeeRate: std.ZeroInt, - TreasuryAccountIndex: std.ZeroInt, - TreasuryRate: std.ZeroInt, + AssetAId: types.ZeroInt, + AssetBId: types.ZeroInt, + AssetADelta: types.ZeroInt, + AssetBDelta: types.ZeroInt, + LpDelta: types.ZeroInt, + KLast: types.ZeroInt, + FeeRate: types.ZeroInt, + TreasuryAccountIndex: types.ZeroInt, + TreasuryRate: types.ZeroInt, } } diff --git a/legend/circuit/bn254/block/nftDelta.go b/circuit/nft_delta.go similarity index 79% rename from legend/circuit/bn254/block/nftDelta.go rename to circuit/nft_delta.go index 8f5e61f04..d5eafd0c9 100644 --- a/legend/circuit/bn254/block/nftDelta.go +++ b/circuit/nft_delta.go @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Zecrey Protocol + * Copyright © 2022 ZkBNB Protocol * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,10 +15,10 @@ * */ -package block +package circuit import ( - "github.com/bnb-chain/zkbnb-crypto/legend/circuit/bn254/std" + "github.com/bnb-chain/zkbnb-crypto/circuit/types" ) type NftDeltaConstraints struct { @@ -33,13 +33,13 @@ type NftDeltaConstraints struct { func EmptyNftDeltaConstraints() NftDeltaConstraints { return NftDeltaConstraints{ - CreatorAccountIndex: std.ZeroInt, - OwnerAccountIndex: std.ZeroInt, - NftContentHash: std.ZeroInt, - NftL1Address: std.ZeroInt, - NftL1TokenId: std.ZeroInt, - CreatorTreasuryRate: std.ZeroInt, - CollectionId: std.ZeroInt, + CreatorAccountIndex: types.ZeroInt, + OwnerAccountIndex: types.ZeroInt, + NftContentHash: types.ZeroInt, + NftL1Address: types.ZeroInt, + NftL1TokenId: types.ZeroInt, + CreatorTreasuryRate: types.ZeroInt, + CollectionId: types.ZeroInt, } } diff --git a/legend/circuit/bn254/solidity/zkbnb_test.go b/circuit/solidity/zkbnb_test.go similarity index 77% rename from legend/circuit/bn254/solidity/zkbnb_test.go rename to circuit/solidity/zkbnb_test.go index 4b0b55693..b6188fa37 100644 --- a/legend/circuit/bn254/solidity/zkbnb_test.go +++ b/circuit/solidity/zkbnb_test.go @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Zecrey Protocol + * Copyright © 2022 ZkBNB Protocol * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,19 +27,19 @@ import ( "github.com/consensys/gnark/frontend" "github.com/consensys/gnark/frontend/cs/r1cs" - "github.com/bnb-chain/zkbnb-crypto/legend/circuit/bn254/block" + "github.com/bnb-chain/zkbnb-crypto/circuit" ) func TestExportSol(t *testing.T) { differentBlockSizes := []int{1, 10} for i := 0; i < len(differentBlockSizes); i++ { - var circuit block.BlockConstraints - circuit.TxsCount = differentBlockSizes[i] - circuit.Txs = make([]block.TxConstraints, circuit.TxsCount) - for i := 0; i < circuit.TxsCount; i++ { - circuit.Txs[i] = block.GetZeroTxConstraint() + var blockConstrains circuit.BlockConstraints + blockConstrains.TxsCount = differentBlockSizes[i] + blockConstrains.Txs = make([]circuit.TxConstraints, blockConstrains.TxsCount) + for i := 0; i < blockConstrains.TxsCount; i++ { + blockConstrains.Txs[i] = circuit.GetZeroTxConstraint() } - oR1cs, err := frontend.Compile(ecc.BN254, r1cs.NewBuilder, &circuit, frontend.IgnoreUnconstrainedInputs()) + oR1cs, err := frontend.Compile(ecc.BN254, r1cs.NewBuilder, &blockConstrains, frontend.IgnoreUnconstrainedInputs()) if err != nil { panic(err) } diff --git a/legend/circuit/bn254/block/tx.go b/circuit/tx.go similarity index 90% rename from legend/circuit/bn254/block/tx.go rename to circuit/tx.go index b559ebd08..ecee858df 100644 --- a/legend/circuit/bn254/block/tx.go +++ b/circuit/tx.go @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Zecrey Protocol + * Copyright © 2022 ZkBNB Protocol * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,10 +15,10 @@ * */ -package block +package circuit import ( - "github.com/bnb-chain/zkbnb-crypto/legend/circuit/bn254/std" + "github.com/bnb-chain/zkbnb-crypto/circuit/types" ) type Tx struct { @@ -52,15 +52,15 @@ type Tx struct { // account root before AccountRootBefore []byte // account before info, size is 5 - AccountsInfoBefore [NbAccountsPerTx]*std.Account + AccountsInfoBefore [NbAccountsPerTx]*types.Account // liquidity root before LiquidityRootBefore []byte // liquidity before - LiquidityBefore *std.Liquidity + LiquidityBefore *types.Liquidity // nft root before NftRootBefore []byte // nft before - NftBefore *std.Nft + NftBefore *types.Nft // state root before StateRootBefore []byte // before account asset merkle proof diff --git a/legend/circuit/bn254/block/tx_addLiquidityTx_test.go b/circuit/tx_add_liquidity_test.go similarity index 99% rename from legend/circuit/bn254/block/tx_addLiquidityTx_test.go rename to circuit/tx_add_liquidity_test.go index 54f6d4750..d058e69b4 100644 --- a/legend/circuit/bn254/block/tx_addLiquidityTx_test.go +++ b/circuit/tx_add_liquidity_test.go @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Zecrey Protocol + * Copyright © 2022 ZkBNB Protocol * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,7 +15,7 @@ * */ -package block +package circuit import ( "encoding/json" @@ -26,7 +26,7 @@ import ( "github.com/consensys/gnark/frontend" "github.com/consensys/gnark/test" - "github.com/bnb-chain/zkbnb-crypto/legend/circuit/bn254/std" + "github.com/bnb-chain/zkbnb-crypto/circuit/types" ) func TestVerifyAddLiquidityTransaction(t *testing.T) { @@ -45,6 +45,6 @@ func TestVerifyAddLiquidityTransaction(t *testing.T) { assert.SolvingSucceeded( &circuit, &witness, test.WithBackends(backend.GROTH16), test.WithCurves(ecc.BN254), - test.WithProverOpts(backend.WithHints(std.Keccak256, std.ComputeSLp)), + test.WithProverOpts(backend.WithHints(types.Keccak256, types.ComputeSLp)), test.WithCompileOpts(frontend.IgnoreUnconstrainedInputs())) } diff --git a/legend/circuit/bn254/block/tx_atomicMatch_test.go b/circuit/tx_atomic_match_test.go similarity index 99% rename from legend/circuit/bn254/block/tx_atomicMatch_test.go rename to circuit/tx_atomic_match_test.go index 37b1e5541..ad6134359 100644 --- a/legend/circuit/bn254/block/tx_atomicMatch_test.go +++ b/circuit/tx_atomic_match_test.go @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Zecrey Protocol + * Copyright © 2022 ZkBNB Protocol * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,7 +15,7 @@ * */ -package block +package circuit import ( "encoding/json" @@ -26,7 +26,7 @@ import ( "github.com/consensys/gnark/frontend" "github.com/consensys/gnark/test" - "github.com/bnb-chain/zkbnb-crypto/legend/circuit/bn254/std" + "github.com/bnb-chain/zkbnb-crypto/circuit/types" ) func TestVerifyAtomicMatchTransaction(t *testing.T) { @@ -45,7 +45,7 @@ func TestVerifyAtomicMatchTransaction(t *testing.T) { assert.SolvingSucceeded( &circuit, &witness, test.WithBackends(backend.GROTH16), test.WithCurves(ecc.BN254), - test.WithProverOpts(backend.WithHints(std.Keccak256, std.ComputeSLp)), + test.WithProverOpts(backend.WithHints(types.Keccak256, types.ComputeSLp)), test.WithCompileOpts(frontend.IgnoreUnconstrainedInputs()), ) } diff --git a/legend/circuit/bn254/block/tx_cancelOfferTx_test.go b/circuit/tx_cancel_offer_test.go similarity index 99% rename from legend/circuit/bn254/block/tx_cancelOfferTx_test.go rename to circuit/tx_cancel_offer_test.go index 1b06cdac4..30d21d862 100644 --- a/legend/circuit/bn254/block/tx_cancelOfferTx_test.go +++ b/circuit/tx_cancel_offer_test.go @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Zecrey Protocol + * Copyright © 2022 ZkBNB Protocol * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,7 +15,7 @@ * */ -package block +package circuit import ( "encoding/json" @@ -26,7 +26,7 @@ import ( "github.com/consensys/gnark/frontend" "github.com/consensys/gnark/test" - "github.com/bnb-chain/zkbnb-crypto/legend/circuit/bn254/std" + "github.com/bnb-chain/zkbnb-crypto/circuit/types" ) func TestVerifyCancelOfferTransaction(t *testing.T) { @@ -45,6 +45,6 @@ func TestVerifyCancelOfferTransaction(t *testing.T) { assert.SolvingSucceeded( &circuit, &witness, test.WithBackends(backend.GROTH16), test.WithCurves(ecc.BN254), - test.WithProverOpts(backend.WithHints(std.Keccak256, std.ComputeSLp)), + test.WithProverOpts(backend.WithHints(types.Keccak256, types.ComputeSLp)), test.WithCompileOpts(frontend.IgnoreUnconstrainedInputs())) } diff --git a/legend/circuit/bn254/block/txConstraints.go b/circuit/tx_constraints.go similarity index 68% rename from legend/circuit/bn254/block/txConstraints.go rename to circuit/tx_constraints.go index d46215811..4ee14a618 100644 --- a/legend/circuit/bn254/block/txConstraints.go +++ b/circuit/tx_constraints.go @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Zecrey Protocol + * Copyright © 2022 ZkBNB Protocol * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,7 +15,7 @@ * */ -package block +package circuit import ( "errors" @@ -23,7 +23,7 @@ import ( "github.com/consensys/gnark/std/hash/mimc" - "github.com/bnb-chain/zkbnb-crypto/legend/circuit/bn254/std" + "github.com/bnb-chain/zkbnb-crypto/circuit/types" ) type TxConstraints struct { @@ -57,15 +57,15 @@ type TxConstraints struct { // account root before AccountRootBefore Variable // account before info, size is 5 - AccountsInfoBefore [NbAccountsPerTx]std.AccountConstraints + AccountsInfoBefore [NbAccountsPerTx]types.AccountConstraints // liquidity root before LiquidityRootBefore Variable // liquidity before - LiquidityBefore std.LiquidityConstraints + LiquidityBefore types.LiquidityConstraints // nft root before NftRootBefore Variable // nft before - NftBefore std.NftConstraints + NftBefore types.NftConstraints // state root before StateRootBefore Variable // before account asset merkle proof @@ -99,27 +99,27 @@ func VerifyTransaction( tx TxConstraints, hFunc MiMC, blockCreatedAt Variable, -) (isOnChainOp Variable, pubData [std.PubDataSizePerTx]Variable, err error) { +) (isOnChainOp Variable, pubData [types.PubDataSizePerTx]Variable, err error) { // compute tx type - isEmptyTx := api.IsZero(api.Sub(tx.TxType, std.TxTypeEmptyTx)) - isRegisterZnsTx := api.IsZero(api.Sub(tx.TxType, std.TxTypeRegisterZns)) - isCreatePairTx := api.IsZero(api.Sub(tx.TxType, std.TxTypeCreatePair)) - isUpdatePairRateTx := api.IsZero(api.Sub(tx.TxType, std.TxTypeUpdatePairRate)) - isDepositTx := api.IsZero(api.Sub(tx.TxType, std.TxTypeDeposit)) - isDepositNftTx := api.IsZero(api.Sub(tx.TxType, std.TxTypeDepositNft)) - isTransferTx := api.IsZero(api.Sub(tx.TxType, std.TxTypeTransfer)) - isSwapTx := api.IsZero(api.Sub(tx.TxType, std.TxTypeSwap)) - isAddLiquidityTx := api.IsZero(api.Sub(tx.TxType, std.TxTypeAddLiquidity)) - isRemoveLiquidityTx := api.IsZero(api.Sub(tx.TxType, std.TxTypeRemoveLiquidity)) - isWithdrawTx := api.IsZero(api.Sub(tx.TxType, std.TxTypeWithdraw)) - isCreateCollectionTx := api.IsZero(api.Sub(tx.TxType, std.TxTypeCreateCollection)) - isMintNftTx := api.IsZero(api.Sub(tx.TxType, std.TxTypeMintNft)) - isTransferNftTx := api.IsZero(api.Sub(tx.TxType, std.TxTypeTransferNft)) - isAtomicMatchTx := api.IsZero(api.Sub(tx.TxType, std.TxTypeAtomicMatch)) - isCancelOfferTx := api.IsZero(api.Sub(tx.TxType, std.TxTypeCancelOffer)) - isWithdrawNftTx := api.IsZero(api.Sub(tx.TxType, std.TxTypeWithdrawNft)) - isFullExitTx := api.IsZero(api.Sub(tx.TxType, std.TxTypeFullExit)) - isFullExitNftTx := api.IsZero(api.Sub(tx.TxType, std.TxTypeFullExitNft)) + isEmptyTx := api.IsZero(api.Sub(tx.TxType, types.TxTypeEmptyTx)) + isRegisterZnsTx := api.IsZero(api.Sub(tx.TxType, types.TxTypeRegisterZns)) + isCreatePairTx := api.IsZero(api.Sub(tx.TxType, types.TxTypeCreatePair)) + isUpdatePairRateTx := api.IsZero(api.Sub(tx.TxType, types.TxTypeUpdatePairRate)) + isDepositTx := api.IsZero(api.Sub(tx.TxType, types.TxTypeDeposit)) + isDepositNftTx := api.IsZero(api.Sub(tx.TxType, types.TxTypeDepositNft)) + isTransferTx := api.IsZero(api.Sub(tx.TxType, types.TxTypeTransfer)) + isSwapTx := api.IsZero(api.Sub(tx.TxType, types.TxTypeSwap)) + isAddLiquidityTx := api.IsZero(api.Sub(tx.TxType, types.TxTypeAddLiquidity)) + isRemoveLiquidityTx := api.IsZero(api.Sub(tx.TxType, types.TxTypeRemoveLiquidity)) + isWithdrawTx := api.IsZero(api.Sub(tx.TxType, types.TxTypeWithdraw)) + isCreateCollectionTx := api.IsZero(api.Sub(tx.TxType, types.TxTypeCreateCollection)) + isMintNftTx := api.IsZero(api.Sub(tx.TxType, types.TxTypeMintNft)) + isTransferNftTx := api.IsZero(api.Sub(tx.TxType, types.TxTypeTransferNft)) + isAtomicMatchTx := api.IsZero(api.Sub(tx.TxType, types.TxTypeAtomicMatch)) + isCancelOfferTx := api.IsZero(api.Sub(tx.TxType, types.TxTypeCancelOffer)) + isWithdrawNftTx := api.IsZero(api.Sub(tx.TxType, types.TxTypeWithdrawNft)) + isFullExitTx := api.IsZero(api.Sub(tx.TxType, types.TxTypeFullExit)) + isFullExitNftTx := api.IsZero(api.Sub(tx.TxType, types.TxTypeFullExitNft)) // verify nonce isLayer2Tx := api.Add( @@ -150,42 +150,42 @@ func VerifyTransaction( // get hash value from tx based on tx type // transfer tx - hashVal := std.ComputeHashFromTransferTx(tx.TransferTxInfo, tx.Nonce, tx.ExpiredAt, hFunc) + hashVal := types.ComputeHashFromTransferTx(tx.TransferTxInfo, tx.Nonce, tx.ExpiredAt, hFunc) // swap tx - hashValCheck := std.ComputeHashFromSwapTx(tx.SwapTxInfo, tx.Nonce, tx.ExpiredAt, hFunc) + hashValCheck := types.ComputeHashFromSwapTx(tx.SwapTxInfo, tx.Nonce, tx.ExpiredAt, hFunc) hashVal = api.Select(isSwapTx, hashValCheck, hashVal) // add liquidity tx - hashValCheck = std.ComputeHashFromAddLiquidityTx(tx.AddLiquidityTxInfo, tx.Nonce, tx.ExpiredAt, hFunc) + hashValCheck = types.ComputeHashFromAddLiquidityTx(tx.AddLiquidityTxInfo, tx.Nonce, tx.ExpiredAt, hFunc) hashVal = api.Select(isAddLiquidityTx, hashValCheck, hashVal) // remove liquidity tx - hashValCheck = std.ComputeHashFromRemoveLiquidityTx(tx.RemoveLiquidityTxInfo, tx.Nonce, tx.ExpiredAt, hFunc) + hashValCheck = types.ComputeHashFromRemoveLiquidityTx(tx.RemoveLiquidityTxInfo, tx.Nonce, tx.ExpiredAt, hFunc) hashVal = api.Select(isRemoveLiquidityTx, hashValCheck, hashVal) // withdraw tx - hashValCheck = std.ComputeHashFromWithdrawTx(tx.WithdrawTxInfo, tx.Nonce, tx.ExpiredAt, hFunc) + hashValCheck = types.ComputeHashFromWithdrawTx(tx.WithdrawTxInfo, tx.Nonce, tx.ExpiredAt, hFunc) hashVal = api.Select(isWithdrawTx, hashValCheck, hashVal) // createCollection tx - hashValCheck = std.ComputeHashFromCreateCollectionTx(tx.CreateCollectionTxInfo, tx.Nonce, tx.ExpiredAt, hFunc) + hashValCheck = types.ComputeHashFromCreateCollectionTx(tx.CreateCollectionTxInfo, tx.Nonce, tx.ExpiredAt, hFunc) hashVal = api.Select(isCreateCollectionTx, hashValCheck, hashVal) // mint nft tx - hashValCheck = std.ComputeHashFromMintNftTx(api, tx.MintNftTxInfo, tx.Nonce, tx.ExpiredAt, hFunc) + hashValCheck = types.ComputeHashFromMintNftTx(api, tx.MintNftTxInfo, tx.Nonce, tx.ExpiredAt, hFunc) hashVal = api.Select(isMintNftTx, hashValCheck, hashVal) // transfer nft tx - hashValCheck = std.ComputeHashFromTransferNftTx(tx.TransferNftTxInfo, tx.Nonce, tx.ExpiredAt, hFunc) + hashValCheck = types.ComputeHashFromTransferNftTx(tx.TransferNftTxInfo, tx.Nonce, tx.ExpiredAt, hFunc) hashVal = api.Select(isTransferNftTx, hashValCheck, hashVal) // set nft price tx - hashValCheck = std.ComputeHashFromAtomicMatchTx(tx.AtomicMatchTxInfo, tx.Nonce, tx.ExpiredAt, hFunc) + hashValCheck = types.ComputeHashFromAtomicMatchTx(tx.AtomicMatchTxInfo, tx.Nonce, tx.ExpiredAt, hFunc) hashVal = api.Select(isAtomicMatchTx, hashValCheck, hashVal) // buy nft tx - hashValCheck = std.ComputeHashFromCancelOfferTx(tx.CancelOfferTxInfo, tx.Nonce, tx.ExpiredAt, hFunc) + hashValCheck = types.ComputeHashFromCancelOfferTx(tx.CancelOfferTxInfo, tx.Nonce, tx.ExpiredAt, hFunc) hashVal = api.Select(isCancelOfferTx, hashValCheck, hashVal) // withdraw nft tx - hashValCheck = std.ComputeHashFromWithdrawNftTx(tx.WithdrawNftTxInfo, tx.Nonce, tx.ExpiredAt, hFunc) + hashValCheck = types.ComputeHashFromWithdrawNftTx(tx.WithdrawNftTxInfo, tx.Nonce, tx.ExpiredAt, hFunc) hashVal = api.Select(isWithdrawNftTx, hashValCheck, hashVal) hFunc.Reset() - std.IsVariableEqual(api, isLayer2Tx, tx.AccountsInfoBefore[0].Nonce, tx.Nonce) + types.IsVariableEqual(api, isLayer2Tx, tx.AccountsInfoBefore[0].Nonce, tx.Nonce) // verify signature - err = std.VerifyEddsaSig( + err = types.VerifyEddsaSig( isLayer2Tx, api, hFunc, @@ -199,43 +199,43 @@ func VerifyTransaction( } // verify transactions - for i := 0; i < std.PubDataSizePerTx; i++ { + for i := 0; i < types.PubDataSizePerTx; i++ { pubData[i] = 0 } - pubDataCheck := std.VerifyRegisterZNSTx(api, isRegisterZnsTx, tx.RegisterZnsTxInfo, tx.AccountsInfoBefore) + pubDataCheck := types.VerifyRegisterZNSTx(api, isRegisterZnsTx, tx.RegisterZnsTxInfo, tx.AccountsInfoBefore) pubData = SelectPubData(api, isRegisterZnsTx, pubDataCheck, pubData) - pubDataCheck = std.VerifyCreatePairTx(api, isCreatePairTx, tx.CreatePairTxInfo, tx.LiquidityBefore) + pubDataCheck = types.VerifyCreatePairTx(api, isCreatePairTx, tx.CreatePairTxInfo, tx.LiquidityBefore) pubData = SelectPubData(api, isCreatePairTx, pubDataCheck, pubData) - pubDataCheck = std.VerifyUpdatePairRateTx(api, isUpdatePairRateTx, tx.UpdatePairRateTxInfo, tx.LiquidityBefore) + pubDataCheck = types.VerifyUpdatePairRateTx(api, isUpdatePairRateTx, tx.UpdatePairRateTxInfo, tx.LiquidityBefore) pubData = SelectPubData(api, isUpdatePairRateTx, pubDataCheck, pubData) - pubDataCheck = std.VerifyDepositTx(api, isDepositTx, tx.DepositTxInfo, tx.AccountsInfoBefore) + pubDataCheck = types.VerifyDepositTx(api, isDepositTx, tx.DepositTxInfo, tx.AccountsInfoBefore) pubData = SelectPubData(api, isDepositTx, pubDataCheck, pubData) - pubDataCheck = std.VerifyDepositNftTx(api, isDepositNftTx, tx.DepositNftTxInfo, tx.AccountsInfoBefore, tx.NftBefore) + pubDataCheck = types.VerifyDepositNftTx(api, isDepositNftTx, tx.DepositNftTxInfo, tx.AccountsInfoBefore, tx.NftBefore) pubData = SelectPubData(api, isDepositNftTx, pubDataCheck, pubData) - pubDataCheck = std.VerifyTransferTx(api, isTransferTx, &tx.TransferTxInfo, tx.AccountsInfoBefore) + pubDataCheck = types.VerifyTransferTx(api, isTransferTx, &tx.TransferTxInfo, tx.AccountsInfoBefore) pubData = SelectPubData(api, isTransferTx, pubDataCheck, pubData) - pubDataCheck = std.VerifySwapTx(api, isSwapTx, &tx.SwapTxInfo, tx.AccountsInfoBefore, tx.LiquidityBefore) + pubDataCheck = types.VerifySwapTx(api, isSwapTx, &tx.SwapTxInfo, tx.AccountsInfoBefore, tx.LiquidityBefore) pubData = SelectPubData(api, isSwapTx, pubDataCheck, pubData) - pubDataCheck, err = std.VerifyAddLiquidityTx(api, isAddLiquidityTx, &tx.AddLiquidityTxInfo, tx.AccountsInfoBefore, tx.LiquidityBefore) + pubDataCheck, err = types.VerifyAddLiquidityTx(api, isAddLiquidityTx, &tx.AddLiquidityTxInfo, tx.AccountsInfoBefore, tx.LiquidityBefore) if err != nil { return nil, pubData, err } pubData = SelectPubData(api, isAddLiquidityTx, pubDataCheck, pubData) - pubDataCheck, err = std.VerifyRemoveLiquidityTx(api, isRemoveLiquidityTx, &tx.RemoveLiquidityTxInfo, tx.AccountsInfoBefore, tx.LiquidityBefore) + pubDataCheck, err = types.VerifyRemoveLiquidityTx(api, isRemoveLiquidityTx, &tx.RemoveLiquidityTxInfo, tx.AccountsInfoBefore, tx.LiquidityBefore) if err != nil { return nil, pubData, err } pubData = SelectPubData(api, isRemoveLiquidityTx, pubDataCheck, pubData) - pubDataCheck = std.VerifyCreateCollectionTx(api, isCreateCollectionTx, &tx.CreateCollectionTxInfo, tx.AccountsInfoBefore) + pubDataCheck = types.VerifyCreateCollectionTx(api, isCreateCollectionTx, &tx.CreateCollectionTxInfo, tx.AccountsInfoBefore) pubData = SelectPubData(api, isCreateCollectionTx, pubDataCheck, pubData) - pubDataCheck = std.VerifyWithdrawTx(api, isWithdrawTx, &tx.WithdrawTxInfo, tx.AccountsInfoBefore) + pubDataCheck = types.VerifyWithdrawTx(api, isWithdrawTx, &tx.WithdrawTxInfo, tx.AccountsInfoBefore) pubData = SelectPubData(api, isWithdrawTx, pubDataCheck, pubData) - pubDataCheck = std.VerifyMintNftTx(api, isMintNftTx, &tx.MintNftTxInfo, tx.AccountsInfoBefore, tx.NftBefore) + pubDataCheck = types.VerifyMintNftTx(api, isMintNftTx, &tx.MintNftTxInfo, tx.AccountsInfoBefore, tx.NftBefore) pubData = SelectPubData(api, isMintNftTx, pubDataCheck, pubData) - pubDataCheck = std.VerifyTransferNftTx(api, isTransferNftTx, &tx.TransferNftTxInfo, tx.AccountsInfoBefore, tx.NftBefore) + pubDataCheck = types.VerifyTransferNftTx(api, isTransferNftTx, &tx.TransferNftTxInfo, tx.AccountsInfoBefore, tx.NftBefore) pubData = SelectPubData(api, isTransferNftTx, pubDataCheck, pubData) hFunc.Reset() - pubDataCheck, err = std.VerifyAtomicMatchTx( + pubDataCheck, err = types.VerifyAtomicMatchTx( api, isAtomicMatchTx, &tx.AtomicMatchTxInfo, tx.AccountsInfoBefore, tx.NftBefore, blockCreatedAt, hFunc, ) @@ -243,17 +243,17 @@ func VerifyTransaction( return nil, pubData, err } pubData = SelectPubData(api, isAtomicMatchTx, pubDataCheck, pubData) - pubDataCheck = std.VerifyCancelOfferTx(api, isCancelOfferTx, &tx.CancelOfferTxInfo, tx.AccountsInfoBefore) + pubDataCheck = types.VerifyCancelOfferTx(api, isCancelOfferTx, &tx.CancelOfferTxInfo, tx.AccountsInfoBefore) pubData = SelectPubData(api, isCancelOfferTx, pubDataCheck, pubData) - pubDataCheck = std.VerifyWithdrawNftTx(api, isWithdrawNftTx, &tx.WithdrawNftTxInfo, tx.AccountsInfoBefore, tx.NftBefore) + pubDataCheck = types.VerifyWithdrawNftTx(api, isWithdrawNftTx, &tx.WithdrawNftTxInfo, tx.AccountsInfoBefore, tx.NftBefore) pubData = SelectPubData(api, isWithdrawNftTx, pubDataCheck, pubData) - pubDataCheck = std.VerifyFullExitTx(api, isFullExitTx, tx.FullExitTxInfo, tx.AccountsInfoBefore) + pubDataCheck = types.VerifyFullExitTx(api, isFullExitTx, tx.FullExitTxInfo, tx.AccountsInfoBefore) pubData = SelectPubData(api, isFullExitTx, pubDataCheck, pubData) - pubDataCheck = std.VerifyFullExitNftTx(api, isFullExitNftTx, tx.FullExitNftTxInfo, tx.AccountsInfoBefore, tx.NftBefore) + pubDataCheck = types.VerifyFullExitNftTx(api, isFullExitNftTx, tx.FullExitNftTxInfo, tx.AccountsInfoBefore, tx.NftBefore) pubData = SelectPubData(api, isFullExitNftTx, pubDataCheck, pubData) // verify timestamp - std.IsVariableLessOrEqual(api, isLayer2Tx, blockCreatedAt, tx.ExpiredAt) + types.IsVariableLessOrEqual(api, isLayer2Tx, blockCreatedAt, tx.ExpiredAt) // empty delta var ( @@ -272,9 +272,9 @@ func VerifyTransaction( liquidityDelta = LiquidityDeltaConstraints{ AssetAId: tx.LiquidityBefore.AssetAId, AssetBId: tx.LiquidityBefore.AssetBId, - AssetADelta: std.ZeroInt, - AssetBDelta: std.ZeroInt, - LpDelta: std.ZeroInt, + AssetADelta: types.ZeroInt, + AssetBDelta: types.ZeroInt, + LpDelta: types.ZeroInt, KLast: tx.LiquidityBefore.KLast, FeeRate: tx.LiquidityBefore.FeeRate, TreasuryAccountIndex: tx.LiquidityBefore.TreasuryAccountIndex, @@ -372,7 +372,7 @@ func VerifyTransaction( ) oldStateRoot := hFunc.Sum() notEmptyTx := api.IsZero(isEmptyTx) - std.IsVariableEqual(api, notEmptyTx, oldStateRoot, tx.StateRootBefore) + types.IsVariableEqual(api, notEmptyTx, oldStateRoot, tx.StateRootBefore) NewAccountRoot := tx.AccountRootBefore for i := 0; i < NbAccountsPerTx; i++ { @@ -392,7 +392,7 @@ func VerifyTransaction( assetNodeHash := hFunc.Sum() // verify account asset merkle proof hFunc.Reset() - std.VerifyMerkleProof( + types.VerifyMerkleProof( api, notEmptyTx, hFunc, @@ -410,7 +410,7 @@ func VerifyTransaction( assetNodeHash = hFunc.Sum() hFunc.Reset() // update merkle proof - NewAccountAssetsRoot = std.UpdateMerkleProof( + NewAccountAssetsRoot = types.UpdateMerkleProof( api, hFunc, assetNodeHash, tx.MerkleProofsAccountAssetsBefore[i][j][:], assetMerkleHelper) } // verify account node hash @@ -428,7 +428,7 @@ func VerifyTransaction( accountNodeHash := hFunc.Sum() // verify account merkle proof hFunc.Reset() - std.VerifyMerkleProof( + types.VerifyMerkleProof( api, notEmptyTx, hFunc, @@ -449,11 +449,12 @@ func VerifyTransaction( accountNodeHash = hFunc.Sum() hFunc.Reset() // update merkle proof - NewAccountRoot = std.UpdateMerkleProof(api, hFunc, accountNodeHash, tx.MerkleProofsAccountBefore[i][:], accountIndexMerkleHelper) + NewAccountRoot = types.UpdateMerkleProof(api, hFunc, accountNodeHash, tx.MerkleProofsAccountBefore[i][:], accountIndexMerkleHelper) } //// liquidity tree NewLiquidityRoot := tx.LiquidityRootBefore + api.AssertIsLessOrEqual(tx.LiquidityBefore.PairIndex, LastPairIndex) pairIndexMerkleHelper := PairIndexToMerkleHelper(api, tx.LiquidityBefore.PairIndex) hFunc.Write( tx.LiquidityBefore.AssetAId, @@ -469,7 +470,7 @@ func VerifyTransaction( liquidityNodeHash := hFunc.Sum() // verify account merkle proof hFunc.Reset() - std.VerifyMerkleProof( + types.VerifyMerkleProof( api, notEmptyTx, hFunc, @@ -493,10 +494,11 @@ func VerifyTransaction( liquidityNodeHash = hFunc.Sum() hFunc.Reset() // update merkle proof - NewLiquidityRoot = std.UpdateMerkleProof(api, hFunc, liquidityNodeHash, tx.MerkleProofsLiquidityBefore[:], pairIndexMerkleHelper) + NewLiquidityRoot = types.UpdateMerkleProof(api, hFunc, liquidityNodeHash, tx.MerkleProofsLiquidityBefore[:], pairIndexMerkleHelper) //// nft tree NewNftRoot := tx.NftRootBefore + api.AssertIsLessOrEqual(tx.NftBefore.NftIndex, LastNftIndex) nftIndexMerkleHelper := NftIndexToMerkleHelper(api, tx.NftBefore.NftIndex) hFunc.Reset() hFunc.Write( @@ -511,7 +513,7 @@ func VerifyTransaction( nftNodeHash := hFunc.Sum() // verify account merkle proof hFunc.Reset() - std.VerifyMerkleProof( + types.VerifyMerkleProof( api, notEmptyTx, hFunc, @@ -533,7 +535,7 @@ func VerifyTransaction( nftNodeHash = hFunc.Sum() hFunc.Reset() // update merkle proof - NewNftRoot = std.UpdateMerkleProof(api, hFunc, nftNodeHash, tx.MerkleProofsNftBefore[:], nftIndexMerkleHelper) + NewNftRoot = types.UpdateMerkleProof(api, hFunc, nftNodeHash, tx.MerkleProofsNftBefore[:], nftIndexMerkleHelper) // check state root hFunc.Reset() @@ -543,28 +545,28 @@ func VerifyTransaction( NewNftRoot, ) newStateRoot := hFunc.Sum() - std.IsVariableEqual(api, notEmptyTx, newStateRoot, tx.StateRootAfter) + types.IsVariableEqual(api, notEmptyTx, newStateRoot, tx.StateRootAfter) return isOnChainOp, pubData, nil } func EmptyTx() (oTx *Tx) { oTx = &Tx{ - TxType: std.TxTypeEmptyTx, + TxType: types.TxTypeEmptyTx, Nonce: 0, ExpiredAt: 0, - Signature: std.EmptySignature(), + Signature: types.EmptySignature(), AccountRootBefore: make([]byte, 32), - AccountsInfoBefore: [5]*std.Account{ - std.EmptyAccount(0, make([]byte, 32)), - std.EmptyAccount(0, make([]byte, 32)), - std.EmptyAccount(0, make([]byte, 32)), - std.EmptyAccount(0, make([]byte, 32)), - std.EmptyAccount(0, make([]byte, 32)), + AccountsInfoBefore: [5]*types.Account{ + types.EmptyAccount(0, make([]byte, 32)), + types.EmptyAccount(0, make([]byte, 32)), + types.EmptyAccount(0, make([]byte, 32)), + types.EmptyAccount(0, make([]byte, 32)), + types.EmptyAccount(0, make([]byte, 32)), }, LiquidityRootBefore: make([]byte, 32), - LiquidityBefore: std.EmptyLiquidity(0), + LiquidityBefore: types.EmptyLiquidity(0), NftRootBefore: make([]byte, 32), - NftBefore: std.EmptyNft(0), + NftBefore: types.EmptyNft(0), StateRootBefore: make([]byte, 32), MerkleProofsAccountAssetsBefore: [NbAccountsPerTx][NbAccountAssetsPerAccount][AssetMerkleLevels][]byte{}, MerkleProofsAccountBefore: [NbAccountsPerTx][AccountMerkleLevels][]byte{}, @@ -593,116 +595,116 @@ func EmptyTx() (oTx *Tx) { func SetTxWitness(oTx *Tx) (witness TxConstraints, err error) { witness.TxType = int64(oTx.TxType) - witness.RegisterZnsTxInfo = std.EmptyRegisterZnsTxWitness() - witness.CreatePairTxInfo = std.EmptyCreatePairTxWitness() - witness.UpdatePairRateTxInfo = std.EmptyUpdatePairRateTxWitness() - witness.DepositTxInfo = std.EmptyDepositTxWitness() - witness.DepositNftTxInfo = std.EmptyDepositNftTxWitness() - witness.TransferTxInfo = std.EmptyTransferTxWitness() - witness.SwapTxInfo = std.EmptySwapTxWitness() - witness.AddLiquidityTxInfo = std.EmptyAddLiquidityTxWitness() - witness.RemoveLiquidityTxInfo = std.EmptyRemoveLiquidityTxWitness() - witness.CreateCollectionTxInfo = std.EmptyCreateCollectionTxWitness() - witness.MintNftTxInfo = std.EmptyMintNftTxWitness() - witness.TransferNftTxInfo = std.EmptyTransferNftTxWitness() - witness.AtomicMatchTxInfo = std.EmptyAtomicMatchTxWitness() - witness.CancelOfferTxInfo = std.EmptyCancelOfferTxWitness() - witness.WithdrawTxInfo = std.EmptyWithdrawTxWitness() - witness.WithdrawNftTxInfo = std.EmptyWithdrawNftTxWitness() - witness.FullExitTxInfo = std.EmptyFullExitTxWitness() - witness.FullExitNftTxInfo = std.EmptyFullExitNftTxWitness() + witness.RegisterZnsTxInfo = types.EmptyRegisterZnsTxWitness() + witness.CreatePairTxInfo = types.EmptyCreatePairTxWitness() + witness.UpdatePairRateTxInfo = types.EmptyUpdatePairRateTxWitness() + witness.DepositTxInfo = types.EmptyDepositTxWitness() + witness.DepositNftTxInfo = types.EmptyDepositNftTxWitness() + witness.TransferTxInfo = types.EmptyTransferTxWitness() + witness.SwapTxInfo = types.EmptySwapTxWitness() + witness.AddLiquidityTxInfo = types.EmptyAddLiquidityTxWitness() + witness.RemoveLiquidityTxInfo = types.EmptyRemoveLiquidityTxWitness() + witness.CreateCollectionTxInfo = types.EmptyCreateCollectionTxWitness() + witness.MintNftTxInfo = types.EmptyMintNftTxWitness() + witness.TransferNftTxInfo = types.EmptyTransferNftTxWitness() + witness.AtomicMatchTxInfo = types.EmptyAtomicMatchTxWitness() + witness.CancelOfferTxInfo = types.EmptyCancelOfferTxWitness() + witness.WithdrawTxInfo = types.EmptyWithdrawTxWitness() + witness.WithdrawNftTxInfo = types.EmptyWithdrawNftTxWitness() + witness.FullExitTxInfo = types.EmptyFullExitTxWitness() + witness.FullExitNftTxInfo = types.EmptyFullExitNftTxWitness() witness.Signature = EmptySignatureWitness() witness.Nonce = oTx.Nonce witness.ExpiredAt = oTx.ExpiredAt switch oTx.TxType { - case std.TxTypeEmptyTx: + case types.TxTypeEmptyTx: break - case std.TxTypeRegisterZns: - witness.RegisterZnsTxInfo = std.SetRegisterZnsTxWitness(oTx.RegisterZnsTxInfo) + case types.TxTypeRegisterZns: + witness.RegisterZnsTxInfo = types.SetRegisterZnsTxWitness(oTx.RegisterZnsTxInfo) break - case std.TxTypeCreatePair: - witness.CreatePairTxInfo = std.SetCreatePairTxWitness(oTx.CreatePairTxInfo) + case types.TxTypeCreatePair: + witness.CreatePairTxInfo = types.SetCreatePairTxWitness(oTx.CreatePairTxInfo) break - case std.TxTypeUpdatePairRate: - witness.UpdatePairRateTxInfo = std.SetUpdatePairRateTxWitness(oTx.UpdatePairRateTxInfo) + case types.TxTypeUpdatePairRate: + witness.UpdatePairRateTxInfo = types.SetUpdatePairRateTxWitness(oTx.UpdatePairRateTxInfo) break - case std.TxTypeDeposit: - witness.DepositTxInfo = std.SetDepositTxWitness(oTx.DepositTxInfo) + case types.TxTypeDeposit: + witness.DepositTxInfo = types.SetDepositTxWitness(oTx.DepositTxInfo) break - case std.TxTypeDepositNft: - witness.DepositNftTxInfo = std.SetDepositNftTxWitness(oTx.DepositNftTxInfo) + case types.TxTypeDepositNft: + witness.DepositNftTxInfo = types.SetDepositNftTxWitness(oTx.DepositNftTxInfo) break - case std.TxTypeTransfer: - witness.TransferTxInfo = std.SetTransferTxWitness(oTx.TransferTxInfo) + case types.TxTypeTransfer: + witness.TransferTxInfo = types.SetTransferTxWitness(oTx.TransferTxInfo) witness.Signature.R.X = oTx.Signature.R.X witness.Signature.R.Y = oTx.Signature.R.Y witness.Signature.S = oTx.Signature.S[:] break - case std.TxTypeSwap: - witness.SwapTxInfo = std.SetSwapTxWitness(oTx.SwapTxInfo) + case types.TxTypeSwap: + witness.SwapTxInfo = types.SetSwapTxWitness(oTx.SwapTxInfo) witness.Signature.R.X = oTx.Signature.R.X witness.Signature.R.Y = oTx.Signature.R.Y witness.Signature.S = oTx.Signature.S[:] break - case std.TxTypeAddLiquidity: - witness.AddLiquidityTxInfo = std.SetAddLiquidityTxWitness(oTx.AddLiquidityTxInfo) + case types.TxTypeAddLiquidity: + witness.AddLiquidityTxInfo = types.SetAddLiquidityTxWitness(oTx.AddLiquidityTxInfo) witness.Signature.R.X = oTx.Signature.R.X witness.Signature.R.Y = oTx.Signature.R.Y witness.Signature.S = oTx.Signature.S[:] break - case std.TxTypeRemoveLiquidity: - witness.RemoveLiquidityTxInfo = std.SetRemoveLiquidityTxWitness(oTx.RemoveLiquidityTxInfo) + case types.TxTypeRemoveLiquidity: + witness.RemoveLiquidityTxInfo = types.SetRemoveLiquidityTxWitness(oTx.RemoveLiquidityTxInfo) witness.Signature.R.X = oTx.Signature.R.X witness.Signature.R.Y = oTx.Signature.R.Y witness.Signature.S = oTx.Signature.S[:] break - case std.TxTypeWithdraw: - witness.WithdrawTxInfo = std.SetWithdrawTxWitness(oTx.WithdrawTxInfo) + case types.TxTypeWithdraw: + witness.WithdrawTxInfo = types.SetWithdrawTxWitness(oTx.WithdrawTxInfo) witness.Signature.R.X = oTx.Signature.R.X witness.Signature.R.Y = oTx.Signature.R.Y witness.Signature.S = oTx.Signature.S[:] break - case std.TxTypeCreateCollection: - witness.CreateCollectionTxInfo = std.SetCreateCollectionTxWitness(oTx.CreateCollectionTxInfo) + case types.TxTypeCreateCollection: + witness.CreateCollectionTxInfo = types.SetCreateCollectionTxWitness(oTx.CreateCollectionTxInfo) witness.Signature.R.X = oTx.Signature.R.X witness.Signature.R.Y = oTx.Signature.R.Y witness.Signature.S = oTx.Signature.S[:] break - case std.TxTypeMintNft: - witness.MintNftTxInfo = std.SetMintNftTxWitness(oTx.MintNftTxInfo) + case types.TxTypeMintNft: + witness.MintNftTxInfo = types.SetMintNftTxWitness(oTx.MintNftTxInfo) witness.Signature.R.X = oTx.Signature.R.X witness.Signature.R.Y = oTx.Signature.R.Y witness.Signature.S = oTx.Signature.S[:] break - case std.TxTypeTransferNft: - witness.TransferNftTxInfo = std.SetTransferNftTxWitness(oTx.TransferNftTxInfo) + case types.TxTypeTransferNft: + witness.TransferNftTxInfo = types.SetTransferNftTxWitness(oTx.TransferNftTxInfo) witness.Signature.R.X = oTx.Signature.R.X witness.Signature.R.Y = oTx.Signature.R.Y witness.Signature.S = oTx.Signature.S[:] break - case std.TxTypeAtomicMatch: - witness.AtomicMatchTxInfo = std.SetAtomicMatchTxWitness(oTx.AtomicMatchTxInfo) + case types.TxTypeAtomicMatch: + witness.AtomicMatchTxInfo = types.SetAtomicMatchTxWitness(oTx.AtomicMatchTxInfo) witness.Signature.R.X = oTx.Signature.R.X witness.Signature.R.Y = oTx.Signature.R.Y witness.Signature.S = oTx.Signature.S[:] break - case std.TxTypeCancelOffer: - witness.CancelOfferTxInfo = std.SetCancelOfferTxWitness(oTx.CancelOfferTxInfo) + case types.TxTypeCancelOffer: + witness.CancelOfferTxInfo = types.SetCancelOfferTxWitness(oTx.CancelOfferTxInfo) witness.Signature.R.X = oTx.Signature.R.X witness.Signature.R.Y = oTx.Signature.R.Y witness.Signature.S = oTx.Signature.S[:] break - case std.TxTypeWithdrawNft: - witness.WithdrawNftTxInfo = std.SetWithdrawNftTxWitness(oTx.WithdrawNftTxInfo) + case types.TxTypeWithdrawNft: + witness.WithdrawNftTxInfo = types.SetWithdrawNftTxWitness(oTx.WithdrawNftTxInfo) witness.Signature.R.X = oTx.Signature.R.X witness.Signature.R.Y = oTx.Signature.R.Y witness.Signature.S = oTx.Signature.S[:] break - case std.TxTypeFullExit: - witness.FullExitTxInfo = std.SetFullExitTxWitness(oTx.FullExitTxInfo) + case types.TxTypeFullExit: + witness.FullExitTxInfo = types.SetFullExitTxWitness(oTx.FullExitTxInfo) break - case std.TxTypeFullExitNft: - witness.FullExitNftTxInfo = std.SetFullExitNftTxWitness(oTx.FullExitNftTxInfo) + case types.TxTypeFullExitNft: + witness.FullExitNftTxInfo = types.SetFullExitNftTxWitness(oTx.FullExitNftTxInfo) break default: log.Println("[SetTxWitness] invalid oTx type") @@ -717,12 +719,12 @@ func SetTxWitness(oTx *Tx) (witness TxConstraints, err error) { witness.StateRootAfter = oTx.StateRootAfter // before - witness.LiquidityBefore, err = std.SetLiquidityWitness(oTx.LiquidityBefore) + witness.LiquidityBefore, err = types.SetLiquidityWitness(oTx.LiquidityBefore) if err != nil { log.Println("[SetTxWitness] unable to set liquidity witness:", err.Error()) return witness, err } - witness.NftBefore, err = std.SetNftWitness(oTx.NftBefore) + witness.NftBefore, err = types.SetNftWitness(oTx.NftBefore) if err != nil { log.Println("[SetTxWitness] unable to set nft witness:", err.Error()) return witness, err @@ -731,7 +733,7 @@ func SetTxWitness(oTx *Tx) (witness TxConstraints, err error) { // account before info, size is 4 for i := 0; i < NbAccountsPerTx; i++ { // accounts info before - witness.AccountsInfoBefore[i], err = std.SetAccountWitness(oTx.AccountsInfoBefore[i]) + witness.AccountsInfoBefore[i], err = types.SetAccountWitness(oTx.AccountsInfoBefore[i]) if err != nil { log.Println("[SetTxWitness] err info:", err) return witness, err diff --git a/legend/circuit/bn254/block/tx_createCollectionTx_test.go b/circuit/tx_create_collection_test.go similarity index 99% rename from legend/circuit/bn254/block/tx_createCollectionTx_test.go rename to circuit/tx_create_collection_test.go index 7b120db5d..a651032c2 100644 --- a/legend/circuit/bn254/block/tx_createCollectionTx_test.go +++ b/circuit/tx_create_collection_test.go @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Zecrey Protocol + * Copyright © 2022 ZkBNB Protocol * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,7 +15,7 @@ * */ -package block +package circuit import ( "encoding/json" @@ -26,7 +26,7 @@ import ( "github.com/consensys/gnark/frontend" "github.com/consensys/gnark/test" - "github.com/bnb-chain/zkbnb-crypto/legend/circuit/bn254/std" + "github.com/bnb-chain/zkbnb-crypto/circuit/types" ) func TestVerifyCreateCollectionTransaction(t *testing.T) { @@ -45,6 +45,6 @@ func TestVerifyCreateCollectionTransaction(t *testing.T) { assert.SolvingSucceeded( &circuit, &witness, test.WithBackends(backend.GROTH16), test.WithCurves(ecc.BN254), - test.WithProverOpts(backend.WithHints(std.Keccak256, std.ComputeSLp)), + test.WithProverOpts(backend.WithHints(types.Keccak256, types.ComputeSLp)), test.WithCompileOpts(frontend.IgnoreUnconstrainedInputs())) } diff --git a/legend/circuit/bn254/block/tx_createPairTx_test.go b/circuit/tx_create_pair_test.go similarity index 99% rename from legend/circuit/bn254/block/tx_createPairTx_test.go rename to circuit/tx_create_pair_test.go index e341f7769..559dac4cc 100644 --- a/legend/circuit/bn254/block/tx_createPairTx_test.go +++ b/circuit/tx_create_pair_test.go @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Zecrey Protocol + * Copyright © 2022 ZkBNB Protocol * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,7 +15,7 @@ * */ -package block +package circuit import ( "encoding/json" @@ -26,7 +26,7 @@ import ( "github.com/consensys/gnark/frontend" "github.com/consensys/gnark/test" - "github.com/bnb-chain/zkbnb-crypto/legend/circuit/bn254/std" + "github.com/bnb-chain/zkbnb-crypto/circuit/types" ) func TestVerifyCreatePairTransaction(t *testing.T) { @@ -45,6 +45,6 @@ func TestVerifyCreatePairTransaction(t *testing.T) { assert.SolvingSucceeded( &circuit, &witness, test.WithBackends(backend.GROTH16), test.WithCurves(ecc.BN254), - test.WithProverOpts(backend.WithHints(std.Keccak256, std.ComputeSLp)), + test.WithProverOpts(backend.WithHints(types.Keccak256, types.ComputeSLp)), test.WithCompileOpts(frontend.IgnoreUnconstrainedInputs())) } diff --git a/legend/circuit/bn254/block/tx_depositNftTx_test.go b/circuit/tx_deposit_nft_test.go similarity index 99% rename from legend/circuit/bn254/block/tx_depositNftTx_test.go rename to circuit/tx_deposit_nft_test.go index df9416223..c9eb28fdd 100644 --- a/legend/circuit/bn254/block/tx_depositNftTx_test.go +++ b/circuit/tx_deposit_nft_test.go @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Zecrey Protocol + * Copyright © 2022 ZkBNB Protocol * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,7 +15,7 @@ * */ -package block +package circuit import ( "encoding/json" @@ -26,7 +26,7 @@ import ( "github.com/consensys/gnark/frontend" "github.com/consensys/gnark/test" - "github.com/bnb-chain/zkbnb-crypto/legend/circuit/bn254/std" + "github.com/bnb-chain/zkbnb-crypto/circuit/types" ) func TestVerifyDepositNftTransaction(t *testing.T) { @@ -45,6 +45,6 @@ func TestVerifyDepositNftTransaction(t *testing.T) { assert.SolvingSucceeded( &circuit, &witness, test.WithBackends(backend.GROTH16), test.WithCurves(ecc.BN254), - test.WithProverOpts(backend.WithHints(std.Keccak256, std.ComputeSLp)), + test.WithProverOpts(backend.WithHints(types.Keccak256, types.ComputeSLp)), test.WithCompileOpts(frontend.IgnoreUnconstrainedInputs())) } diff --git a/legend/circuit/bn254/block/tx_depositTx_test.go b/circuit/tx_deposit_test.go similarity index 99% rename from legend/circuit/bn254/block/tx_depositTx_test.go rename to circuit/tx_deposit_test.go index 93d289da3..1ef45f413 100644 --- a/legend/circuit/bn254/block/tx_depositTx_test.go +++ b/circuit/tx_deposit_test.go @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Zecrey Protocol + * Copyright © 2022 ZkBNB Protocol * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,7 +15,7 @@ * */ -package block +package circuit import ( "encoding/json" @@ -26,7 +26,7 @@ import ( "github.com/consensys/gnark/frontend" "github.com/consensys/gnark/test" - "github.com/bnb-chain/zkbnb-crypto/legend/circuit/bn254/std" + "github.com/bnb-chain/zkbnb-crypto/circuit/types" ) func TestVerifyDepositTransaction(t *testing.T) { @@ -45,6 +45,6 @@ func TestVerifyDepositTransaction(t *testing.T) { assert.SolvingSucceeded( &circuit, &witness, test.WithBackends(backend.GROTH16), test.WithCurves(ecc.BN254), - test.WithProverOpts(backend.WithHints(std.Keccak256, std.ComputeSLp)), + test.WithProverOpts(backend.WithHints(types.Keccak256, types.ComputeSLp)), test.WithCompileOpts(frontend.IgnoreUnconstrainedInputs())) } diff --git a/legend/circuit/bn254/block/tx_fullExitNftTx_test.go b/circuit/tx_fullexit_nft_test.go similarity index 99% rename from legend/circuit/bn254/block/tx_fullExitNftTx_test.go rename to circuit/tx_fullexit_nft_test.go index 8a9c12be2..114f0ac04 100644 --- a/legend/circuit/bn254/block/tx_fullExitNftTx_test.go +++ b/circuit/tx_fullexit_nft_test.go @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Zecrey Protocol + * Copyright © 2022 ZkBNB Protocol * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,7 +15,7 @@ * */ -package block +package circuit import ( "encoding/json" @@ -26,7 +26,7 @@ import ( "github.com/consensys/gnark/frontend" "github.com/consensys/gnark/test" - "github.com/bnb-chain/zkbnb-crypto/legend/circuit/bn254/std" + "github.com/bnb-chain/zkbnb-crypto/circuit/types" ) func TestVerifyFullExitNftTransaction(t *testing.T) { @@ -45,6 +45,6 @@ func TestVerifyFullExitNftTransaction(t *testing.T) { assert.SolvingSucceeded( &circuit, &witness, test.WithBackends(backend.GROTH16), test.WithCurves(ecc.BN254), - test.WithProverOpts(backend.WithHints(std.Keccak256, std.ComputeSLp)), + test.WithProverOpts(backend.WithHints(types.Keccak256, types.ComputeSLp)), test.WithCompileOpts(frontend.IgnoreUnconstrainedInputs())) } diff --git a/legend/circuit/bn254/block/tx_fullExitTx_test.go b/circuit/tx_fullexit_test.go similarity index 99% rename from legend/circuit/bn254/block/tx_fullExitTx_test.go rename to circuit/tx_fullexit_test.go index 21a9e1c08..e2e8b5aea 100644 --- a/legend/circuit/bn254/block/tx_fullExitTx_test.go +++ b/circuit/tx_fullexit_test.go @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Zecrey Protocol + * Copyright © 2022 ZkBNB Protocol * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,7 +15,7 @@ * */ -package block +package circuit import ( "encoding/json" @@ -26,7 +26,7 @@ import ( "github.com/consensys/gnark/frontend" "github.com/consensys/gnark/test" - "github.com/bnb-chain/zkbnb-crypto/legend/circuit/bn254/std" + "github.com/bnb-chain/zkbnb-crypto/circuit/types" ) func TestVerifyFullExitTransaction(t *testing.T) { @@ -45,6 +45,6 @@ func TestVerifyFullExitTransaction(t *testing.T) { assert.SolvingSucceeded( &circuit, &witness, test.WithBackends(backend.GROTH16), test.WithCurves(ecc.BN254), - test.WithProverOpts(backend.WithHints(std.Keccak256, std.ComputeSLp)), + test.WithProverOpts(backend.WithHints(types.Keccak256, types.ComputeSLp)), test.WithCompileOpts(frontend.IgnoreUnconstrainedInputs())) } diff --git a/legend/circuit/bn254/block/tx_mintNftTx_test.go b/circuit/tx_mint_nft_test.go similarity index 99% rename from legend/circuit/bn254/block/tx_mintNftTx_test.go rename to circuit/tx_mint_nft_test.go index 4cc05ea18..54da1961a 100644 --- a/legend/circuit/bn254/block/tx_mintNftTx_test.go +++ b/circuit/tx_mint_nft_test.go @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Zecrey Protocol + * Copyright © 2022 ZkBNB Protocol * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,7 +15,7 @@ * */ -package block +package circuit import ( "encoding/json" @@ -26,7 +26,7 @@ import ( "github.com/consensys/gnark/frontend" "github.com/consensys/gnark/test" - "github.com/bnb-chain/zkbnb-crypto/legend/circuit/bn254/std" + "github.com/bnb-chain/zkbnb-crypto/circuit/types" ) func TestVerifyMintNftTransaction(t *testing.T) { @@ -45,6 +45,6 @@ func TestVerifyMintNftTransaction(t *testing.T) { assert.SolvingSucceeded( &circuit, &witness, test.WithBackends(backend.GROTH16), test.WithCurves(ecc.BN254), - test.WithProverOpts(backend.WithHints(std.Keccak256, std.ComputeSLp)), + test.WithProverOpts(backend.WithHints(types.Keccak256, types.ComputeSLp)), test.WithCompileOpts(frontend.IgnoreUnconstrainedInputs())) } diff --git a/legend/circuit/bn254/block/tx_registerZnsTx_test.go b/circuit/tx_register_zns_test.go similarity index 99% rename from legend/circuit/bn254/block/tx_registerZnsTx_test.go rename to circuit/tx_register_zns_test.go index 50937fcee..82164d4af 100644 --- a/legend/circuit/bn254/block/tx_registerZnsTx_test.go +++ b/circuit/tx_register_zns_test.go @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Zecrey Protocol + * Copyright © 2022 ZkBNB Protocol * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,7 +15,7 @@ * */ -package block +package circuit import ( "encoding/json" @@ -26,7 +26,7 @@ import ( "github.com/consensys/gnark/frontend" "github.com/consensys/gnark/test" - "github.com/bnb-chain/zkbnb-crypto/legend/circuit/bn254/std" + "github.com/bnb-chain/zkbnb-crypto/circuit/types" ) func TestVerifyRegisterZnsTransaction(t *testing.T) { @@ -64,6 +64,6 @@ func TestVerifyRegisterZnsTransaction2(t *testing.T) { assert.SolvingSucceeded( &circuit, &witness, test.WithBackends(backend.GROTH16), test.WithCurves(ecc.BN254), - test.WithProverOpts(backend.WithHints(std.Keccak256, std.ComputeSLp)), + test.WithProverOpts(backend.WithHints(types.Keccak256, types.ComputeSLp)), test.WithCompileOpts(frontend.IgnoreUnconstrainedInputs())) } diff --git a/legend/circuit/bn254/block/tx_removeLiquidityTx_test.go b/circuit/tx_remove_liquidity_test.go similarity index 99% rename from legend/circuit/bn254/block/tx_removeLiquidityTx_test.go rename to circuit/tx_remove_liquidity_test.go index 1e1102157..0dd4e4ff5 100644 --- a/legend/circuit/bn254/block/tx_removeLiquidityTx_test.go +++ b/circuit/tx_remove_liquidity_test.go @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Zecrey Protocol + * Copyright © 2022 ZkBNB Protocol * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,7 +15,7 @@ * */ -package block +package circuit import ( "encoding/json" @@ -26,7 +26,7 @@ import ( "github.com/consensys/gnark/frontend" "github.com/consensys/gnark/test" - "github.com/bnb-chain/zkbnb-crypto/legend/circuit/bn254/std" + "github.com/bnb-chain/zkbnb-crypto/circuit/types" ) func TestVerifyRemoveLiquidityTransaction(t *testing.T) { @@ -45,6 +45,6 @@ func TestVerifyRemoveLiquidityTransaction(t *testing.T) { assert.SolvingSucceeded( &circuit, &witness, test.WithBackends(backend.GROTH16), test.WithCurves(ecc.BN254), - test.WithProverOpts(backend.WithHints(std.Keccak256, std.ComputeSLp)), + test.WithProverOpts(backend.WithHints(types.Keccak256, types.ComputeSLp)), test.WithCompileOpts(frontend.IgnoreUnconstrainedInputs())) } diff --git a/legend/circuit/bn254/block/tx_swapTx_test.go b/circuit/tx_swap_test.go similarity index 99% rename from legend/circuit/bn254/block/tx_swapTx_test.go rename to circuit/tx_swap_test.go index ce6931b42..98035268c 100644 --- a/legend/circuit/bn254/block/tx_swapTx_test.go +++ b/circuit/tx_swap_test.go @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Zecrey Protocol + * Copyright © 2022 ZkBNB Protocol * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,7 +15,7 @@ * */ -package block +package circuit import ( "encoding/json" @@ -26,7 +26,7 @@ import ( "github.com/consensys/gnark/frontend" "github.com/consensys/gnark/test" - "github.com/bnb-chain/zkbnb-crypto/legend/circuit/bn254/std" + "github.com/bnb-chain/zkbnb-crypto/circuit/types" ) func TestVerifySwapTransaction(t *testing.T) { @@ -45,6 +45,6 @@ func TestVerifySwapTransaction(t *testing.T) { assert.SolvingSucceeded( &circuit, &witness, test.WithBackends(backend.GROTH16), test.WithCurves(ecc.BN254), - test.WithProverOpts(backend.WithHints(std.Keccak256, std.ComputeSLp)), + test.WithProverOpts(backend.WithHints(types.Keccak256, types.ComputeSLp)), test.WithCompileOpts(frontend.IgnoreUnconstrainedInputs())) } diff --git a/legend/circuit/bn254/block/tx_test.go b/circuit/tx_test.go similarity index 95% rename from legend/circuit/bn254/block/tx_test.go rename to circuit/tx_test.go index e6f1ca96f..153cc2afa 100644 --- a/legend/circuit/bn254/block/tx_test.go +++ b/circuit/tx_test.go @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Zecrey Protocol + * Copyright © 2022 ZkBNB Protocol * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,7 +15,7 @@ * */ -package block +package circuit import ( "fmt" diff --git a/legend/circuit/bn254/block/tx_transferNftTx_test.go b/circuit/tx_transfer_nft_test.go similarity index 99% rename from legend/circuit/bn254/block/tx_transferNftTx_test.go rename to circuit/tx_transfer_nft_test.go index dfaef3469..dbfc5bc33 100644 --- a/legend/circuit/bn254/block/tx_transferNftTx_test.go +++ b/circuit/tx_transfer_nft_test.go @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Zecrey Protocol + * Copyright © 2022 ZkBNB Protocol * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,7 +15,7 @@ * */ -package block +package circuit import ( "encoding/json" @@ -26,7 +26,7 @@ import ( "github.com/consensys/gnark/frontend" "github.com/consensys/gnark/test" - "github.com/bnb-chain/zkbnb-crypto/legend/circuit/bn254/std" + "github.com/bnb-chain/zkbnb-crypto/circuit/types" ) func TestVerifyTransferNftTransaction(t *testing.T) { @@ -45,7 +45,7 @@ func TestVerifyTransferNftTransaction(t *testing.T) { assert.SolvingSucceeded( &circuit, &witness, test.WithBackends(backend.GROTH16), test.WithCurves(ecc.BN254), - test.WithProverOpts(backend.WithHints(std.Keccak256, std.ComputeSLp)), + test.WithProverOpts(backend.WithHints(types.Keccak256, types.ComputeSLp)), test.WithCompileOpts(frontend.IgnoreUnconstrainedInputs()), ) } diff --git a/legend/circuit/bn254/block/tx_transferTx_test.go b/circuit/tx_transfer_test.go similarity index 99% rename from legend/circuit/bn254/block/tx_transferTx_test.go rename to circuit/tx_transfer_test.go index 08c57f7fd..e02cf328b 100644 --- a/legend/circuit/bn254/block/tx_transferTx_test.go +++ b/circuit/tx_transfer_test.go @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Zecrey Protocol + * Copyright © 2022 ZkBNB Protocol * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,7 +15,7 @@ * */ -package block +package circuit import ( "encoding/json" @@ -26,7 +26,7 @@ import ( "github.com/consensys/gnark/frontend" "github.com/consensys/gnark/test" - "github.com/bnb-chain/zkbnb-crypto/legend/circuit/bn254/std" + "github.com/bnb-chain/zkbnb-crypto/circuit/types" ) func TestVerifyTransferTransaction(t *testing.T) { @@ -45,6 +45,6 @@ func TestVerifyTransferTransaction(t *testing.T) { assert.SolvingSucceeded( &circuit, &witness, test.WithBackends(backend.GROTH16), test.WithCurves(ecc.BN254), - test.WithProverOpts(backend.WithHints(std.Keccak256, std.ComputeSLp)), + test.WithProverOpts(backend.WithHints(types.Keccak256, types.ComputeSLp)), test.WithCompileOpts(frontend.IgnoreUnconstrainedInputs())) } diff --git a/legend/circuit/bn254/block/tx_updatePairRateTx_test.go b/circuit/tx_update_pair_rate_test.go similarity index 99% rename from legend/circuit/bn254/block/tx_updatePairRateTx_test.go rename to circuit/tx_update_pair_rate_test.go index 77876e18c..154ad2fc7 100644 --- a/legend/circuit/bn254/block/tx_updatePairRateTx_test.go +++ b/circuit/tx_update_pair_rate_test.go @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Zecrey Protocol + * Copyright © 2022 ZkBNB Protocol * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,7 +15,7 @@ * */ -package block +package circuit import ( "encoding/json" @@ -26,7 +26,7 @@ import ( "github.com/consensys/gnark/frontend" "github.com/consensys/gnark/test" - "github.com/bnb-chain/zkbnb-crypto/legend/circuit/bn254/std" + "github.com/bnb-chain/zkbnb-crypto/circuit/types" ) func TestVerifyUpdatePairRateTransaction(t *testing.T) { @@ -45,6 +45,6 @@ func TestVerifyUpdatePairRateTransaction(t *testing.T) { assert.SolvingSucceeded( &circuit, &witness, test.WithBackends(backend.GROTH16), test.WithCurves(ecc.BN254), - test.WithProverOpts(backend.WithHints(std.Keccak256, std.ComputeSLp)), + test.WithProverOpts(backend.WithHints(types.Keccak256, types.ComputeSLp)), test.WithCompileOpts(frontend.IgnoreUnconstrainedInputs())) } diff --git a/legend/circuit/bn254/block/tx_withdrawNftTx_test.go b/circuit/tx_withdraw_nft_test.go similarity index 99% rename from legend/circuit/bn254/block/tx_withdrawNftTx_test.go rename to circuit/tx_withdraw_nft_test.go index 605aa5c72..579594684 100644 --- a/legend/circuit/bn254/block/tx_withdrawNftTx_test.go +++ b/circuit/tx_withdraw_nft_test.go @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Zecrey Protocol + * Copyright © 2022 ZkBNB Protocol * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,7 +15,7 @@ * */ -package block +package circuit import ( "encoding/json" @@ -26,7 +26,7 @@ import ( "github.com/consensys/gnark/frontend" "github.com/consensys/gnark/test" - "github.com/bnb-chain/zkbnb-crypto/legend/circuit/bn254/std" + "github.com/bnb-chain/zkbnb-crypto/circuit/types" ) func TestVerifyWithdrawNftTransaction(t *testing.T) { @@ -45,7 +45,7 @@ func TestVerifyWithdrawNftTransaction(t *testing.T) { assert.SolvingSucceeded( &circuit, &witness, test.WithBackends(backend.GROTH16), test.WithCurves(ecc.BN254), - test.WithProverOpts(backend.WithHints(std.Keccak256, std.ComputeSLp)), + test.WithProverOpts(backend.WithHints(types.Keccak256, types.ComputeSLp)), test.WithCompileOpts(frontend.IgnoreUnconstrainedInputs()), ) } diff --git a/legend/circuit/bn254/block/tx_withdrawTx_test.go b/circuit/tx_withdraw_test.go similarity index 99% rename from legend/circuit/bn254/block/tx_withdrawTx_test.go rename to circuit/tx_withdraw_test.go index 4b4f7c347..fcbf68a2b 100644 --- a/legend/circuit/bn254/block/tx_withdrawTx_test.go +++ b/circuit/tx_withdraw_test.go @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Zecrey Protocol + * Copyright © 2022 ZkBNB Protocol * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,7 +15,7 @@ * */ -package block +package circuit import ( "encoding/json" @@ -26,7 +26,7 @@ import ( "github.com/consensys/gnark/frontend" "github.com/consensys/gnark/test" - "github.com/bnb-chain/zkbnb-crypto/legend/circuit/bn254/std" + "github.com/bnb-chain/zkbnb-crypto/circuit/types" ) func TestVerifyWithdrawTransaction(t *testing.T) { @@ -45,6 +45,6 @@ func TestVerifyWithdrawTransaction(t *testing.T) { assert.SolvingSucceeded( &circuit, &witness, test.WithBackends(backend.GROTH16), test.WithCurves(ecc.BN254), - test.WithProverOpts(backend.WithHints(std.Keccak256, std.ComputeSLp)), + test.WithProverOpts(backend.WithHints(types.Keccak256, types.ComputeSLp)), test.WithCompileOpts(frontend.IgnoreUnconstrainedInputs())) } diff --git a/circuit/types.go b/circuit/types.go new file mode 100644 index 000000000..f97129618 --- /dev/null +++ b/circuit/types.go @@ -0,0 +1,94 @@ +/* + * Copyright © 2022 ZkBNB Protocol + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package circuit + +import ( + "github.com/consensys/gnark-crypto/ecc/bn254/twistededwards/eddsa" + "github.com/consensys/gnark/frontend" + "github.com/consensys/gnark/std/hash/mimc" + eddsaConstraints "github.com/consensys/gnark/std/signature/eddsa" + + "github.com/bnb-chain/zkbnb-crypto/circuit/types" +) + +type ( + Variable = frontend.Variable + + Signature = eddsa.Signature + SignatureConstraints = eddsaConstraints.Signature + API = frontend.API + MiMC = mimc.MiMC + + RegisterZnsTx = types.RegisterZnsTx + CreatePairTx = types.CreatePairTx + UpdatePairRateTx = types.UpdatePairRateTx + DepositTx = types.DepositTx + DepositNftTx = types.DepositNftTx + TransferTx = types.TransferTx + SwapTx = types.SwapTx + AddLiquidityTx = types.AddLiquidityTx + RemoveLiquidityTx = types.RemoveLiquidityTx + CreateCollectionTx = types.CreateCollectionTx + MintNftTx = types.MintNftTx + TransferNftTx = types.TransferNftTx + AtomicMatchTx = types.AtomicMatchTx + CancelOfferTx = types.CancelOfferTx + WithdrawTx = types.WithdrawTx + WithdrawNftTx = types.WithdrawNftTx + FullExitTx = types.FullExitTx + FullExitNftTx = types.FullExitNftTx + + RegisterZnsTxConstraints = types.RegisterZnsTxConstraints + CreatePairTxConstraints = types.CreatePairTxConstraints + UpdatePairRateTxConstraints = types.UpdatePairRateTxConstraints + DepositTxConstraints = types.DepositTxConstraints + DepositNftTxConstraints = types.DepositNftTxConstraints + TransferTxConstraints = types.TransferTxConstraints + SwapTxConstraints = types.SwapTxConstraints + AddLiquidityTxConstraints = types.AddLiquidityTxConstraints + RemoveLiquidityTxConstraints = types.RemoveLiquidityTxConstraints + CreateCollectionTxConstraints = types.CreateCollectionTxConstraints + MintNftTxConstraints = types.MintNftTxConstraints + TransferNftTxConstraints = types.TransferNftTxConstraints + AtomicMatchTxConstraints = types.AtomicMatchTxConstraints + CancelOfferTxConstraints = types.CancelOfferTxConstraints + WithdrawTxConstraints = types.WithdrawTxConstraints + WithdrawNftTxConstraints = types.WithdrawNftTxConstraints + FullExitTxConstraints = types.FullExitTxConstraints + FullExitNftTxConstraints = types.FullExitNftTxConstraints + + LiquidityConstraints = types.LiquidityConstraints + NftConstraints = types.NftConstraints +) + +const ( + NbAccountAssetsPerAccount = types.NbAccountAssetsPerAccount + NbAccountsPerTx = types.NbAccountsPerTx + AssetMerkleLevels = 16 + LiquidityMerkleLevels = 16 + NftMerkleLevels = 40 + AccountMerkleLevels = 32 + RateBase = types.RateBase + OfferSizePerAsset = 128 + + LastAccountIndex = 4294967295 + LastAccountAssetId = 65535 + + LastPairIndex = 65535 + LastNftIndex = 1099511627775 +) diff --git a/legend/circuit/bn254/std/account.go b/circuit/types/account.go similarity index 95% rename from legend/circuit/bn254/std/account.go rename to circuit/types/account.go index 94dd0390b..ee104f22b 100644 --- a/legend/circuit/bn254/std/account.go +++ b/circuit/types/account.go @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Zecrey Protocol + * Copyright © 2022 ZkBNB Protocol * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,7 +15,7 @@ * */ -package std +package types import ( "math/big" @@ -26,9 +26,6 @@ import ( curve "github.com/bnb-chain/zkbnb-crypto/ecc/ztwistededwards/tebn254" ) -/* - Account: account info -*/ type Account struct { AccountIndex int64 AccountNameHash []byte @@ -61,9 +58,6 @@ func EmptyAccount(accountIndex int64, assetRoot []byte) *Account { } } -/* - AccountAsset: asset info -*/ type AccountAsset struct { AssetId int64 Balance *big.Int diff --git a/legend/circuit/bn254/std/accountConstraints.go b/circuit/types/account_constraints.go similarity index 98% rename from legend/circuit/bn254/std/accountConstraints.go rename to circuit/types/account_constraints.go index 3bd98d75b..1d1ac13c9 100644 --- a/legend/circuit/bn254/std/accountConstraints.go +++ b/circuit/types/account_constraints.go @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Zecrey Protocol + * Copyright © 2022 ZkBNB Protocol * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,7 +15,7 @@ * */ -package std +package types import ( "errors" diff --git a/legend/circuit/bn254/std/addLiquidity.go b/circuit/types/add_liquidity.go similarity index 99% rename from legend/circuit/bn254/std/addLiquidity.go rename to circuit/types/add_liquidity.go index d2818fa35..ef2214cf3 100644 --- a/legend/circuit/bn254/std/addLiquidity.go +++ b/circuit/types/add_liquidity.go @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Zecrey Protocol + * Copyright © 2022 ZkBNB Protocol * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,7 +15,7 @@ * */ -package std +package types type AddLiquidityTx struct { FromAccountIndex int64 diff --git a/legend/circuit/bn254/std/atomicMatch.go b/circuit/types/atomic_match.go similarity index 99% rename from legend/circuit/bn254/std/atomicMatch.go rename to circuit/types/atomic_match.go index 07226b2de..9b1acef4d 100644 --- a/legend/circuit/bn254/std/atomicMatch.go +++ b/circuit/types/atomic_match.go @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Zecrey Protocol + * Copyright © 2022 ZkBNB Protocol * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,7 +15,7 @@ * */ -package std +package types type AtomicMatchTx struct { AccountIndex int64 diff --git a/legend/circuit/bn254/std/cancelOffer.go b/circuit/types/cancel_offer.go similarity index 98% rename from legend/circuit/bn254/std/cancelOffer.go rename to circuit/types/cancel_offer.go index f312c1125..c37da2360 100644 --- a/legend/circuit/bn254/std/cancelOffer.go +++ b/circuit/types/cancel_offer.go @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Zecrey Protocol + * Copyright © 2022 ZkBNB Protocol * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,7 +15,7 @@ * */ -package std +package types type CancelOfferTx struct { AccountIndex int64 diff --git a/legend/circuit/bn254/std/comparators.go b/circuit/types/comparators.go similarity index 88% rename from legend/circuit/bn254/std/comparators.go rename to circuit/types/comparators.go index f9d163038..b22a4f622 100644 --- a/legend/circuit/bn254/std/comparators.go +++ b/circuit/types/comparators.go @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Zecrey Protocol + * Copyright © 2022 ZkBNB Protocol * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,11 +15,8 @@ * */ -package std +package types -/* - IsVariableEqual: check if two variables are equal, will force equal if isEnabled = false -*/ func IsVariableEqual(api API, isEnabled, i1, i2 Variable) { zero := 0 i1 = api.Select(isEnabled, i1, zero) diff --git a/legend/circuit/bn254/std/constants.go b/circuit/types/constants.go similarity index 93% rename from legend/circuit/bn254/std/constants.go rename to circuit/types/constants.go index 9cf6f035f..a527c49c9 100644 --- a/legend/circuit/bn254/std/constants.go +++ b/circuit/types/constants.go @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Zecrey Protocol + * Copyright © 2022 ZkBNB Protocol * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,7 +15,7 @@ * */ -package std +package types import ( "math/big" @@ -24,8 +24,6 @@ import ( "github.com/consensys/gnark/frontend" "github.com/consensys/gnark/std/hash/mimc" eddsaConstraints "github.com/consensys/gnark/std/signature/eddsa" - - "github.com/bnb-chain/zkbnb-crypto/common" ) type ( @@ -47,7 +45,7 @@ const ( OfferSizePerAsset = 128 - ChainId = common.ChainId + ChainId = 1 ) const ( diff --git a/legend/circuit/bn254/std/createCollection.go b/circuit/types/create_collection.go similarity index 98% rename from legend/circuit/bn254/std/createCollection.go rename to circuit/types/create_collection.go index 3a659fab4..e84855860 100644 --- a/legend/circuit/bn254/std/createCollection.go +++ b/circuit/types/create_collection.go @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Zecrey Protocol + * Copyright © 2022 ZkBNB Protocol * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,7 +15,7 @@ * */ -package std +package types type CreateCollectionTx struct { AccountIndex int64 diff --git a/legend/circuit/bn254/std/createPair.go b/circuit/types/create_pair.go similarity index 97% rename from legend/circuit/bn254/std/createPair.go rename to circuit/types/create_pair.go index 4acbd60f6..a3a2b4b38 100644 --- a/legend/circuit/bn254/std/createPair.go +++ b/circuit/types/create_pair.go @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Zecrey Protocol + * Copyright © 2022 ZkBNB Protocol * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,7 +15,7 @@ * */ -package std +package types type CreatePairTx struct { PairIndex int64 diff --git a/legend/circuit/bn254/std/deposit.go b/circuit/types/deposit.go similarity index 97% rename from legend/circuit/bn254/std/deposit.go rename to circuit/types/deposit.go index 980238f2f..b03d554c1 100644 --- a/legend/circuit/bn254/std/deposit.go +++ b/circuit/types/deposit.go @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Zecrey Protocol + * Copyright © 2022 ZkBNB Protocol * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,7 +15,7 @@ * */ -package std +package types import ( "math/big" diff --git a/legend/circuit/bn254/std/depositNFT.go b/circuit/types/deposit_nft.go similarity index 98% rename from legend/circuit/bn254/std/depositNFT.go rename to circuit/types/deposit_nft.go index e2087ba5d..5e9329e97 100644 --- a/legend/circuit/bn254/std/depositNFT.go +++ b/circuit/types/deposit_nft.go @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Zecrey Protocol + * Copyright © 2022 ZkBNB Protocol * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,7 +15,7 @@ * */ -package std +package types import ( "math/big" diff --git a/legend/circuit/bn254/std/eddsa.go b/circuit/types/eddsa.go similarity index 93% rename from legend/circuit/bn254/std/eddsa.go rename to circuit/types/eddsa.go index 04bc8d55b..06c58dc95 100644 --- a/legend/circuit/bn254/std/eddsa.go +++ b/circuit/types/eddsa.go @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Zecrey Protocol + * Copyright © 2022 ZkBNB Protocol * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,7 +15,7 @@ * */ -package std +package types import ( "errors" @@ -90,8 +90,3 @@ func verifySignature(flag Variable, curve twistededwards.Curve, sig eddsa.Signat return nil } - -func IsEqualPubKey(api API, a, b PublicKeyConstraints) { - api.AssertIsEqual(a.A.X, b.A.X) - api.AssertIsEqual(a.A.Y, b.A.Y) -} diff --git a/legend/circuit/bn254/std/fullExit.go b/circuit/types/fullexit.go similarity index 97% rename from legend/circuit/bn254/std/fullExit.go rename to circuit/types/fullexit.go index e7d75c974..c707250f3 100644 --- a/legend/circuit/bn254/std/fullExit.go +++ b/circuit/types/fullexit.go @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Zecrey Protocol + * Copyright © 2022 ZkBNB Protocol * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,7 +15,7 @@ * */ -package std +package types import ( "math/big" diff --git a/legend/circuit/bn254/std/fullExitNft.go b/circuit/types/fullexit_nft.go similarity index 93% rename from legend/circuit/bn254/std/fullExitNft.go rename to circuit/types/fullexit_nft.go index 0d63cef40..33bb0bfda 100644 --- a/legend/circuit/bn254/std/fullExitNft.go +++ b/circuit/types/fullexit_nft.go @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Zecrey Protocol + * Copyright © 2022 ZkBNB Protocol * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,7 +15,7 @@ * */ -package std +package types import ( "math/big" @@ -90,8 +90,8 @@ func VerifyFullExitNftTx( IsVariableEqual(api, flag, tx.NftIndex, nftBefore.NftIndex) isCheck := api.IsZero(api.IsZero(tx.CreatorAccountNameHash)) isCheck = api.And(flag, isCheck) - IsVariableEqual(api, flag, tx.CreatorAccountIndex, nftBefore.CreatorAccountIndex) - IsVariableEqual(api, flag, tx.CreatorTreasuryRate, nftBefore.CreatorTreasuryRate) + IsVariableEqual(api, isCheck, tx.CreatorAccountIndex, nftBefore.CreatorAccountIndex) + IsVariableEqual(api, isCheck, tx.CreatorTreasuryRate, nftBefore.CreatorTreasuryRate) isOwner := api.And(api.IsZero(api.Sub(tx.AccountIndex, nftBefore.OwnerAccountIndex)), flag) IsVariableEqual(api, isOwner, tx.NftContentHash, nftBefore.NftContentHash) IsVariableEqual(api, isOwner, tx.NftL1Address, nftBefore.NftL1Address) diff --git a/circuit/types/hint.go b/circuit/types/hint.go new file mode 100644 index 000000000..e31237c66 --- /dev/null +++ b/circuit/types/hint.go @@ -0,0 +1,20 @@ +package types + +import ( + "bytes" + "math/big" + + "github.com/consensys/gnark-crypto/ecc" + "github.com/ethereum/go-ethereum/crypto" +) + +func Keccak256(_ ecc.ID, inputs []*big.Int, outputs []*big.Int) error { + var buf bytes.Buffer + for i := 0; i < len(inputs); i++ { + buf.Write(inputs[i].FillBytes(make([]byte, 32))) + } + hashVal := crypto.Keccak256Hash(buf.Bytes()) + result := outputs[0] + result.SetBytes(hashVal[:]) + return nil +} diff --git a/legend/circuit/bn254/std/hint_test.go b/circuit/types/hint_test.go similarity index 98% rename from legend/circuit/bn254/std/hint_test.go rename to circuit/types/hint_test.go index 75234dc27..d2e605047 100644 --- a/legend/circuit/bn254/std/hint_test.go +++ b/circuit/types/hint_test.go @@ -1,4 +1,4 @@ -package std +package types import ( "bytes" diff --git a/legend/circuit/bn254/std/liquidity.go b/circuit/types/liquidity.go similarity index 96% rename from legend/circuit/bn254/std/liquidity.go rename to circuit/types/liquidity.go index eabda0a16..4c93420b0 100644 --- a/legend/circuit/bn254/std/liquidity.go +++ b/circuit/types/liquidity.go @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Zecrey Protocol + * Copyright © 2022 ZkBNB Protocol * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,7 +15,7 @@ * */ -package std +package types import ( "math/big" diff --git a/legend/circuit/bn254/std/liquidityConstraints.go b/circuit/types/liquidity_constraints.go similarity index 95% rename from legend/circuit/bn254/std/liquidityConstraints.go rename to circuit/types/liquidity_constraints.go index b8571b0ab..6e83db7fc 100644 --- a/legend/circuit/bn254/std/liquidityConstraints.go +++ b/circuit/types/liquidity_constraints.go @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Zecrey Protocol + * Copyright © 2022 ZkBNB Protocol * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,7 +15,7 @@ * */ -package std +package types import ( "errors" @@ -47,9 +47,6 @@ func CheckEmptyLiquidityNode(api API, flag Variable, liquidity LiquidityConstrai IsVariableEqual(api, flag, liquidity.TreasuryRate, ZeroInt) } -/* - SetLiquidityWitness: set liquidity witness -*/ func SetLiquidityWitness(liquidity *Liquidity) (witness LiquidityConstraints, err error) { if liquidity == nil { log.Println("[SetLiquidityWitness] invalid params") diff --git a/legend/circuit/bn254/std/merkle.go b/circuit/types/merkle.go similarity index 83% rename from legend/circuit/bn254/std/merkle.go rename to circuit/types/merkle.go index 6fc49a9b2..81f2cfcf3 100644 --- a/legend/circuit/bn254/std/merkle.go +++ b/circuit/types/merkle.go @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Zecrey Protocol + * Copyright © 2022 ZkBNB Protocol * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,13 +15,14 @@ * */ -package std +package types /* - VerifyMerkleProof: takes a Merkle root, a proofSet, and a proofIndex and returns - true if the first element of the proof set is a leaf of data in the Merkle - root. False is returned if the proof set or Merkle root is nil, and if - 'numLeaves' equals 0. +VerifyMerkleProof: takes a Merkle root, a proofSet, and a proofIndex and returns + + true if the first element of the proof set is a leaf of data in the Merkle + root. False is returned if the proof set or Merkle root is nil, and if + 'numLeaves' equals 0. */ func VerifyMerkleProof(api API, isEnabled Variable, h MiMC, merkleRoot Variable, node Variable, proofSet, helper []Variable) { for i := 0; i < len(proofSet); i++ { diff --git a/legend/circuit/bn254/std/mintNft.go b/circuit/types/mint_nft.go similarity index 98% rename from legend/circuit/bn254/std/mintNft.go rename to circuit/types/mint_nft.go index 0abc46514..5d7eb16ea 100644 --- a/legend/circuit/bn254/std/mintNft.go +++ b/circuit/types/mint_nft.go @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Zecrey Protocol + * Copyright © 2022 ZkBNB Protocol * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,7 +15,7 @@ * */ -package std +package types type MintNftTx struct { CreatorAccountIndex int64 diff --git a/legend/circuit/bn254/std/nft.go b/circuit/types/nft.go similarity index 95% rename from legend/circuit/bn254/std/nft.go rename to circuit/types/nft.go index 54e393352..69fa5e89c 100644 --- a/legend/circuit/bn254/std/nft.go +++ b/circuit/types/nft.go @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Zecrey Protocol + * Copyright © 2022 ZkBNB Protocol * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,7 +15,7 @@ * */ -package std +package types import ( "math/big" diff --git a/legend/circuit/bn254/std/nftConstraints.go b/circuit/types/nft_constraints.go similarity index 97% rename from legend/circuit/bn254/std/nftConstraints.go rename to circuit/types/nft_constraints.go index efd2e1c4b..c90c1f3d3 100644 --- a/legend/circuit/bn254/std/nftConstraints.go +++ b/circuit/types/nft_constraints.go @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Zecrey Protocol + * Copyright © 2022 ZkBNB Protocol * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,7 +15,7 @@ * */ -package std +package types import ( "errors" diff --git a/legend/circuit/bn254/std/offer.go b/circuit/types/offer.go similarity index 97% rename from legend/circuit/bn254/std/offer.go rename to circuit/types/offer.go index 6a6720dd5..6a85462f6 100644 --- a/legend/circuit/bn254/std/offer.go +++ b/circuit/types/offer.go @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Zecrey Protocol + * Copyright © 2022 ZkBNB Protocol * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,7 +15,7 @@ * */ -package std +package types import ( oEddsa "github.com/consensys/gnark-crypto/ecc/bn254/twistededwards/eddsa" diff --git a/legend/circuit/bn254/std/packedAmountHelper.go b/circuit/types/packed_amount_helper.go similarity index 96% rename from legend/circuit/bn254/std/packedAmountHelper.go rename to circuit/types/packed_amount_helper.go index c8f676c30..5dbbfb6a3 100644 --- a/legend/circuit/bn254/std/packedAmountHelper.go +++ b/circuit/types/packed_amount_helper.go @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Zecrey Protocol + * Copyright © 2022 ZkBNB Protocol * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,7 +15,7 @@ * */ -package std +package types func UnpackAmount(api API, packedAmount Variable) Variable { amountBits := api.ToBinary(packedAmount, 40) diff --git a/legend/circuit/bn254/std/pubdataHelper.go b/circuit/types/pubdata_helper.go similarity index 99% rename from legend/circuit/bn254/std/pubdataHelper.go rename to circuit/types/pubdata_helper.go index df17e8157..6b6928c1e 100644 --- a/legend/circuit/bn254/std/pubdataHelper.go +++ b/circuit/types/pubdata_helper.go @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Zecrey Protocol + * Copyright © 2022 ZkBNB Protocol * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,7 +15,7 @@ * */ -package std +package types func CollectPubDataFromRegisterZNS(api API, txInfo RegisterZnsTxConstraints) (pubData [PubDataSizePerTx]Variable) { txTypeBits := api.ToBinary(TxTypeRegisterZns, TxTypeBitsSize) diff --git a/legend/circuit/bn254/std/registerZNS.go b/circuit/types/register_zns.go similarity index 97% rename from legend/circuit/bn254/std/registerZNS.go rename to circuit/types/register_zns.go index 8af7d55d9..011d70898 100644 --- a/legend/circuit/bn254/std/registerZNS.go +++ b/circuit/types/register_zns.go @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Zecrey Protocol + * Copyright © 2022 ZkBNB Protocol * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,7 +15,7 @@ * */ -package std +package types import ( "github.com/consensys/gnark-crypto/ecc/bn254/twistededwards/eddsa" diff --git a/legend/circuit/bn254/std/removeLiquidity.go b/circuit/types/remove_liquidity.go similarity index 99% rename from legend/circuit/bn254/std/removeLiquidity.go rename to circuit/types/remove_liquidity.go index 4a62aeaf6..902be67ee 100644 --- a/legend/circuit/bn254/std/removeLiquidity.go +++ b/circuit/types/remove_liquidity.go @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Zecrey Protocol + * Copyright © 2022 ZkBNB Protocol * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,7 +15,7 @@ * */ -package std +package types type RemoveLiquidityTx struct { FromAccountIndex int64 diff --git a/legend/circuit/bn254/std/swap.go b/circuit/types/swap.go similarity index 99% rename from legend/circuit/bn254/std/swap.go rename to circuit/types/swap.go index 45640896b..fa1fb70b8 100644 --- a/legend/circuit/bn254/std/swap.go +++ b/circuit/types/swap.go @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Zecrey Protocol + * Copyright © 2022 ZkBNB Protocol * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,7 +15,7 @@ * */ -package std +package types type SwapTx struct { FromAccountIndex int64 diff --git a/legend/circuit/bn254/std/transfer.go b/circuit/types/transfer.go similarity index 98% rename from legend/circuit/bn254/std/transfer.go rename to circuit/types/transfer.go index 7e0ee4579..2802e682a 100644 --- a/legend/circuit/bn254/std/transfer.go +++ b/circuit/types/transfer.go @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Zecrey Protocol + * Copyright © 2022 ZkBNB Protocol * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,7 +15,7 @@ * */ -package std +package types type TransferTx struct { FromAccountIndex int64 diff --git a/legend/circuit/bn254/std/transferNft.go b/circuit/types/transfer_nft.go similarity index 98% rename from legend/circuit/bn254/std/transferNft.go rename to circuit/types/transfer_nft.go index bb094f572..9b9b5bb30 100644 --- a/legend/circuit/bn254/std/transferNft.go +++ b/circuit/types/transfer_nft.go @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Zecrey Protocol + * Copyright © 2022 ZkBNB Protocol * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,7 +15,7 @@ * */ -package std +package types type TransferNftTx struct { FromAccountIndex int64 diff --git a/legend/circuit/bn254/std/typeSize.go b/circuit/types/typesize.go similarity index 80% rename from legend/circuit/bn254/std/typeSize.go rename to circuit/types/typesize.go index b772d092f..5482aaaa8 100644 --- a/legend/circuit/bn254/std/typeSize.go +++ b/circuit/types/typesize.go @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Zecrey Protocol + * Copyright © 2022 ZkBNB Protocol * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,7 +15,7 @@ * */ -package std +package types const ( TxTypeBitsSize = 8 @@ -26,16 +26,10 @@ const ( AccountIndexBitsSize = 32 PairIndexBitsSize = 16 AssetIdBitsSize = 16 - AccountNameBitsSize = 256 - AccountNameHashBitsSize = 256 - PubKeyBitsSize = 256 NftIndexBitsSize = 40 - NftContentHashBitsSize = 256 - NftL1TokenIdBitsSize = 256 CreatorTreasuryRateBitsSize = 16 StateAmountBitsSize = 128 PackedAmountBitsSize = 40 PackedFeeBitsSize = 16 - CallDataHashBitsSize = 256 AddressBitsSize = 160 ) diff --git a/legend/circuit/bn254/std/updatePairRate.go b/circuit/types/update_pair_rate.go similarity index 97% rename from legend/circuit/bn254/std/updatePairRate.go rename to circuit/types/update_pair_rate.go index f535c3885..3dec79864 100644 --- a/legend/circuit/bn254/std/updatePairRate.go +++ b/circuit/types/update_pair_rate.go @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Zecrey Protocol + * Copyright © 2022 ZkBNB Protocol * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,7 +15,7 @@ * */ -package std +package types type UpdatePairRateTx struct { PairIndex int64 diff --git a/legend/circuit/bn254/std/utils.go b/circuit/types/utils.go similarity index 55% rename from legend/circuit/bn254/std/utils.go rename to circuit/types/utils.go index 476880e1a..053e28493 100644 --- a/legend/circuit/bn254/std/utils.go +++ b/circuit/types/utils.go @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Zecrey Protocol + * Copyright © 2022 ZkBNB Protocol * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,12 +15,17 @@ * */ -package std +package types import ( + "errors" + "github.com/bnb-chain/zkbnb-crypto/ffmath" + "github.com/bnb-chain/zkbnb-crypto/util" + "github.com/consensys/gnark-crypto/ecc" "github.com/consensys/gnark-crypto/ecc/bn254/twistededwards/eddsa" "github.com/consensys/gnark/std/algebra/twistededwards" eddsaConstraints "github.com/consensys/gnark/std/signature/eddsa" + "math/big" ) func SetPubKeyWitness(pk *eddsa.PublicKey) (witness eddsaConstraints.PublicKey) { @@ -48,3 +53,32 @@ func Min(api API, a, b Variable) Variable { minAB := api.Select(api.IsZero(api.Add(1, api.Cmp(a, b))), a, b) return minAB } + + +func ComputeSLp(curveID ecc.ID, inputs []*big.Int, outputs []*big.Int) error { + if len(inputs) != 5 { + return errors.New("[ComputeSLp] invalid params") + } + poolA := inputs[0] + poolB := inputs[1] + kLast := inputs[2] + feeRate := inputs[3] + treasuryRate := inputs[4] + if poolA.Cmp(util.ZeroBigInt) == 0 || poolB.Cmp(util.ZeroBigInt) == 0 { + outputs[0] = util.ZeroBigInt + return nil + } + kCurrent := ffmath.Multiply(poolA, poolB) + kLast.Sqrt(kLast) + kCurrent.Sqrt(kCurrent) + l := ffmath.Multiply(ffmath.Sub(kCurrent, kLast), big.NewInt(RateBase)) + r := ffmath.Multiply(ffmath.Sub(ffmath.Multiply(big.NewInt(RateBase), ffmath.Div(feeRate, treasuryRate)), big.NewInt(RateBase)), kCurrent) + r = ffmath.Add(r, ffmath.Multiply(big.NewInt(RateBase), kLast)) + var err error + outputs[0], err = util.CleanPackedAmount(ffmath.Div(l, r)) + if err != nil { + return err + } + return nil +} + diff --git a/legend/circuit/bn254/std/withdraw.go b/circuit/types/withdraw.go similarity index 98% rename from legend/circuit/bn254/std/withdraw.go rename to circuit/types/withdraw.go index 849c3757a..23af61145 100644 --- a/legend/circuit/bn254/std/withdraw.go +++ b/circuit/types/withdraw.go @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Zecrey Protocol + * Copyright © 2022 ZkBNB Protocol * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,7 +15,7 @@ * */ -package std +package types import ( "math/big" diff --git a/legend/circuit/bn254/std/withdrawNft.go b/circuit/types/withdraw_nft.go similarity index 98% rename from legend/circuit/bn254/std/withdrawNft.go rename to circuit/types/withdraw_nft.go index 9d2d385b1..d7789e997 100644 --- a/legend/circuit/bn254/std/withdrawNft.go +++ b/circuit/types/withdraw_nft.go @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Zecrey Protocol + * Copyright © 2022 ZkBNB Protocol * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,7 +15,7 @@ * */ -package std +package types import ( "math/big" diff --git a/legend/circuit/bn254/block/utils.go b/circuit/utils.go similarity index 90% rename from legend/circuit/bn254/block/utils.go rename to circuit/utils.go index 56d2e43a3..c3d83c3fd 100644 --- a/legend/circuit/bn254/block/utils.go +++ b/circuit/utils.go @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Zecrey Protocol + * Copyright © 2022 ZkBNB Protocol * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,12 +15,12 @@ * */ -package block +package circuit import ( "github.com/consensys/gnark/std/signature/eddsa" - "github.com/bnb-chain/zkbnb-crypto/legend/circuit/bn254/std" + "github.com/bnb-chain/zkbnb-crypto/circuit/types" ) func SelectAssetDeltas( @@ -76,17 +76,17 @@ func SelectNftDeltas( func SelectPubData( api API, flag Variable, - delta, deltaCheck [std.PubDataSizePerTx]Variable, -) (deltaRes [std.PubDataSizePerTx]Variable) { - for i := 0; i < std.PubDataSizePerTx; i++ { + delta, deltaCheck [types.PubDataSizePerTx]Variable, +) (deltaRes [types.PubDataSizePerTx]Variable) { + for i := 0; i < types.PubDataSizePerTx; i++ { deltaRes[i] = api.Select(flag, delta[i], deltaCheck[i]) } return deltaRes } func EmptySignatureWitness() (sig eddsa.Signature) { - sig.R.X = std.ZeroInt - sig.R.Y = std.ZeroInt - sig.S = std.ZeroInt + sig.R.X = types.ZeroInt + sig.R.Y = types.ZeroInt + sig.S = types.ZeroInt return sig } diff --git a/common/constant.go b/common/constant.go deleted file mode 100644 index c2f6ee8de..000000000 --- a/common/constant.go +++ /dev/null @@ -1,5 +0,0 @@ -package common - -const ( - ChainId = 1 -) diff --git a/ecc/zbls381/bls381.go b/ecc/zbls381/bls381.go deleted file mode 100644 index 6766cdb55..000000000 --- a/ecc/zbls381/bls381.go +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright © 2021 Zecrey Protocol - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package zbls381 - -import ( - "math/big" - - "github.com/consensys/gnark-crypto/ecc/bls12-381" - - "github.com/bnb-chain/zkbnb-crypto/ffmath" -) - -var ( - Order, _ = new(big.Int).SetString("8444461749428370424248824938781546531375899335154063827935233455917409239041", 10) - SEEDH = "ZecreyBLS377SetupH" -) - -type G1Affine = bls12381.G1Affine - -func G1Base() *G1Affine { - _, _, g1Aff, _ := bls12381.Generators() - return &g1Aff -} - -func G1ScalarMul(a *G1Affine, b *big.Int) *G1Affine { - return new(G1Affine).ScalarMultiplication(a, b) -} - -func G1ScalarBaseMul(a *big.Int) *G1Affine { - return new(G1Affine).ScalarMultiplication(G1Base(), a) -} - -func G1Add(a, b *G1Affine) *G1Affine { - aJac := new(bls12381.G1Jac).FromAffine(a) - p := new(G1Affine).FromJacobian(aJac.AddMixed(b)) - return p -} - -func G1Neg(a *G1Affine) *G1Affine { - return new(G1Affine).Neg(a) -} - -func G1InfinityPoint() *G1Affine { - p := &G1Affine{} - p.X.SetZero() - p.Y.SetZero() - return p -} - -func HashToG1(m string) (*G1Affine, error) { - p, err := bls12381.HashToCurveG1Svdw([]byte(m), []byte(m)) - return &p, err -} - -func G1ScalarHBaseMul(a *big.Int) *G1Affine { - _, h := GetG1TwoBaseAffine() - return new(G1Affine).ScalarMultiplication(h, a) -} - -func GetG1TwoBaseAffine() (g *G1Affine, h *G1Affine) { - _, _, G1Affine, _ := bls12381.Generators() - HAffine, _ := HashToG1(SEEDH) - return &G1Affine, HAffine -} - -func RandomValue() *big.Int { - r, _ := ffmath.RandomValue(Order) - return r -} diff --git a/ecc/zbls381/bls381_test.go b/ecc/zbls381/bls381_test.go deleted file mode 100644 index ccb961ce6..000000000 --- a/ecc/zbls381/bls381_test.go +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright © 2021 Zecrey Protocol - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package zbls381 - -import ( - "fmt" - "math/big" - "testing" -) - -func TestG1ScalarMult(t *testing.T) { - a := big.NewInt(2) - b := big.NewInt(3) - c := big.NewInt(8) - A := G1ScalarBaseMul(a) - B := G1ScalarMul(A, b) - C := G1ScalarBaseMul(c) - AB := G1Add(A, B) - fmt.Println(AB.IsOnCurve()) - fmt.Println(AB.Equal(C)) -} - -func TestG1Neg(t *testing.T) { - a := big.NewInt(39) - A := G1ScalarBaseMul(a) - ANeg := G1Neg(A) - C := G1Add(A, ANeg) - fmt.Println(C.IsInfinity()) -} diff --git a/ecc/zbn254/alt_bn128.go b/ecc/zbn254/alt_bn128.go deleted file mode 100644 index a54aeb87a..000000000 --- a/ecc/zbn254/alt_bn128.go +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Copyright © 2021 Zecrey Protocol - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package zbn254 - -import ( - "math/big" - - "github.com/consensys/gnark-crypto/ecc/bn254" - - "github.com/bnb-chain/zkbnb-crypto/ffmath" - "github.com/bnb-chain/zkbnb-crypto/util" -) - -var ( - Order, _ = new(big.Int).SetString("21888242871839275222246405745257275088548364400416034343698204186575808495617", 10) - SeedH = "ZecreyBN128SetupH" -) - -type G1Affine = bn254.G1Affine - -func HashToG1(m string) (*G1Affine, error) { - p, err := bn254.HashToCurveG1Svdw([]byte(m), []byte(m)) - return &p, err -} - -func GetG1InfinityPoint() *G1Affine { - p := new(G1Affine) - p.X.SetZero() - p.Y.SetZero() - return p -} - -func G1Add(a, b *G1Affine) *G1Affine { - aJac := new(bn254.G1Jac).FromAffine(a) - p := new(G1Affine).FromJacobian(aJac.AddMixed(b)) - return p -} - -func G1ScalarMul(a *G1Affine, s *big.Int) *G1Affine { - return new(G1Affine).ScalarMultiplication(a, s) -} - -func G1ScalarHBaseMul(s *big.Int) *G1Affine { - _, HAffine := GetG1TwoBaseAffine() - return new(G1Affine).ScalarMultiplication(HAffine, s) -} - -func G1ScalarBaseMul(s *big.Int) *G1Affine { - base := G1BaseAffine() - return new(G1Affine).ScalarMultiplication(base, s) -} - -func G1BaseAffine() *G1Affine { - _, _, G1Affine, _ := bn254.Generators() - return &G1Affine -} - -func GetG1TwoBaseAffine() (g *G1Affine, h *G1Affine) { - _, _, G1Affine, _ := bn254.Generators() - HAffine, _ := HashToG1(SeedH) - return &G1Affine, HAffine -} - -func G1Neg(s *G1Affine) *G1Affine { - return new(G1Affine).Neg(s) -} - -func ToBytes(a *G1Affine) []byte { - aBytes := a.Bytes() - return aBytes[:] -} - -func VecToBytes(arr []*G1Affine) []byte { - var res []byte - for _, value := range arr { - res = util.ContactBytes(res, ToBytes(value)) - } - return res -} - -func RandomValue() *big.Int { - r, _ := ffmath.RandomValue(Order) - return r -} diff --git a/ecc/zbn254/alt_bn128_test.go b/ecc/zbn254/alt_bn128_test.go deleted file mode 100644 index 93351b235..000000000 --- a/ecc/zbn254/alt_bn128_test.go +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright © 2021 Zecrey Protocol - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package zbn254 - -import ( - "fmt" - "math/big" - "testing" -) - -func TestG1Neg(t *testing.T) { - a := big.NewInt(100) - A := G1ScalarBaseMul(a) - ANeg := G1Neg(A) - C := G1Add(A, ANeg) - fmt.Println(C) -} diff --git a/ecc/zp256/secp256k1.go b/ecc/zp256/secp256k1.go deleted file mode 100644 index 4c64e17f4..000000000 --- a/ecc/zp256/secp256k1.go +++ /dev/null @@ -1,310 +0,0 @@ -/* - * Copyright © 2021 Zecrey Protocol - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package zp256 - -import ( - "encoding/json" - "math/big" - - "github.com/ethereum/go-ethereum/crypto/secp256k1" - - "github.com/bnb-chain/zkbnb-crypto/ffmath" -) - -type MyBitCurve struct { - secp256k1.BitCurve -} - -/* -Elliptic Curve Point struct. -*/ -type P256 struct { - X, Y *big.Int -} - -// Add returns the sum of s(x1,y1) and (x2,y2) -func (BitCurve *MyBitCurve) Add(x1, y1, x2, y2 *big.Int) (*big.Int, *big.Int) { - secp256k1.S256() - z := new(big.Int).SetInt64(1) - return BitCurve.affineFromJacobian(BitCurve.addJacobian(x1, y1, z, x2, y2, z)) -} - -// addJacobian takes two points in Jacobian coordinates, (x1, y1, z1) and -// (x2, y2, z2) and returns their sum, also in Jacobian form. -func (BitCurve *MyBitCurve) addJacobian(x1, y1, z1, x2, y2, z2 *big.Int) (*big.Int, *big.Int, *big.Int) { - z1z1 := new(big.Int).Mul(z1, z1) - z1z1.Mod(z1z1, BitCurve.P) - z2z2 := new(big.Int).Mul(z2, z2) - z2z2.Mod(z2z2, BitCurve.P) - - u1 := new(big.Int).Mul(x1, z2z2) - u1.Mod(u1, BitCurve.P) - u2 := new(big.Int).Mul(x2, z1z1) - u2.Mod(u2, BitCurve.P) - h := new(big.Int).Sub(u2, u1) - if h.Sign() == -1 { - h.Add(h, BitCurve.P) - } - i := new(big.Int).Lsh(h, 1) - i.Mul(i, i) - j := new(big.Int).Mul(h, i) - - s1 := new(big.Int).Mul(y1, z2) - s1.Mul(s1, z2z2) - s1.Mod(s1, BitCurve.P) - s2 := new(big.Int).Mul(y2, z1) - s2.Mul(s2, z1z1) - s2.Mod(s2, BitCurve.P) - r := new(big.Int).Sub(s2, s1) - if r.Sign() == -1 { - r.Add(r, BitCurve.P) - } - r.Lsh(r, 1) - v := new(big.Int).Mul(u1, i) - - x3 := new(big.Int).Set(r) - x3.Mul(x3, x3) - x3.Sub(x3, j) - x3.Sub(x3, v) - x3.Sub(x3, v) - x3.Mod(x3, BitCurve.P) - - y3 := new(big.Int).Set(r) - v.Sub(v, x3) - y3.Mul(y3, v) - s1.Mul(s1, j) - s1.Lsh(s1, 1) - y3.Sub(y3, s1) - y3.Mod(y3, BitCurve.P) - - z3 := new(big.Int).Add(z1, z2) - z3.Mul(z3, z3) - z3.Sub(z3, z1z1) - if z3.Sign() == -1 { - z3.Add(z3, BitCurve.P) - } - z3.Sub(z3, z2z2) - if z3.Sign() == -1 { - z3.Add(z3, BitCurve.P) - } - z3.Mul(z3, h) - z3.Mod(z3, BitCurve.P) - - return x3, y3, z3 -} - -func (BitCurve *MyBitCurve) affineFromJacobian(x, y, z *big.Int) (xOut, yOut *big.Int) { - if z.Sign() == 0 { - return new(big.Int), new(big.Int) - } - zinv := new(big.Int).ModInverse(z, BitCurve.P) - zinvsq := new(big.Int).Mul(zinv, zinv) - - xOut = new(big.Int).Mul(x, zinvsq) - xOut.Mod(xOut, BitCurve.P) - zinvsq.Mul(zinvsq, zinv) - yOut = new(big.Int).Mul(y, zinvsq) - yOut.Mod(yOut, BitCurve.P) - return -} - -var theCurve = new(MyBitCurve) - -func init() { - // http://www.secg.org/sec2-v2.pdf - theCurve.P, _ = new(big.Int).SetString("0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F", 0) - theCurve.N, _ = new(big.Int).SetString("0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141", 0) - theCurve.B, _ = new(big.Int).SetString("0x0000000000000000000000000000000000000000000000000000000000000007", 0) - theCurve.Gx, _ = new(big.Int).SetString("0x79BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798", 0) - theCurve.Gy, _ = new(big.Int).SetString("0x483ADA7726A3C4655DA4FBFC0E1108A8FD17B448A68554199C47D08FFB10D4B8", 0) - theCurve.BitSize = 256 - H, _ = MapToGroup(SeedH) - U, _ = MapToGroup(SeedU) -} - -func S256() *MyBitCurve { - return theCurve -} - -var ( - Curve = S256() - H *P256 - U *P256 -) - -/* -IsZero returns true if and only if the elliptic curve point is the point at infinity. -*/ -func (p *P256) IsZero() bool { - c1 := p.X == nil || p.Y == nil - if !c1 { - z := new(big.Int).SetInt64(0) - return p.X.Cmp(z) == 0 && p.Y.Cmp(z) == 0 - } - return true -} - -/* -Neg returns the inverse of the given elliptic curve point. -*/ -func (p *P256) Neg(a *P256) *P256 { - // (X, Y) -> (X, X + Y) - if a.IsZero() { - return p.SetInfinity() - } - one := new(big.Int).SetInt64(1) - mone := new(big.Int).Sub(Curve.N, one) - p.ScalarMult(a, mone) - return p -} - -/* -Input points must be distinct -*/ -func (p *P256) Add(a, b *P256) *P256 { - if a.IsZero() { - p.X = b.X - p.Y = b.Y - return p - } else if b.IsZero() { - p.X = b.X - p.Y = b.Y - return p - - } - resx, resy := Curve.Add(a.X, a.Y, b.X, b.Y) - p.X = resx - p.Y = resy - return p -} - -/* -Double returns 2*P, where P is the given elliptic curve point. -*/ -func (p *P256) Double(a *P256) *P256 { - if a.IsZero() { - return p.SetInfinity() - } - resx, resy := Curve.Double(a.X, a.Y) - p.X = resx - p.Y = resy - return p -} - -/* -ScalarMul encapsulates the scalar Multiplication Algorithm from secP256k1. -*/ -func (p *P256) ScalarMult(a *P256, n *big.Int) *P256 { - if a.IsZero() { - return p.SetInfinity() - } - cmp := n.Cmp(big.NewInt(0)) - if cmp == 0 { - return p.SetInfinity() - } - n = ffmath.Mod(n, Curve.N) - bns := n.Bytes() - resx, resy := Curve.ScalarMult(a.X, a.Y, bns) - p.X = resx - p.Y = resy - return p -} - -/* -ScalarBaseMul returns the Scalar Multiplication by the base generator. -*/ -func (p *P256) ScalarBaseMult(n *big.Int) *P256 { - cmp := n.Cmp(big.NewInt(0)) - if cmp == 0 { - return p.SetInfinity() - } - n = ffmath.Mod(n, Curve.N) - bns := n.Bytes() - resx, resy := Curve.ScalarBaseMult(bns) - p.X = resx - p.Y = resy - return p -} - -/* -Multiply actually is reponsible for the addition of elliptic curve points. -The name here is to maintain compatibility with zbn254 interface. -This algorithm verifies if the given elliptic curve points are equal, in which case it -returns the result of Double function, otherwise it returns the result of Add function. -*/ -func (p *P256) Multiply(a, b *P256) *P256 { - if a.IsZero() { - p.X = b.X - p.Y = b.Y - return p - } else if b.IsZero() { - p.X = a.X - p.Y = a.Y - return p - } - if a.X.Cmp(b.X) == 0 && a.Y.Cmp(b.Y) == 0 { - resx, resy := Curve.Double(a.X, a.Y) - p.X = resx - p.Y = resy - return p - } - resx, resy := Curve.Add(a.X, a.Y, b.X, b.Y) - p.X = resx - p.Y = resy - return p -} - -/* -SetInfinity sets the given elliptic curve point to the point at infinity. -*/ -func (p *P256) SetInfinity() *P256 { - p.X = nil - p.Y = nil - return p -} - -/* -String returns the readable representation of the given elliptic curve point, i.e. -the tuple formed by X and Y coordinates. -*/ -func (p *P256) String() string { - return "P256(" + p.X.String() + "," + p.Y.String() + ")" -} - -func (p *P256) Bytes() []byte { - pBytes, _ := json.Marshal(p) - return pBytes -} - -/* -IsOnCurve returns TRUE if and only if p has coordinates X and Y that satisfy the -Elliptic Curve equation: y^2 = x^3 + 7. -*/ -func (p *P256) IsOnCurve() bool { - // y² = x³ + 7 - y2 := new(big.Int).Mul(p.Y, p.Y) - y2.Mod(y2, Curve.P) - - x3 := new(big.Int).Mul(p.X, p.X) - x3.Mul(x3, p.X) - - x3.Add(x3, new(big.Int).SetInt64(7)) - x3.Mod(x3, Curve.P) - - return x3.Cmp(y2) == 0 -} diff --git a/ecc/zp256/secp256k1Util.go b/ecc/zp256/secp256k1Util.go deleted file mode 100644 index c4dfe74bd..000000000 --- a/ecc/zp256/secp256k1Util.go +++ /dev/null @@ -1,144 +0,0 @@ -/* - * Copyright © 2021 Zecrey Protocol - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package zp256 - -import ( - "bytes" - "encoding/json" - "errors" - "math/big" - "strconv" - - "github.com/bnb-chain/zkbnb-crypto/ffmath" - "github.com/bnb-chain/zkbnb-crypto/hash/bn254/zmimc" - "github.com/bnb-chain/zkbnb-crypto/util" -) - -const ( - SeedH = "ZecreyP256HSeed" - SeedU = "ZecreyP256USeed" -) - -func Neg(a *P256) *P256 { - return new(P256).Neg(a) -} - -func Add(a, b *P256) *P256 { - return new(P256).Multiply(a, b) -} - -func ScalarBaseMul(a *big.Int) *P256 { - return new(P256).ScalarBaseMult(a) -} - -func ScalarHBaseMul(a *big.Int) *P256 { - return new(P256).ScalarMult(H, a) -} - -func ScalarMul(a *P256, n *big.Int) *P256 { - return new(P256).ScalarMult(a, n) -} - -func Set(a *P256) *P256 { - res := &P256{} - res.X.Set(a.X) - res.Y.Set(a.Y) - return res -} - -func Base() *P256 { - return &P256{X: Curve.Gx, Y: Curve.Gy} -} - -func FromBytes(aBytes []byte) (a *P256, err error) { - a = new(P256) - err = json.Unmarshal(aBytes, &a) - return a, err -} - -func VecToBytes(a []*P256) []byte { - aBytes, _ := json.Marshal(a) - return aBytes -} - -func Equal(a, b *P256) bool { - return a.String() == b.String() -} - -func InfinityPoint() *P256 { - res := &P256{} - res.SetInfinity() - return res -} - -func RandomValue() *big.Int { - r, _ := ffmath.RandomValue(Curve.N) - return r -} - -/* -MapToGroup is a hash function that returns a valid elliptic curve point given as -input a string. It is also known as hash-to-point and is used to obtain a generator -that has no discrete logarithm known relation, thus addressing the concept of -NUMS (nothing up my sleeve). -This implementation is based on the paper: -Short signatures from the Weil pairing -Boneh, Lynn and Shacham -Journal of Cryptology, September 2004, Volume 17, Issue 4, pp 297–319 -*/ -func MapToGroup(m string) (*P256, error) { - var ( - i int - buffer bytes.Buffer - ) - i = 0 - for i < 256 { - buffer.Reset() - buffer.WriteString(strconv.Itoa(i)) - buffer.WriteString(m) - x, _ := util.HashToInt(buffer, zmimc.Hmimc) - x = ffmath.Mod(x, Curve.P) - fx, _ := F(x) - fx = ffmath.Mod(fx, Curve.P) - y := fx.ModSqrt(fx, Curve.P) - if y != nil { - p := &P256{X: x, Y: y} - if p.IsOnCurve() && !p.IsZero() { - return p, nil - } - } - i = i + 1 - } - return nil, errors.New("Failed to Hash-to-point.") -} - -/* -F receives a big integer x as input and return x^3 + 7 mod ORDER. -*/ -func F(x *big.Int) (*big.Int, error) { - // Compute x^2 - x3p7 := ffmath.Multiply(x, x) - x3p7 = ffmath.Mod(x3p7, Curve.P) - // Compute x^3 - x3p7 = ffmath.Multiply(x3p7, x) - x3p7 = ffmath.Mod(x3p7, Curve.P) - // Compute X^3 + 7 - x3p7 = ffmath.Add(x3p7, new(big.Int).SetInt64(7)) - x3p7 = ffmath.Mod(x3p7, Curve.P) - return x3p7, nil -} diff --git a/ecc/zp256/secp256k1Util_test.go b/ecc/zp256/secp256k1Util_test.go deleted file mode 100644 index e0c0a47d2..000000000 --- a/ecc/zp256/secp256k1Util_test.go +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright © 2021 Zecrey Protocol - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package zp256 - -import ( - "fmt" - "math/big" - "testing" -) - -func TestAdd(t *testing.T) { - a := big.NewInt(2) - b := big.NewInt(3) - c := big.NewInt(8) - A := ScalarBaseMul(a) - B := ScalarMul(A, b) - C := ScalarBaseMul(c) - AB := Add(A, B) - fmt.Println(AB.IsOnCurve()) - fmt.Println(Equal(AB, C)) - fmt.Println(ScalarBaseMul(big.NewInt(0)).IsZero()) -} - -func TestNeg(t *testing.T) { - a := big.NewInt(100) - A := ScalarBaseMul(a) - ANeg := Neg(A) - fmt.Println(A) - fmt.Println(ANeg) - C := Add(A, ANeg) - fmt.Println(C) - fmt.Println(C.IsZero()) -} diff --git a/ecc/ztwistededwards/tebn254/constants.go b/ecc/ztwistededwards/tebn254/constants.go index 34adcc48c..5900eb923 100644 --- a/ecc/ztwistededwards/tebn254/constants.go +++ b/ecc/ztwistededwards/tebn254/constants.go @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Zecrey Protocol + * Copyright © 2022 ZkBNB Protocol * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/ecc/ztwistededwards/tebn254/eddsa.go b/ecc/ztwistededwards/tebn254/eddsa.go index e4243f54c..a371473db 100644 --- a/ecc/ztwistededwards/tebn254/eddsa.go +++ b/ecc/ztwistededwards/tebn254/eddsa.go @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Zecrey Protocol + * Copyright © 2022 ZkBNB Protocol * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/ecc/ztwistededwards/tebn254/eddsa_test.go b/ecc/ztwistededwards/tebn254/eddsa_test.go index b866c8a72..87156e136 100644 --- a/ecc/ztwistededwards/tebn254/eddsa_test.go +++ b/ecc/ztwistededwards/tebn254/eddsa_test.go @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Zecrey Protocol + * Copyright © 2022 ZkBNB Protocol * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/ecc/ztwistededwards/tebn254/errors.go b/ecc/ztwistededwards/tebn254/errors.go index 49aad5048..72086dde4 100644 --- a/ecc/ztwistededwards/tebn254/errors.go +++ b/ecc/ztwistededwards/tebn254/errors.go @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Zecrey Protocol + * Copyright © 2022 ZkBNB Protocol * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/ecc/ztwistededwards/tebn254/tebn254.go b/ecc/ztwistededwards/tebn254/tebn254.go index 266610d49..017c44c0e 100644 --- a/ecc/ztwistededwards/tebn254/tebn254.go +++ b/ecc/ztwistededwards/tebn254/tebn254.go @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Zecrey Protocol + * Copyright © 2022 ZkBNB Protocol * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,10 +26,10 @@ import ( "strconv" "github.com/consensys/gnark-crypto/ecc/bn254/fr" + "github.com/consensys/gnark-crypto/ecc/bn254/fr/mimc" "github.com/consensys/gnark-crypto/ecc/bn254/twistededwards" "github.com/bnb-chain/zkbnb-crypto/ffmath" - "github.com/bnb-chain/zkbnb-crypto/hash/bn254/zmimc" "github.com/bnb-chain/zkbnb-crypto/util" ) @@ -44,8 +44,8 @@ var ( ) const ( - SeedH = "ZecreyTwistedEdwardsBn254HSeed" - SeedU = "ZecreyTwistedEdwardsBn254USeed" + SeedH = "ZkBNBTwistedEdwardsBn254HSeed" + SeedU = "ZkBNBTwistedEdwardsBn254USeed" PointSize = 32 ) @@ -109,11 +109,12 @@ func MapToGroup(seed string) (H *Point, err error) { buffer bytes.Buffer ) i = 0 + hmimc := mimc.NewMiMC() for i < 256 { buffer.Reset() buffer.WriteString(seed) buffer.WriteString(strconv.Itoa(i)) - y, err := util.HashToInt(buffer, zmimc.Hmimc) + y, err := util.HashToInt(buffer, hmimc) if err != nil { return nil, err } diff --git a/ecc/ztwistededwards/tebn254/tebn254_test.go b/ecc/ztwistededwards/tebn254/tebn254_test.go index f7ccc223b..b11fdf326 100644 --- a/ecc/ztwistededwards/tebn254/tebn254_test.go +++ b/ecc/ztwistededwards/tebn254/tebn254_test.go @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Zecrey Protocol + * Copyright © 2022 ZkBNB Protocol * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -59,7 +59,7 @@ func TestNeg(t *testing.T) { } func TestMapToGroup(t *testing.T) { - HTest, err := MapToGroup("zecreyHSeed") + HTest, err := MapToGroup("zkbnbHSeed") if err != nil { t.Error(err) } diff --git a/ffmath/ffmath.go b/ffmath/ffmath.go index d001b16ce..5391d000e 100644 --- a/ffmath/ffmath.go +++ b/ffmath/ffmath.go @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Zecrey Protocol + * Copyright © 2022 ZkBNB Protocol * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/ffmath/ffmath_test.go b/ffmath/ffmath_test.go deleted file mode 100644 index 7fd9d610f..000000000 --- a/ffmath/ffmath_test.go +++ /dev/null @@ -1 +0,0 @@ -package ffmath diff --git a/ffmath/float.go b/ffmath/float.go index a795ad8fb..da8a1af8f 100644 --- a/ffmath/float.go +++ b/ffmath/float.go @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Zecrey Protocol + * Copyright © 2022 ZkBNB Protocol * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/go.mod b/go.mod index 3de4e5589..9097c8fee 100644 --- a/go.mod +++ b/go.mod @@ -6,46 +6,20 @@ require ( github.com/consensys/gnark v0.7.0 github.com/consensys/gnark-crypto v0.7.0 github.com/ethereum/go-ethereum v1.10.17 - github.com/magiconair/properties v1.8.5 github.com/stretchr/testify v1.7.1 golang.org/x/crypto v0.0.0-20220321153916-2c7772ba3064 - gotest.tools v2.2.0+incompatible ) require ( - github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6 // indirect - github.com/VictoriaMetrics/fastcache v1.6.0 // indirect github.com/btcsuite/btcd/btcec/v2 v2.1.2 // indirect - github.com/cespare/xxhash/v2 v2.1.1 // indirect github.com/davecgh/go-spew v1.1.1 // indirect - github.com/deckarep/golang-set v1.8.0 // indirect github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1 // indirect - github.com/edsrzf/mmap-go v1.0.0 // indirect github.com/fxamacker/cbor/v2 v2.2.0 // indirect - github.com/go-ole/go-ole v1.2.1 // indirect - github.com/go-stack/stack v1.8.0 // indirect - github.com/golang/snappy v0.0.4 // indirect - github.com/google/go-cmp v0.5.6 // indirect - github.com/google/uuid v1.2.0 // indirect - github.com/gorilla/websocket v1.4.2 // indirect - github.com/hashicorp/golang-lru v0.5.5-0.20210104140557-80c98217689d // indirect - github.com/holiman/bloomfilter/v2 v2.0.3 // indirect - github.com/holiman/uint256 v1.2.0 // indirect - github.com/mattn/go-runewidth v0.0.9 // indirect github.com/mmcloughlin/addchain v0.4.0 // indirect - github.com/olekukonko/tablewriter v0.0.5 // indirect - github.com/pkg/errors v0.9.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - github.com/prometheus/tsdb v0.7.1 // indirect - github.com/rjeczalik/notify v0.9.1 // indirect github.com/rogpeppe/go-internal v1.8.1 // indirect github.com/rs/zerolog v1.26.1 // indirect - github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible // indirect - github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 // indirect - github.com/tklauser/go-sysconf v0.3.5 // indirect - github.com/tklauser/numcpus v0.2.2 // indirect github.com/x448/float16 v0.8.4 // indirect golang.org/x/sys v0.0.0-20220319134239-a9b59b0215f8 // indirect - gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce // indirect gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect ) diff --git a/go.sum b/go.sum index a021e49ad..71df3f1f0 100644 --- a/go.sum +++ b/go.sum @@ -25,14 +25,11 @@ github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03 github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= github.com/DATA-DOG/go-sqlmock v1.3.3/go.mod h1:f/Ixk793poVmq4qj/V1dPUg2JEAKC73Q5eFN3EC/SaM= github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= -github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6 h1:fLjPD/aNc3UIOA6tDi6QXUemppXK3P9BI7mr2hd6gx8= github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6/go.mod h1:3eOhrUMpNV+6aFIbp5/iudMxNCF27Vw2OZgy4xEx0Fg= -github.com/VictoriaMetrics/fastcache v1.6.0 h1:C/3Oi3EiBCqufydp1neRZkqcwmEiuRT9c3fqvvgKm5o= github.com/VictoriaMetrics/fastcache v1.6.0/go.mod h1:0qHz5QP0GMX4pfmMA/zt5RgfNuXJrTP0zS7DqpHGGTw= github.com/ajstarks/svgo v0.0.0-20180226025133-644b8db467af/go.mod h1:K08gAheRH3/J6wwsYMMT4xOr94bZjxIelGM0+d/wbFw= github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= -github.com/allegro/bigcache v1.2.1-0.20190218064605-e24eb225f156 h1:eMwmnE/GDgah4HI848JfFxHt+iPb26b4zyfspmqY0/8= github.com/allegro/bigcache v1.2.1-0.20190218064605-e24eb225f156/go.mod h1:Cb/ax3seSYIx7SuZdm2G2xzfwmv3TPSk2ucNfQESPXM= github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883/go.mod h1:rCTlJbsFo29Kk6CurOXKm700vrz8f0KW0JNfpkRJY/8= github.com/apache/arrow/go/arrow v0.0.0-20191024131854-af6fa24be0db/go.mod h1:VTxUBvSJ3s3eHAg65PNgrsn5BtqCRPdmyXh6rAfdxN0= @@ -55,11 +52,8 @@ github.com/btcsuite/btcd/chaincfg/chainhash v1.0.0 h1:MSskdM4/xJYcFzy0altH/C/xHo github.com/btcsuite/btcd/chaincfg/chainhash v1.0.0/go.mod h1:7SFka0XMvUgj3hfZtydOrQY2mwhPclbT2snogU7SQQc= github.com/c-bata/go-prompt v0.2.2/go.mod h1:VzqtzE2ksDBcdln8G7mk2RX9QyGjH+OVqOCSiVIqS34= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= -github.com/cespare/cp v0.1.0 h1:SE+dxFebS7Iik5LK0tsi1k9ZCxEaFX4AjQmoyA+1dJk= github.com/cespare/cp v0.1.0/go.mod h1:SOGHArjBr4JWaSDEVpWpo/hNg6RoKrls6Oh40hiwW+s= -github.com/cespare/xxhash v1.1.0 h1:a6HrQnmkObjyL+Gs60czilIUGqrzKutQD6XZog3p+ko= github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= -github.com/cespare/xxhash/v2 v2.1.1 h1:6MnRN8NT7+YBpUIWxHtefFZOKTAPgGjpQSxqLNn0+qY= github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI= @@ -81,7 +75,6 @@ github.com/dave/jennifer v1.2.0/go.mod h1:fIb+770HOpJ2fmN9EPPKOqm1vMGhB+TwXKMZhr github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/deckarep/golang-set v1.8.0 h1:sk9/l/KqpunDwP7pSjUg0keiOOLEnOBHzykLrsPppp4= github.com/deckarep/golang-set v1.8.0/go.mod h1:5nI87KwE7wgsBU1F4GKAw2Qod7p5kyS383rP6+o6qqo= github.com/decred/dcrd/crypto/blake256 v1.0.0 h1:/8DMNYp9SGi5f0w7uCm6d6M4OU2rGFK09Y2A4Xv7EE0= github.com/decred/dcrd/crypto/blake256 v1.0.0/go.mod h1:sQl2p6Y26YV+ZOcSTP6thNdn47hh8kt6rqSlvmrXFAc= @@ -99,18 +92,15 @@ github.com/docker/docker v1.4.2-0.20180625184442-8e610b2b55bf/go.mod h1:eEKB0N0r github.com/dop251/goja v0.0.0-20211011172007-d99e4b8cbf48/go.mod h1:R9ET47fwRVRPZnOGvHxxhuZcbrMCuiqOz3Rlrh4KSnk= github.com/dop251/goja_nodejs v0.0.0-20210225215109-d91c329300e7/go.mod h1:hn7BA7c8pLvoGndExHudxTDKZ84Pyvv+90pbBjbTz0Y= github.com/eclipse/paho.mqtt.golang v1.2.0/go.mod h1:H9keYFcgq3Qr5OUJm/JZI/i6U7joQ8SYLhZwfeOo6Ts= -github.com/edsrzf/mmap-go v1.0.0 h1:CEBF7HpRnUCSJgGUb5h1Gm7e3VkmVDrR8lvWVLtrOFw= github.com/edsrzf/mmap-go v1.0.0/go.mod h1:YO35OhQPt3KJa3ryjFM5Bs14WD66h8eGKpfaBNrHW5M= github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= github.com/ethereum/go-ethereum v1.10.17 h1:XEcumY+qSr1cZQaWsQs5Kck3FHB0V2RiMHPdTBJ+oT8= github.com/ethereum/go-ethereum v1.10.17/go.mod h1:Lt5WzjM07XlXc95YzrhosmR4J9Ahd6X2wyEV2SvGhk0= github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= -github.com/fjl/memsize v0.0.0-20190710130421-bcb5799ab5e5 h1:FtmdgXiUlNeRsoNMFlKLDt+S+6hbjVMEW6RGQ7aUf7c= github.com/fjl/memsize v0.0.0-20190710130421-bcb5799ab5e5/go.mod h1:VvhXpOYNQvB+uIk2RvXzuaQtkQJzzIx6lSBe1xv7hi0= github.com/fogleman/gg v1.2.1-0.20190220221249-0403632d5b90/go.mod h1:R/bRT+9gY/C5z7JzPU0zXsXHKM4/ayA+zqcVNZzPa1k= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= -github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4= github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= github.com/fxamacker/cbor/v2 v2.2.0 h1:6eXqdDDe588rSYAi1HfZKbx6YYQO4mxQ9eC6xYpU/JQ= github.com/fxamacker/cbor/v2 v2.2.0/go.mod h1:TA1xS00nchWmaBnEIxPSE5oHLuJBAVvqrtAnWBwBCVo= @@ -123,24 +113,19 @@ github.com/glycerine/goconvey v0.0.0-20190410193231-58a59202ab31/go.mod h1:Ogl1T github.com/go-chi/chi/v5 v5.0.0/go.mod h1:BBug9lr0cqtdAhsu6R4AAdvufI0/XBzAQSsUqJpoZOs= github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= -github.com/go-kit/kit v0.8.0 h1:Wz+5lgoB0kkuqLEc6NVmwRknTKP6dTGbSqvhZtBI/j0= github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= -github.com/go-logfmt/logfmt v0.4.0 h1:MP4Eh7ZCb31lleYCFuwm0oe4/YGak+5l1vA2NOE80nA= github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= -github.com/go-ole/go-ole v1.2.1 h1:2lOsA72HgjxAuMlKpFiCbHTvu44PIVkZ5hqm3RSdI/E= github.com/go-ole/go-ole v1.2.1/go.mod h1:7FAglXiTm7HKlQRDeOQ6ZNUHidzCWXuZWq/1dTyBNF8= github.com/go-openapi/jsonpointer v0.19.5/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg= github.com/go-openapi/swag v0.19.5/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk= github.com/go-sourcemap/sourcemap v2.1.3+incompatible/go.mod h1:F8jJfvm2KbVjc5NqelyYJmf/v5J0dwNLS2mL4sNA1Jg= github.com/go-sql-driver/mysql v1.4.1/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w= -github.com/go-stack/stack v1.8.0 h1:5SgMzNM5HxrEjV0ww2lTmX6E2Izsfxas4+YHWRs3Lsk= github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= github.com/gofrs/uuid v3.3.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM= github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= github.com/gogo/protobuf v1.3.1/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o= -github.com/golang-jwt/jwt/v4 v4.3.0 h1:kHL1vqdqWNfATmA0FNMdmZNMyZI1U6O31X4rlIPoBog= github.com/golang-jwt/jwt/v4 v4.3.0/go.mod h1:/xlHOz8bRuivTWchD4jCa+NbatV+wEUSzwAxVc6locg= github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k= github.com/golang/geo v0.0.0-20190916061304-5b978397cfec/go.mod h1:QZ0nwyI2jOfgRAoBvP+ab5aRr7c9x7lhGEJrKvBwjWI= @@ -162,7 +147,6 @@ github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/golang/snappy v0.0.3/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= -github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM= github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/golangci/lint-1 v0.0.0-20181222135242-d2cdd8c08219/go.mod h1:/X8TswGSh1pIozq4ZwCfxS0WA5JGXguxk94ar/4c87Y= github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= @@ -174,8 +158,6 @@ github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMyw github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.4.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ= -github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/gofuzz v1.1.1-0.20200604201612-c04b05f3adfa/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs= github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= @@ -183,27 +165,20 @@ github.com/google/pprof v0.0.0-20190515194954-54271f7e092f/go.mod h1:zfwlbNMJ+OI github.com/google/pprof v0.0.0-20191218002539-d4f498aebedc/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= github.com/google/subcommands v1.2.0/go.mod h1:ZjhPrFU+Olkh9WazFPsl27BQ4UPiG37m3yTrtFlrHVk= -github.com/google/uuid v1.2.0 h1:qJYtXnJRWmpe7m/3XlyhrsLrEURqHRM2kxzoxXqyUDs= github.com/google/uuid v1.2.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg= github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk= github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So= -github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc= github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/graph-gophers/graphql-go v1.3.0/go.mod h1:9CQHMSxwO4MprSdzoIEobiHpoLtHm77vfxsvsIN5Vuc= -github.com/hashicorp/go-bexpr v0.1.10 h1:9kuI5PFotCboP3dkDYFr/wi0gg0QVbSNz5oFRpxn4uE= github.com/hashicorp/go-bexpr v0.1.10/go.mod h1:oxlubA2vC/gFVfX1A6JGp7ls7uCDlfJn732ehYYg+g0= github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= -github.com/hashicorp/golang-lru v0.5.5-0.20210104140557-80c98217689d h1:dg1dEPuWpEqDnvIw251EVy4zlP8gWbsGj4BsUKCRpYs= github.com/hashicorp/golang-lru v0.5.5-0.20210104140557-80c98217689d/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4= -github.com/holiman/bloomfilter/v2 v2.0.3 h1:73e0e/V0tCydx14a0SCYS/EWCxgwLZ18CZcZKVu0fao= github.com/holiman/bloomfilter/v2 v2.0.3/go.mod h1:zpoh+gs7qcpqrHr3dB55AMiJwo0iURXE7ZOP9L9hSkA= -github.com/holiman/uint256 v1.2.0 h1:gpSYcPLWGv4sG43I2mVLiDZCNDh/EpGjSk8tmtxitHM= github.com/holiman/uint256 v1.2.0/go.mod h1:y4ga/t+u+Xwd7CpDgZESaRcWy0I7XMlTMA25ApIH5Jw= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= -github.com/huin/goupnp v1.0.3-0.20220313090229-ca81a64b4204 h1:+EYBkW+dbi3F/atB+LSQZSWh7+HNrV3A/N0y6DSoy9k= github.com/huin/goupnp v1.0.3-0.20220313090229-ca81a64b4204/go.mod h1:ZxNlw5WqJj6wSsRK5+YfflQGXYfccj5VgQsMNixHM7Y= github.com/huin/goutil v0.0.0-20170803182201-1ca381bf3150/go.mod h1:PpLOETDnJ0o3iZrZfqZzyLl6l7F3c6L1oWn7OICBi6o= github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= @@ -219,7 +194,6 @@ github.com/influxdata/promql/v2 v2.12.0/go.mod h1:fxOPu+DY0bqCTCECchSRtWfc+0X19y github.com/influxdata/roaring v0.4.13-0.20180809181101-fc520f41fab6/go.mod h1:bSgUQ7q5ZLSO+bKBGqJiCBGAl+9DxyW63zLTujjUlOE= github.com/influxdata/tdigest v0.0.0-20181121200506-bf2b5ad3c0a9/go.mod h1:Js0mqiSBE6Ffsg94weZZ2c+v/ciT8QRHFOap7EKDrR0= github.com/influxdata/usage-client v0.0.0-20160829180054-6d3895376368/go.mod h1:Wbbw6tYNvwa5dlB6304Sd+82Z3f7PmVZHVKU637d4po= -github.com/jackpal/go-nat-pmp v1.0.2 h1:KzKSgb7qkJvOUTqYl9/Hg/me3pWgBmERKrTGD7BdWus= github.com/jackpal/go-nat-pmp v1.0.2/go.mod h1:QPH045xvCAeXUZOxsnwmrtiCoxIr9eob+4orBN1SBKc= github.com/jedisct1/go-minisign v0.0.0-20190909160543-45766022959e/go.mod h1:G1CVv03EnqU1wYL2dFwXxW2An0az9JTl/ZsqXQeBlkU= github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo= @@ -240,7 +214,6 @@ github.com/klauspost/cpuid v0.0.0-20170728055534-ae7887de9fa5/go.mod h1:Pj4uuM52 github.com/klauspost/crc32 v0.0.0-20161016154125-cb6bfca970f6/go.mod h1:+ZoRqAPRLkC4NPOvfYeR5KNOrY6TD+/sAC3HXPZgDYg= github.com/klauspost/pgzip v1.0.2-0.20170402124221-0bf5dcad4ada/go.mod h1:Ch1tH69qFZu15pkjo5kYi6mth2Zzwzt50oCQKQE9RUs= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= -github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515 h1:T+h1c/A9Gawja4Y9mFVWj2vyii2bbUNDw3kt9VxK2EY= github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= @@ -256,30 +229,23 @@ github.com/labstack/gommon v0.3.0/go.mod h1:MULnywXg0yavhxWKc+lOruYdAhDwPK9wf0OL github.com/leanovate/gopter v0.2.9 h1:fQjYxZaynp97ozCzfOyOuAGOU4aU/z37zf/tOujFk7c= github.com/leanovate/gopter v0.2.9/go.mod h1:U2L/78B+KVFIx2VmW6onHJQzXtFb+p5y3y2Sh+Jxxv8= github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= -github.com/magiconair/properties v1.8.5 h1:b6kJs+EmPFMYGkow9GiUyCyOvIwYetYJ3fSaWak/Gls= -github.com/magiconair/properties v1.8.5/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPKd5NZ3oSwXrF60= github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= github.com/matryer/moq v0.0.0-20190312154309-6cfb0558e1bd/go.mod h1:9ELz6aaclSIGnZBoaSLZ3NAl1VTufbOrXBPvtcy6WiQ= github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= github.com/mattn/go-colorable v0.1.7/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= -github.com/mattn/go-colorable v0.1.8 h1:c1ghPdyEDarC70ftn0y+A/Ee++9zz8ljHG1b13eJ0s8= github.com/mattn/go-colorable v0.1.8/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= github.com/mattn/go-isatty v0.0.9/go.mod h1:YNRxwqDuOph6SZLI9vUUz6OYw3QyUt7WiY2yME+cCiQ= -github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY= github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= github.com/mattn/go-runewidth v0.0.3/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= -github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0= github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= github.com/mattn/go-sqlite3 v1.11.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc= github.com/mattn/go-tty v0.0.0-20180907095812-13ff1204f104/go.mod h1:XPvLUNfbS4fJH25nqRHfWLMa1ONC8Amw+mIA639KxkE= github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= -github.com/mitchellh/mapstructure v1.4.1 h1:CpVNEelQCZBooIPDn+AR3NpivK/TIKU8bDxdASFVQag= github.com/mitchellh/mapstructure v1.4.1/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= -github.com/mitchellh/pointerstructure v1.2.0 h1:O+i9nHnXS3l/9Wu7r4NrEdwA2VFTicjUEN1uBnDo34A= github.com/mitchellh/pointerstructure v1.2.0/go.mod h1:BRAsLI5zgXmw97Lf6s25bs8ohIXc3tViBH44KcwB2g4= github.com/mmcloughlin/addchain v0.4.0 h1:SobOdjm2xLj1KkXN5/n0xTIWyZA2+s99UCY1iPfkHRY= github.com/mmcloughlin/addchain v0.4.0/go.mod h1:A86O+tHqZLMNO4w6ZZ4FlVQEadcoqkyU72HC5wJ4RlU= @@ -291,17 +257,13 @@ github.com/mschoch/smat v0.0.0-20160514031455-90eadee771ae/go.mod h1:qAyveg+e4CE github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= github.com/naoina/go-stringutil v0.1.0/go.mod h1:XJ2SJL9jCtBh+P9q5btrd/Ylo8XwT/h1USek5+NqSA0= github.com/naoina/toml v0.1.2-0.20170918210437-9fafd6967416/go.mod h1:NBIhNtsFMo3G2szEBne+bO4gS192HuIYRqfvOWb4i1E= -github.com/nxadm/tail v1.4.4 h1:DQuhQpB1tVlglWS2hLQ5OV6B5r8aGxSrPc5Qo6uTN78= github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A= github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U= -github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec= github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY= github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk= -github.com/onsi/ginkgo v1.14.0 h1:2mOpI4JVVPBN+WQRa0WKH2eXR+Ey+uK4n7Zj0aYpIQA= github.com/onsi/ginkgo v1.14.0/go.mod h1:iSB4RoI2tjJc9BBv4NKIKWKya62Rps+oPG/Lv9klQyY= github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY= -github.com/onsi/gomega v1.10.1 h1:o0+MgICZLuZ7xjH7Vx6zS/zcu93/BEp1VwkIW1mEXCE= github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo= github.com/opentracing/opentracing-go v1.0.2/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o= github.com/opentracing/opentracing-go v1.0.3-0.20180606204148-bd9c31933947/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o= @@ -314,7 +276,6 @@ github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= -github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/term v0.0.0-20180730021639-bffc007b7fd5/go.mod h1:eCbImbZ95eXtAUIbLAuAVnBnwf83mjf6QIVH8SHYwqQ= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= @@ -329,16 +290,13 @@ github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y8 github.com/prometheus/common v0.6.0/go.mod h1:eBmuwkDJBwy6iBfxCBob6t6dR6ENT/y+J+Zk0j9GMYc= github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= -github.com/prometheus/tsdb v0.7.1 h1:YZcsG11NqnK4czYLrWd9mpEuAJIHVQLwdrleYfszMAA= github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU= github.com/retailnext/hllpp v1.0.1-0.20180308014038-101a6d2f8b52/go.mod h1:RDpi1RftBQPUCDRw6SmxeaREsAaRKnOclghuzp/WRzc= -github.com/rjeczalik/notify v0.9.1 h1:CLCKso/QK1snAlnhNR/CNvNiFU2saUtjV0bx3EwNeCE= github.com/rjeczalik/notify v0.9.1/go.mod h1:rKwnCoCGeuQnwBtTSPL9Dad03Vh2n40ePRrjvIXnJho= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc= github.com/rogpeppe/go-internal v1.8.1 h1:geMPLpDpQOgVyCg5z5GoRwLHepNdb71NXb67XFkP+Eg= github.com/rogpeppe/go-internal v1.8.1/go.mod h1:JeRgkft04UBgHMgCIwADu4Pn6Mtm5d4nPKWu0nJ5d+o= -github.com/rs/cors v1.7.0 h1:+88SsELBHx5r+hZ8TCkggzSstaWNbDvThkVK8H6f9ik= github.com/rs/cors v1.7.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU= github.com/rs/xid v1.3.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg= github.com/rs/zerolog v1.26.1 h1:/ihwxqH+4z8UxyI70wM1z9yCvkWcfz/a3mj48k/Zngc= @@ -347,7 +305,6 @@ github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQD github.com/segmentio/kafka-go v0.1.0/go.mod h1:X6itGqS9L4jDletMsxZ7Dz+JFWxM6JHfPOCvTvk+EJo= github.com/segmentio/kafka-go v0.2.0/go.mod h1:X6itGqS9L4jDletMsxZ7Dz+JFWxM6JHfPOCvTvk+EJo= github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo= -github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible h1:Bn1aCHHRnjv4Bl16T8rcaFjYSrGrIZvpiGO6P3Q4GpU= github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA= github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= @@ -368,12 +325,9 @@ github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5 github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMTY= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 h1:epCh84lMvA70Z7CTTCmYQn2CKbY8j86K7/FAIr141uY= github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7/go.mod h1:q4W45IWZaF22tdD+VEXcAWRA037jwmWEB5VWYORlTpc= github.com/tinylib/msgp v1.0.2/go.mod h1:+d+yLhGm8mzTaHzB+wgMYrodPfmZrzkirds8fDWklFE= -github.com/tklauser/go-sysconf v0.3.5 h1:uu3Xl4nkLzQfXNsWn15rPc/HQCJKObbt1dKJeWp3vU4= github.com/tklauser/go-sysconf v0.3.5/go.mod h1:MkWzOF4RMCshBAMXuhXJs64Rte09mITnppBXY/rYEFI= -github.com/tklauser/numcpus v0.2.2 h1:oyhllyrScuYI6g+h/zUvNXNp1wy7x8qQy3t/piefldA= github.com/tklauser/numcpus v0.2.2/go.mod h1:x3qojaO3uyYt0i56EW/VUYs7uBvdl2fkfZFu0T9wgjM= github.com/tyler-smith/go-bip39 v1.0.1-0.20181017060643-dbb3b84ba2ef/go.mod h1:sJ5fKU0s6JVwZjjcUEX2zFOnvq0ASQ2K9Zr6cf67kNs= github.com/urfave/cli/v2 v2.3.0/go.mod h1:LJmUH05zAU44vOAcrfzZQKsZbVcdbOG8rtL3/XcUArI= @@ -458,7 +412,6 @@ golang.org/x/net v0.0.0-20210220033124-5f55cee0dc0d/go.mod h1:m0MpNAwzfU5UDzcl9v golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20210610132358-84b48f89b13b/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= -golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2 h1:CIJ76btIcR3eFI5EgSo6k1qKw9KJexJuRLI9G7Hp5wE= golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -472,7 +425,6 @@ golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20210220032951-036812b2e83c h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -524,7 +476,6 @@ golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= @@ -561,7 +512,6 @@ golang.org/x/tools v0.1.7/go.mod h1:LGqMHiF4EqQNHR1JncWGqT5BVaXmza+X+BDGol+dOxo= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gonum.org/v1/gonum v0.0.0-20180816165407-929014505bf4/go.mod h1:Y+Yx5eoAFn32cQvJDxZx5Dpnq+c3wtXuadVZAcxbbBo= gonum.org/v1/gonum v0.0.0-20181121035319-3f7ecaa7e8ca/go.mod h1:Y+Yx5eoAFn32cQvJDxZx5Dpnq+c3wtXuadVZAcxbbBo= @@ -613,12 +563,9 @@ gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntN gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= -gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce h1:+JknDZhAj8YMt7GC73Ei8pv4MzjDUNPHgQWJdtMAaDU= gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce/go.mod h1:5AcXVHNjg+BDxry382+8OKon8SEWiKktQR07RKPsv1c= gopkg.in/olebedev/go-duktape.v3 v3.0.0-20200619000410-60c24ae608a6/go.mod h1:uAJfkITjFhyEEuUfm7bsmCZRbW5WRq8s9EY8HZ6hCns= -gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= -gopkg.in/urfave/cli.v1 v1.20.0 h1:NdAVW6RYxDif9DhDHaAortIu956m2c0v+09AZBPTbE0= gopkg.in/urfave/cli.v1 v1.20.0/go.mod h1:vuBzUtMdQeixQj8LVd+/98pzhxNGQoyuPBlsXHOQNO0= gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= @@ -626,12 +573,10 @@ gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo= gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -gotest.tools v2.2.0+incompatible h1:VsBPFP1AI068pPrMxtb/S8Zkgf9xEmTLJjfM+P5UIEo= gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= diff --git a/hash/bn254/zmimc/mimc.go b/hash/bn254/zmimc/mimc.go deleted file mode 100644 index 4812aa2a7..000000000 --- a/hash/bn254/zmimc/mimc.go +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright © 2021 Zecrey Protocol - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package zmimc - -import ( - "github.com/consensys/gnark-crypto/ecc/bn254/fr/mimc" -) - -var ( - Hmimc = mimc.NewMiMC() -) diff --git a/legend/circuit/bn254/block/constants.go b/legend/circuit/bn254/block/constants.go deleted file mode 100644 index 0d2491101..000000000 --- a/legend/circuit/bn254/block/constants.go +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright © 2021 Zecrey Protocol - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package block - -import ( - "github.com/consensys/gnark-crypto/ecc/bn254/twistededwards/eddsa" - "github.com/consensys/gnark/frontend" - "github.com/consensys/gnark/std/hash/mimc" - eddsaConstraints "github.com/consensys/gnark/std/signature/eddsa" - - "github.com/bnb-chain/zkbnb-crypto/legend/circuit/bn254/std" -) - -type ( - Variable = frontend.Variable - - Signature = eddsa.Signature - SignatureConstraints = eddsaConstraints.Signature - API = frontend.API - MiMC = mimc.MiMC - - RegisterZnsTx = std.RegisterZnsTx - CreatePairTx = std.CreatePairTx - UpdatePairRateTx = std.UpdatePairRateTx - DepositTx = std.DepositTx - DepositNftTx = std.DepositNftTx - TransferTx = std.TransferTx - SwapTx = std.SwapTx - AddLiquidityTx = std.AddLiquidityTx - RemoveLiquidityTx = std.RemoveLiquidityTx - CreateCollectionTx = std.CreateCollectionTx - MintNftTx = std.MintNftTx - TransferNftTx = std.TransferNftTx - AtomicMatchTx = std.AtomicMatchTx - CancelOfferTx = std.CancelOfferTx - WithdrawTx = std.WithdrawTx - WithdrawNftTx = std.WithdrawNftTx - FullExitTx = std.FullExitTx - FullExitNftTx = std.FullExitNftTx - - RegisterZnsTxConstraints = std.RegisterZnsTxConstraints - CreatePairTxConstraints = std.CreatePairTxConstraints - UpdatePairRateTxConstraints = std.UpdatePairRateTxConstraints - DepositTxConstraints = std.DepositTxConstraints - DepositNftTxConstraints = std.DepositNftTxConstraints - TransferTxConstraints = std.TransferTxConstraints - SwapTxConstraints = std.SwapTxConstraints - AddLiquidityTxConstraints = std.AddLiquidityTxConstraints - RemoveLiquidityTxConstraints = std.RemoveLiquidityTxConstraints - CreateCollectionTxConstraints = std.CreateCollectionTxConstraints - MintNftTxConstraints = std.MintNftTxConstraints - TransferNftTxConstraints = std.TransferNftTxConstraints - AtomicMatchTxConstraints = std.AtomicMatchTxConstraints - CancelOfferTxConstraints = std.CancelOfferTxConstraints - WithdrawTxConstraints = std.WithdrawTxConstraints - WithdrawNftTxConstraints = std.WithdrawNftTxConstraints - FullExitTxConstraints = std.FullExitTxConstraints - FullExitNftTxConstraints = std.FullExitNftTxConstraints - - LiquidityConstraints = std.LiquidityConstraints - NftConstraints = std.NftConstraints -) - -const ( - NbAccountAssetsPerAccount = std.NbAccountAssetsPerAccount - NbAccountsPerTx = std.NbAccountsPerTx - AssetMerkleLevels = 16 - LiquidityMerkleLevels = 16 - NftMerkleLevels = 40 - AccountMerkleLevels = 32 - RateBase = std.RateBase - OfferSizePerAsset = 128 - - LastAccountIndex = 4294967295 - LastAccountAssetId = 65535 -) diff --git a/legend/circuit/bn254/std/hint.go b/legend/circuit/bn254/std/hint.go deleted file mode 100644 index dda7cd9a4..000000000 --- a/legend/circuit/bn254/std/hint.go +++ /dev/null @@ -1,72 +0,0 @@ -package std - -import ( - "bytes" - "errors" - "log" - "math/big" - - "github.com/consensys/gnark-crypto/ecc" - "github.com/ethereum/go-ethereum/crypto" - - "github.com/bnb-chain/zkbnb-crypto/ffmath" -) - -func Keccak256(curveID ecc.ID, inputs []*big.Int, outputs []*big.Int) error { - var buf bytes.Buffer - for i := 0; i < len(inputs); i++ { - buf.Write(inputs[i].FillBytes(make([]byte, 32))) - } - hashVal := crypto.Keccak256Hash(buf.Bytes()) - result := outputs[0] - result.SetBytes(hashVal[:]) - return nil -} - -var ( - PackedAmountMaxAmount = ffmath.Multiply(big.NewInt(34359738367), new(big.Int).Exp(big.NewInt(10), big.NewInt(31), nil)) - PackedAmountMaxMantissa = big.NewInt(34359738367) - ZeroBigInt = big.NewInt(0) -) - -func CleanPackedAmount(amount *big.Int) (nAmount *big.Int, err error) { - if amount.Cmp(ZeroBigInt) < 0 || amount.Cmp(PackedAmountMaxAmount) > 0 { - log.Println("[ToPackedAmount] invalid amount") - return nil, errors.New("[ToPackedAmount] invalid amount") - } - oAmount := new(big.Int).Set(amount) - exponent := int64(0) - for oAmount.Cmp(PackedAmountMaxMantissa) > 0 { - oAmount = ffmath.Div(oAmount, big.NewInt(10)) - exponent++ - } - nAmount = ffmath.Multiply(oAmount, new(big.Int).Exp(big.NewInt(10), big.NewInt(exponent), nil)) - return nAmount, nil -} - -func ComputeSLp(curveID ecc.ID, inputs []*big.Int, outputs []*big.Int) error { - if len(inputs) != 5 { - return errors.New("[ComputeSLp] invalid params") - } - poolA := inputs[0] - poolB := inputs[1] - kLast := inputs[2] - feeRate := inputs[3] - treasuryRate := inputs[4] - if poolA.Cmp(ZeroBigInt) == 0 || poolB.Cmp(ZeroBigInt) == 0 { - outputs[0] = ZeroBigInt - return nil - } - kCurrent := ffmath.Multiply(poolA, poolB) - kLast.Sqrt(kLast) - kCurrent.Sqrt(kCurrent) - l := ffmath.Multiply(ffmath.Sub(kCurrent, kLast), big.NewInt(RateBase)) - r := ffmath.Multiply(ffmath.Sub(ffmath.Multiply(big.NewInt(RateBase), ffmath.Div(feeRate, treasuryRate)), big.NewInt(RateBase)), kCurrent) - r = ffmath.Add(r, ffmath.Multiply(big.NewInt(RateBase), kLast)) - var err error - outputs[0], err = CleanPackedAmount(ffmath.Div(l, r)) - if err != nil { - return err - } - return nil -} diff --git a/accumulators/merkleTree/sparseMerkle.go b/merkleTree/sparse_merkle.go similarity index 98% rename from accumulators/merkleTree/sparseMerkle.go rename to merkleTree/sparse_merkle.go index 386bd735c..8bc8ff2a5 100644 --- a/accumulators/merkleTree/sparseMerkle.go +++ b/merkleTree/sparse_merkle.go @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Zecrey Protocol + * Copyright © 2022 ZkBNB Protocol * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,6 +23,8 @@ import ( "fmt" "hash" "log" + + "github.com/ethereum/go-ethereum/common" ) const ( @@ -30,6 +32,10 @@ const ( Right = 1 ) +var ( + NilHash = common.FromHex("01ef55cdf3b9b0d65e6fb6317f79627534d971fd96c811281af618c0028d5e7a") +) + /* Tree: sparse merkle tree */ @@ -166,7 +172,7 @@ func NewTreeByMap(leaves map[int64]*Node, maxHeight int, nilHash []byte, hFunc h nilHashValueConst[0] = nilHash // scan map maxIndex := int64(-1) - for index, _ := range leaves { + for index := range leaves { if index > maxIndex { maxIndex = index } diff --git a/accumulators/merkleTree/sparseMerkle_test.go b/merkleTree/sparse_merkle_test.go similarity index 97% rename from accumulators/merkleTree/sparseMerkle_test.go rename to merkleTree/sparse_merkle_test.go index 40dabf676..db64a784c 100644 --- a/accumulators/merkleTree/sparseMerkle_test.go +++ b/merkleTree/sparse_merkle_test.go @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Zecrey Protocol + * Copyright © 2022 ZkBNB Protocol * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,8 +28,6 @@ import ( "github.com/consensys/gnark-crypto/ecc/bn254/fr/mimc" "github.com/ethereum/go-ethereum/common" "github.com/stretchr/testify/assert" - - "github.com/bnb-chain/zkbnb-crypto/hash/bn254/zmimc" ) func MockState(size int) [][]byte { @@ -37,7 +35,7 @@ func MockState(size int) [][]byte { // panic("err size") //} var hashState [][]byte - h := zmimc.Hmimc + h := mimc.NewMiMC() for i := 0; i < size; i++ { h.Reset() h.Write([]byte(strconv.Itoa(i))) @@ -183,7 +181,7 @@ func TestNewTreeByMap(t *testing.T) { Parent: nil, Height: 0, } - tree, err := NewTreeByMap(leaves, 16, NilHash, zmimc.Hmimc) + tree, err := NewTreeByMap(leaves, 16, NilHash, mimc.NewMiMC()) if err != nil { t.Fatal(err) } @@ -220,7 +218,7 @@ func TestNewTreeByMap(t *testing.T) { func TestNewEmptyTree(t *testing.T) { h := mimc.NewMiMC() nilHash := h.Sum([]byte{}) - tree, err := NewEmptyTree(5, nilHash, zmimc.Hmimc) + tree, err := NewEmptyTree(5, nilHash, mimc.NewMiMC()) if err != nil { t.Fatal(err) } diff --git a/mobile/cmd.sh b/mobile/cmd.sh deleted file mode 100644 index 8efb9c0e1..000000000 --- a/mobile/cmd.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/usr/bin/env bash -gomobile bind -target andorid . -gomobile bind -target ios . \ No newline at end of file diff --git a/mobile/legend/addLiquidity.go b/mobile/legend/addLiquidity.go deleted file mode 100644 index 8cffd2966..000000000 --- a/mobile/legend/addLiquidity.go +++ /dev/null @@ -1,27 +0,0 @@ -package legend - -import ( - "encoding/json" - "log" - - curve "github.com/bnb-chain/zkbnb-crypto/ecc/ztwistededwards/tebn254" - "github.com/bnb-chain/zkbnb-crypto/wasm/legend/legendTxTypes" -) - -func SignAddLiquidity(seed string, segmentInfo string) (txInfo string, err error) { - // parse segmentInfo - sk, err := curve.GenerateEddsaPrivateKey(seed) - if err != nil { - return "", err - } - oTxInfo, err := legendTxTypes.ConstructAddLiquidityTxInfo(sk, segmentInfo) - if err != nil { - return "", err - } - txInfoBytes, err := json.Marshal(oTxInfo) - if err != nil { - log.Println("unable to marshal:", err) - return "", err - } - return string(txInfoBytes), nil -} diff --git a/mobile/legend/atomicMatch.go b/mobile/legend/atomicMatch.go deleted file mode 100644 index 162763ac8..000000000 --- a/mobile/legend/atomicMatch.go +++ /dev/null @@ -1,27 +0,0 @@ -package legend - -import ( - "encoding/json" - "log" - - curve "github.com/bnb-chain/zkbnb-crypto/ecc/ztwistededwards/tebn254" - "github.com/bnb-chain/zkbnb-crypto/wasm/legend/legendTxTypes" -) - -func SignAtomicMatch(seed string, segmentInfo string) (txInfo string, err error) { - // parse segmentInfo - sk, err := curve.GenerateEddsaPrivateKey(seed) - if err != nil { - return "", err - } - oTxInfo, err := legendTxTypes.ConstructAtomicMatchTxInfo(sk, segmentInfo) - if err != nil { - return "", err - } - txInfoBytes, err := json.Marshal(oTxInfo) - if err != nil { - log.Println("unable to marshal:", err) - return "", err - } - return string(txInfoBytes), nil -} diff --git a/mobile/legend/cancelOffer.go b/mobile/legend/cancelOffer.go deleted file mode 100644 index f368fc5c8..000000000 --- a/mobile/legend/cancelOffer.go +++ /dev/null @@ -1,27 +0,0 @@ -package legend - -import ( - "encoding/json" - "log" - - curve "github.com/bnb-chain/zkbnb-crypto/ecc/ztwistededwards/tebn254" - "github.com/bnb-chain/zkbnb-crypto/wasm/legend/legendTxTypes" -) - -func SignCancelOffer(seed string, segmentInfo string) (txInfo string, err error) { - // parse segmentInfo - sk, err := curve.GenerateEddsaPrivateKey(seed) - if err != nil { - return "", err - } - oTxInfo, err := legendTxTypes.ConstructCancelOfferTxInfo(sk, segmentInfo) - if err != nil { - return "", err - } - txInfoBytes, err := json.Marshal(oTxInfo) - if err != nil { - log.Println("unable to marshal:", err) - return "", err - } - return string(txInfoBytes), nil -} diff --git a/mobile/legend/createCollection.go b/mobile/legend/createCollection.go deleted file mode 100644 index 3bcc0048e..000000000 --- a/mobile/legend/createCollection.go +++ /dev/null @@ -1,27 +0,0 @@ -package legend - -import ( - "encoding/json" - "log" - - curve "github.com/bnb-chain/zkbnb-crypto/ecc/ztwistededwards/tebn254" - "github.com/bnb-chain/zkbnb-crypto/wasm/legend/legendTxTypes" -) - -func SignCreateCollection(seed string, segmentInfo string) (txInfo string, err error) { - // parse segmentInfo - sk, err := curve.GenerateEddsaPrivateKey(seed) - if err != nil { - return "", err - } - oTxInfo, err := legendTxTypes.ConstructCreateCollectionTxInfo(sk, segmentInfo) - if err != nil { - return "", err - } - txInfoBytes, err := json.Marshal(oTxInfo) - if err != nil { - log.Println("unable to marshal:", err) - return "", err - } - return string(txInfoBytes), nil -} diff --git a/mobile/legend/mintNft.go b/mobile/legend/mintNft.go deleted file mode 100644 index ebbdf66c7..000000000 --- a/mobile/legend/mintNft.go +++ /dev/null @@ -1,27 +0,0 @@ -package legend - -import ( - "encoding/json" - "log" - - curve "github.com/bnb-chain/zkbnb-crypto/ecc/ztwistededwards/tebn254" - "github.com/bnb-chain/zkbnb-crypto/wasm/legend/legendTxTypes" -) - -func SignMintNft(seed string, segmentInfo string) (txInfo string, err error) { - // parse segmentInfo - sk, err := curve.GenerateEddsaPrivateKey(seed) - if err != nil { - return "", err - } - oTxInfo, err := legendTxTypes.ConstructMintNftTxInfo(sk, segmentInfo) - if err != nil { - return "", err - } - txInfoBytes, err := json.Marshal(oTxInfo) - if err != nil { - log.Println("unable to marshal:", err) - return "", err - } - return string(txInfoBytes), nil -} diff --git a/mobile/legend/offer.go b/mobile/legend/offer.go deleted file mode 100644 index da08d375c..000000000 --- a/mobile/legend/offer.go +++ /dev/null @@ -1,27 +0,0 @@ -package legend - -import ( - "encoding/json" - "log" - - curve "github.com/bnb-chain/zkbnb-crypto/ecc/ztwistededwards/tebn254" - "github.com/bnb-chain/zkbnb-crypto/wasm/legend/legendTxTypes" -) - -func SignOffer(seed string, segmentInfo string) (txInfo string, err error) { - // parse segmentInfo - sk, err := curve.GenerateEddsaPrivateKey(seed) - if err != nil { - return "", err - } - oTxInfo, err := legendTxTypes.ConstructOfferTxInfo(sk, segmentInfo) - if err != nil { - return "", err - } - txInfoBytes, err := json.Marshal(oTxInfo) - if err != nil { - log.Println("unable to marshal:", err) - return "", err - } - return string(txInfoBytes), nil -} diff --git a/mobile/legend/removeLiquidity.go b/mobile/legend/removeLiquidity.go deleted file mode 100644 index f2ea5bcec..000000000 --- a/mobile/legend/removeLiquidity.go +++ /dev/null @@ -1,27 +0,0 @@ -package legend - -import ( - "encoding/json" - "log" - - curve "github.com/bnb-chain/zkbnb-crypto/ecc/ztwistededwards/tebn254" - "github.com/bnb-chain/zkbnb-crypto/wasm/legend/legendTxTypes" -) - -func SignRemoveLiquidity(seed string, segmentInfo string) (txInfo string, err error) { - // parse segmentInfo - sk, err := curve.GenerateEddsaPrivateKey(seed) - if err != nil { - return "", err - } - oTxInfo, err := legendTxTypes.ConstructRemoveLiquidityTxInfo(sk, segmentInfo) - if err != nil { - return "", err - } - txInfoBytes, err := json.Marshal(oTxInfo) - if err != nil { - log.Println("unable to marshal:", err) - return "", err - } - return string(txInfoBytes), nil -} diff --git a/mobile/legend/swap.go b/mobile/legend/swap.go deleted file mode 100644 index 1617ae043..000000000 --- a/mobile/legend/swap.go +++ /dev/null @@ -1,27 +0,0 @@ -package legend - -import ( - "encoding/json" - "log" - - curve "github.com/bnb-chain/zkbnb-crypto/ecc/ztwistededwards/tebn254" - "github.com/bnb-chain/zkbnb-crypto/wasm/legend/legendTxTypes" -) - -func SignSwap(seed string, segmentInfo string) (txInfo string, err error) { - // parse segmentInfo - sk, err := curve.GenerateEddsaPrivateKey(seed) - if err != nil { - return "", err - } - oTxInfo, err := legendTxTypes.ConstructSwapTxInfo(sk, segmentInfo) - if err != nil { - return "", err - } - txInfoBytes, err := json.Marshal(oTxInfo) - if err != nil { - log.Println("unable to marshal:", err) - return "", err - } - return string(txInfoBytes), nil -} diff --git a/mobile/legend/transfer.go b/mobile/legend/transfer.go deleted file mode 100644 index 1a04e321b..000000000 --- a/mobile/legend/transfer.go +++ /dev/null @@ -1,27 +0,0 @@ -package legend - -import ( - "encoding/json" - "log" - - curve "github.com/bnb-chain/zkbnb-crypto/ecc/ztwistededwards/tebn254" - "github.com/bnb-chain/zkbnb-crypto/wasm/legend/legendTxTypes" -) - -func SignTransfer(seed string, segmentInfo string) (txInfo string, err error) { - // parse segmentInfo - sk, err := curve.GenerateEddsaPrivateKey(seed) - if err != nil { - return "", err - } - oTxInfo, err := legendTxTypes.ConstructTransferTxInfo(sk, segmentInfo) - if err != nil { - return "", err - } - txInfoBytes, err := json.Marshal(oTxInfo) - if err != nil { - log.Println("unable to marshal:", err) - return "", err - } - return string(txInfoBytes), nil -} diff --git a/mobile/legend/transferNft.go b/mobile/legend/transferNft.go deleted file mode 100644 index bc21c07aa..000000000 --- a/mobile/legend/transferNft.go +++ /dev/null @@ -1,27 +0,0 @@ -package legend - -import ( - "encoding/json" - "log" - - curve "github.com/bnb-chain/zkbnb-crypto/ecc/ztwistededwards/tebn254" - "github.com/bnb-chain/zkbnb-crypto/wasm/legend/legendTxTypes" -) - -func SignTransferNft(seed string, segmentInfo string) (txInfo string, err error) { - // parse segmentInfo - sk, err := curve.GenerateEddsaPrivateKey(seed) - if err != nil { - return "", err - } - oTxInfo, err := legendTxTypes.ConstructTransferNftTxInfo(sk, segmentInfo) - if err != nil { - return "", err - } - txInfoBytes, err := json.Marshal(oTxInfo) - if err != nil { - log.Println("unable to marshal:", err) - return "", err - } - return string(txInfoBytes), nil -} diff --git a/mobile/legend/withdraw.go b/mobile/legend/withdraw.go deleted file mode 100644 index 1066f1e81..000000000 --- a/mobile/legend/withdraw.go +++ /dev/null @@ -1,27 +0,0 @@ -package legend - -import ( - "encoding/json" - "log" - - curve "github.com/bnb-chain/zkbnb-crypto/ecc/ztwistededwards/tebn254" - "github.com/bnb-chain/zkbnb-crypto/wasm/legend/legendTxTypes" -) - -func SignWithdraw(seed string, segmentInfo string) (txInfo string, err error) { - // parse segmentInfo - sk, err := curve.GenerateEddsaPrivateKey(seed) - if err != nil { - return "", err - } - oTxInfo, err := legendTxTypes.ConstructWithdrawTxInfo(sk, segmentInfo) - if err != nil { - return "", err - } - txInfoBytes, err := json.Marshal(oTxInfo) - if err != nil { - log.Println("unable to marshal:", err) - return "", err - } - return string(txInfoBytes), nil -} diff --git a/mobile/legend/withdrawNft.go b/mobile/legend/withdrawNft.go deleted file mode 100644 index c0c1fe1bf..000000000 --- a/mobile/legend/withdrawNft.go +++ /dev/null @@ -1,27 +0,0 @@ -package legend - -import ( - "encoding/json" - "log" - - curve "github.com/bnb-chain/zkbnb-crypto/ecc/ztwistededwards/tebn254" - "github.com/bnb-chain/zkbnb-crypto/wasm/legend/legendTxTypes" -) - -func SignWithdrawNft(seed string, segmentInfo string) (txInfo string, err error) { - // parse segmentInfo - sk, err := curve.GenerateEddsaPrivateKey(seed) - if err != nil { - return "", err - } - oTxInfo, err := legendTxTypes.ConstructWithdrawNftTxInfo(sk, segmentInfo) - if err != nil { - return "", err - } - txInfoBytes, err := json.Marshal(oTxInfo) - if err != nil { - log.Println("unable to marshal:", err) - return "", err - } - return string(txInfoBytes), nil -} diff --git a/util/balanceHelper.go b/util/balance.go similarity index 95% rename from util/balanceHelper.go rename to util/balance.go index 5e1781e26..321f306a8 100644 --- a/util/balanceHelper.go +++ b/util/balance.go @@ -20,7 +20,7 @@ var ( ) /* - ToPackedAmount: convert big int to 40 bit, 5 bits for 10^x, 35 bits for a * 10^x +ToPackedAmount: convert big int to 40 bit, 5 bits for 10^x, 35 bits for a * 10^x */ func ToPackedAmount(amount *big.Int) (res int64, err error) { if amount.Cmp(ZeroBigInt) < 0 || amount.Cmp(PackedAmountMaxAmount) > 0 { @@ -63,7 +63,7 @@ func CleanPackedAmount(amount *big.Int) (nAmount *big.Int, err error) { } /* - ToPackedFee: convert big int to 16 bit, 5 bits for 10^x, 11 bits for a * 10^x +ToPackedFee: convert big int to 16 bit, 5 bits for 10^x, 11 bits for a * 10^x */ func ToPackedFee(amount *big.Int) (res int64, err error) { if amount.Cmp(ZeroBigInt) < 0 || amount.Cmp(PackedFeeMaxAmount) > 0 { diff --git a/util/balanceHelper_test.go b/util/balance_test.go similarity index 100% rename from util/balanceHelper_test.go rename to util/balance_test.go diff --git a/util/bytesUtil.go b/util/bytesUtil.go deleted file mode 100644 index 416300dd5..000000000 --- a/util/bytesUtil.go +++ /dev/null @@ -1,107 +0,0 @@ -/* - * Copyright © 2021 Zecrey Protocol - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package util - -import ( - "errors" - "math/big" -) - -// contact bytes -func ContactBytes(a, b []byte, in ...[]byte) (res []byte) { - contact := func(_a, _b []byte) (_res []byte) { - _res = append(_a, _b...) - return _res - } - res = append(a, b...) - for i := 0; i < len(in); i++ { - res = contact(res, in[i]) - } - return res -} - -func FlipBytes(bytesIn []byte) []byte { - length := len(bytesIn) - flippedBytes := make([]byte, length) - for i := 0; i < length; i++ { - flippedBytes[i] = bytesIn[i] ^ 255 - } - return flippedBytes -} - -func ToByteArray(in *big.Int) []byte { - isNegative := in.Cmp(new(big.Int).SetInt64(0)) < 0 - bytes := in.Bytes() - length := len(bytes) - if length == 0 { - return []byte{0} - } - highestByte := bytes[0] - var convertedBytes []byte - if !isNegative { - if (highestByte & 128) != 0 { - - convertedBytes = make([]byte, length+1) - convertedBytes[0] = 0 - copy(convertedBytes[1:], bytes) - return convertedBytes - } else { - return bytes - } - } else { - if (highestByte & 128) != 0 { - - convertedBytes = make([]byte, length+1) - convertedBytes[0] = 255 - copy(convertedBytes[1:], FlipBytes(bytes)) - } else { - convertedBytes = FlipBytes(bytes) - } - - convertedInt := new(big.Int).SetBytes(convertedBytes) - convertedInt.Add(convertedInt, big.NewInt(1)) - return convertedInt.Bytes() - } -} - -func FromByteArray(bytesIn []byte) (*big.Int, error) { - const MINUS_ONE = -1 - if len(bytesIn) == 0 { - err := errors.New("cannot convert empty array to big.Int") - return nil, err - } - highestByte := bytesIn[0] - isNegative := (highestByte & 128) != 0 - var convertedBytes []byte - if isNegative { - tmpInt := new(big.Int).SetBytes(bytesIn) - tmpInt = tmpInt.Sub(tmpInt, big.NewInt(1)) - tmpBytes := tmpInt.Bytes() - if tmpBytes[0] == 255 { - convertedBytes = FlipBytes(tmpBytes)[1:] - } else { - convertedBytes = tmpBytes - copy(convertedBytes, FlipBytes(tmpBytes)) - } - tmp := new(big.Int).SetBytes(convertedBytes) - return tmp.Mul(tmp, big.NewInt(MINUS_ONE)), nil - } else { - // if positive leave unchanged (additional 0-bytes will be ignored) - return new(big.Int).SetBytes(bytesIn), nil - } -} diff --git a/util/hashUtil.go b/util/hash.go similarity index 90% rename from util/hashUtil.go rename to util/hash.go index 41ac4797b..5030a4b01 100644 --- a/util/hashUtil.go +++ b/util/hash.go @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Zecrey Protocol + * Copyright © 2022 ZkBNB Protocol * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,9 +25,6 @@ import ( "github.com/consensys/gnark-crypto/ecc/bn254/fr/mimc" ) -/* - HashToInt: compute hash by buf and convert it to big int -*/ func HashToInt(b bytes.Buffer, h hash.Hash) (*big.Int, error) { h = mimc.NewMiMC() digest := h diff --git a/wasm/legend/main.go b/wasm/legend/main.go deleted file mode 100644 index f8147c62c..000000000 --- a/wasm/legend/main.go +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright © 2021 Zecrey Protocol - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package main - -import ( - "fmt" - - "syscall/js" - - "github.com/bnb-chain/zkbnb-crypto/wasm/legend/src" -) - -/* - zecrey-zero wasm libraries -*/ - -func main() { - fmt.Println("ZkBNB Crypto Assembly") - // util - js.Global().Set("cleanPackedAmount", src.CleanPackedAmountUtil()) - js.Global().Set("cleanPackedFee", src.CleanPackedFeeUtil()) - // account - js.Global().Set("getAccountNameHash", src.AccountNameHash()) - // eddsa - js.Global().Set("getEddsaPublicKey", src.GetEddsaPublicKey()) - js.Global().Set("getEddsaCompressedPublicKey", src.GetEddsaCompressedPublicKey()) - js.Global().Set("generateEddsaKey", src.GenerateEddsaKey()) - js.Global().Set("eddsaSign", src.EddsaSign()) - js.Global().Set("eddsaVerify", src.EddsaVerify()) - - // transaction - // asset - js.Global().Set("signAddLiquidity", src.AddLiquidityTx()) - js.Global().Set("signRemoveLiquidity", src.RemoveLiquidityTx()) - js.Global().Set("signSwap", src.SwapTx()) - js.Global().Set("signTransfer", src.TransferTx()) - js.Global().Set("signWithdraw", src.WithdrawTx()) - - // nft - js.Global().Set("signAtomicMatch", src.AtomicMatchTx()) - js.Global().Set("signCancelOffer", src.CancelOfferTx()) - js.Global().Set("signCreateCollection", src.CreateCollectionTx()) - js.Global().Set("signOffer", src.OfferTx()) - js.Global().Set("signMintNft", src.MintNftTx()) - js.Global().Set("signTransferNft", src.TransferNftTx()) - js.Global().Set("signWithdrawNft", src.WithdrawNftTx()) - <-make(chan bool) -} diff --git a/wasm/legend/test/addLiquidity_test.go b/wasm/legend/test/addLiquidity_test.go deleted file mode 100644 index 22293713f..000000000 --- a/wasm/legend/test/addLiquidity_test.go +++ /dev/null @@ -1,35 +0,0 @@ -package test - -import ( - "encoding/json" - "log" - "testing" - - "github.com/stretchr/testify/assert" - - "github.com/bnb-chain/zkbnb-crypto/wasm/legend/legendTxTypes" -) - -func TestAddLiquiditySegmentFormat(t *testing.T) { - - var segmentFormat *legendTxTypes.AddLiquiditySegmentFormat - segmentFormat = &legendTxTypes.AddLiquiditySegmentFormat{ - FromAccountIndex: 0, - PairIndex: 0, - AssetAId: 1, - AssetAAmount: "10000", - AssetBId: 2, - AssetBAmount: "100", - LpAmount: "1000", - GasAccountIndex: 1, - GasFeeAssetId: 3, - GasFeeAssetAmount: "3", - ExpiredAt: 1654656781000, // milli seconds - Nonce: 1, - } - - res, err := json.Marshal(segmentFormat) - assert.Nil(t, err) - - log.Println(string(res)) -} diff --git a/wasm/legend/test/atomicMatch_test.go b/wasm/legend/test/atomicMatch_test.go deleted file mode 100644 index eb78d2da5..000000000 --- a/wasm/legend/test/atomicMatch_test.go +++ /dev/null @@ -1,46 +0,0 @@ -package test - -import ( - "encoding/json" - "log" - "testing" - - "github.com/stretchr/testify/assert" - - curve "github.com/bnb-chain/zkbnb-crypto/ecc/ztwistededwards/tebn254" - "github.com/bnb-chain/zkbnb-crypto/wasm/legend/legendTxTypes" -) - -func TestAtomicMatchSegmentFormat(t *testing.T) { - - var segmentFormat *legendTxTypes.AtomicMatchSegmentFormat - segmentFormat = &legendTxTypes.AtomicMatchSegmentFormat{ - AccountIndex: 0, - BuyOffer: "{\"Type\":0,\"OfferId\":1,\"AccountIndex\":1,\"NftIndex\":1500,\"AssetId\":1,\"AssetAmount\":10000,\"ListedAt\":1654656761000,\"ExpiredAt\":1654656781000,\"TreasuryRate\":200,\"Sig\":\"f7EryTm0P7xCgDYsyB+R+Of3ZHHyVa4uEI721shjoQgFdYuoMst49X0NFf9MraQevweNVH+728FHh0c1hEz20A==\"}", - SellOffer: "{\"Type\":1,\"OfferId\":1,\"AccountIndex\":2,\"NftIndex\":1500,\"AssetId\":1,\"AssetAmount\":10000,\"ListedAt\":1654656751000,\"ExpiredAt\":1654656791000,\"TreasuryRate\":200,\"Sig\":\"cCh08P8RloU+uNZESVVbl5mqOFiiXR2JRJaAnmqxz6gCBXny2J9OUh5X7tRHaEBxDRRXQ1mQGMVMoe1/ncw3sQ==\"}", - GasAccountIndex: 1, - GasFeeAssetId: 3, - GasFeeAssetAmount: "3", - Nonce: 1, - ExpiredAt: 1654656781000, // milli seconds - } - - res, err := json.Marshal(segmentFormat) - assert.Nil(t, err) - - log.Println(string(res)) - - var OfferTx *legendTxTypes.OfferTxInfo - err = json.Unmarshal([]byte(segmentFormat.BuyOffer), &OfferTx) - assert.Nil(t, err) - log.Println(OfferTx) - - var atomicSig = "{\"account_index\":0,\"buy_offer\":\"{\\\"Type\\\":0,\\\"OfferId\\\":1,\\\"AccountIndex\\\":1,\\\"NftIndex\\\":1500,\\\"AssetId\\\":1,\\\"AssetAmount\\\":10000,\\\"ListedAt\\\":1654656761000,\\\"ExpiredAt\\\":1654656781000,\\\"TreasuryRate\\\":200,\\\"Sig\\\":\\\"f7EryTm0P7xCgDYsyB+R+Of3ZHHyVa4uEI721shjoQgFdYuoMst49X0NFf9MraQevweNVH+728FHh0c1hEz20A==\\\"}\",\"sell_offer\":\"{\\\"Type\\\":1,\\\"OfferId\\\":1,\\\"AccountIndex\\\":2,\\\"NftIndex\\\":1500,\\\"AssetId\\\":1,\\\"AssetAmount\\\":10000,\\\"ListedAt\\\":1654656751000,\\\"ExpiredAt\\\":1654656791000,\\\"TreasuryRate\\\":200,\\\"Sig\\\":\\\"cCh08P8RloU+uNZESVVbl5mqOFiiXR2JRJaAnmqxz6gCBXny2J9OUh5X7tRHaEBxDRRXQ1mQGMVMoe1/ncw3sQ==\\\"}\",\"gas_account_index\":1,\"gas_fee_asset_id\":3,\"gas_fee_asset_amount\":\"3\",\"nonce\":1,\"expired_at\":1654656781000}" - - err = json.Unmarshal([]byte(atomicSig), &segmentFormat) - log.Println(segmentFormat) - - sk, err := curve.GenerateEddsaPrivateKey("seed") - _, err = legendTxTypes.ConstructAtomicMatchTxInfo(sk, atomicSig) - assert.Nil(t, err) -} diff --git a/wasm/legend/test/cancelOffer_test.go b/wasm/legend/test/cancelOffer_test.go deleted file mode 100644 index e9a83c178..000000000 --- a/wasm/legend/test/cancelOffer_test.go +++ /dev/null @@ -1,31 +0,0 @@ -package test - -import ( - "encoding/json" - "log" - "testing" - - "github.com/stretchr/testify/assert" - - "github.com/bnb-chain/zkbnb-crypto/wasm/legend/legendTxTypes" -) - -func TestCancelOfferSegmentFormat(t *testing.T) { - - var segmentFormat *legendTxTypes.CancelOfferSegmentFormat - segmentFormat = &legendTxTypes.CancelOfferSegmentFormat{ - AccountIndex: 0, - OfferId: 1, - GasAccountIndex: 1, - GasFeeAssetId: 3, - GasFeeAssetAmount: "3", - Nonce: 1, - ExpiredAt: 1654656781000, // milli seconds - } - - res, err := json.Marshal(segmentFormat) - assert.Nil(t, err) - - log.Println(string(res)) - -} diff --git a/wasm/legend/test/createCollection_test.go b/wasm/legend/test/createCollection_test.go deleted file mode 100644 index d68afd82e..000000000 --- a/wasm/legend/test/createCollection_test.go +++ /dev/null @@ -1,32 +0,0 @@ -package test - -import ( - "encoding/json" - "log" - "testing" - - "github.com/stretchr/testify/assert" - - "github.com/bnb-chain/zkbnb-crypto/wasm/legend/legendTxTypes" -) - -func TestCreateCollectionSegmentFormat(t *testing.T) { - - var segmentFormat *legendTxTypes.CreateCollectionSegmentFormat - segmentFormat = &legendTxTypes.CreateCollectionSegmentFormat{ - AccountIndex: 0, - CollectionId: 1, - Name: "crypto punk", - Introduction: "crypto punk is the king of jpeg nft", - GasAccountIndex: 1, - GasFeeAssetId: 3, - GasFeeAssetAmount: "3", - ExpiredAt: 1654656781000, // milli seconds - Nonce: 1, - } - - res, err := json.Marshal(segmentFormat) - assert.Nil(t, err) - - log.Println(string(res)) -} diff --git a/wasm/legend/test/eddsa_test.go b/wasm/legend/test/eddsa_test.go deleted file mode 100644 index 5c2558dac..000000000 --- a/wasm/legend/test/eddsa_test.go +++ /dev/null @@ -1,32 +0,0 @@ -package test - -import ( - "encoding/hex" - "log" - "testing" - - "github.com/consensys/gnark-crypto/ecc/bn254/fr/mimc" - "github.com/stretchr/testify/assert" - - curve "github.com/bnb-chain/zkbnb-crypto/ecc/ztwistededwards/tebn254" -) - -func TestEddsaPublicKey(t *testing.T) { - seed := "12345678901234567890123456789012" - sk, err := curve.GenerateEddsaPrivateKey(seed) - - assert.Nil(t, err) - log.Println(hex.EncodeToString(sk.PublicKey.Bytes())) - log.Println(hex.EncodeToString(sk.Bytes())) - - msg := "hello zecrey legend" - - hFunc := mimc.NewMiMC() - signature, err := sk.Sign([]byte(msg), hFunc) - assert.Nil(t, err) - - ok, err := sk.PublicKey.Verify(signature, []byte(msg), hFunc) - assert.Nil(t, err) - assert.True(t, ok) - -} diff --git a/wasm/legend/test/mintNft_test.go b/wasm/legend/test/mintNft_test.go deleted file mode 100644 index ea6c9f8d4..000000000 --- a/wasm/legend/test/mintNft_test.go +++ /dev/null @@ -1,34 +0,0 @@ -package test - -import ( - "encoding/json" - "log" - "testing" - - "github.com/stretchr/testify/assert" - - "github.com/bnb-chain/zkbnb-crypto/wasm/legend/legendTxTypes" -) - -func TestMintNftSegmentFormat(t *testing.T) { - - var segmentFormat *legendTxTypes.MintNftSegmentFormat - segmentFormat = &legendTxTypes.MintNftSegmentFormat{ - CreatorAccountIndex: 15, - ToAccountIndex: 1, - ToAccountNameHash: "ddc6171f9fe33153d95c8394c9135c277eb645401b85eb499393a2aefe6422a6", - NftContentHash: "7eb645401b85eb499393a2aefe6422a6ddc6171f9fe33153d95c8394c9135c27", - NftCollectionId: 65, - CreatorTreasuryRate: 30, - GasAccountIndex: 1, - GasFeeAssetId: 3, - GasFeeAssetAmount: "3", - ExpiredAt: 1654656781000, // milli seconds - Nonce: 1, - } - - res, err := json.Marshal(segmentFormat) - assert.Nil(t, err) - - log.Println(string(res)) -} diff --git a/wasm/legend/test/offer_test.go b/wasm/legend/test/offer_test.go deleted file mode 100644 index 1e049ae89..000000000 --- a/wasm/legend/test/offer_test.go +++ /dev/null @@ -1,51 +0,0 @@ -package test - -import ( - "encoding/json" - "log" - "testing" - - "github.com/stretchr/testify/assert" - - "github.com/bnb-chain/zkbnb-crypto/wasm/legend/legendTxTypes" -) - -func TestOfferSegmentFormat(t *testing.T) { - - var segmentFormat *legendTxTypes.OfferSegmentFormat - // buy offer - segmentFormat = &legendTxTypes.OfferSegmentFormat{ - Type: 0, - OfferId: 1, - AccountIndex: 1, - NftIndex: 1500, - AssetId: 1, - AssetAmount: "10000", - ListedAt: 1654656761000, - ExpiredAt: 1654656781000, // milli seconds - TreasuryRate: 200, // 2% - } - - res, err := json.Marshal(segmentFormat) - assert.Nil(t, err) - - log.Println(string(res)) - // sell offer - segmentFormat = &legendTxTypes.OfferSegmentFormat{ - Type: 1, - OfferId: 1, - AccountIndex: 2, - NftIndex: 1500, - AssetId: 1, - AssetAmount: "10000", - ListedAt: 1654656751000, - ExpiredAt: 1654656791000, // milli seconds - TreasuryRate: 200, // 2% - } - - res, err = json.Marshal(segmentFormat) - assert.Nil(t, err) - - log.Println(string(res)) - -} diff --git a/wasm/legend/test/removeLiquidity_test.go b/wasm/legend/test/removeLiquidity_test.go deleted file mode 100644 index d5cb577e6..000000000 --- a/wasm/legend/test/removeLiquidity_test.go +++ /dev/null @@ -1,37 +0,0 @@ -package test - -import ( - "encoding/json" - "log" - "testing" - - "github.com/stretchr/testify/assert" - - "github.com/bnb-chain/zkbnb-crypto/wasm/legend/legendTxTypes" -) - -func TestRemoveLiquiditySegmentFormat(t *testing.T) { - - var segmentFormat *legendTxTypes.RemoveLiquiditySegmentFormat - segmentFormat = &legendTxTypes.RemoveLiquiditySegmentFormat{ - FromAccountIndex: 0, - PairIndex: 0, - AssetAId: 1, - AssetAMinAmount: "9000", - AssetBId: 2, - AssetBMinAmount: "90", - LpAmount: "1000", - AssetAAmountDelta: "10000", - AssetBAmountDelta: "100", - GasAccountIndex: 1, - GasFeeAssetId: 3, - GasFeeAssetAmount: "3", - ExpiredAt: 1654656781000, // milli seconds - Nonce: 1, - } - - res, err := json.Marshal(segmentFormat) - assert.Nil(t, err) - - log.Println(string(res)) -} diff --git a/wasm/legend/test/swap_test.go b/wasm/legend/test/swap_test.go deleted file mode 100644 index 51b70ec41..000000000 --- a/wasm/legend/test/swap_test.go +++ /dev/null @@ -1,35 +0,0 @@ -package test - -import ( - "encoding/json" - "log" - "testing" - - "github.com/stretchr/testify/assert" - - "github.com/bnb-chain/zkbnb-crypto/wasm/legend/legendTxTypes" -) - -func TestSwapSegmentFormat(t *testing.T) { - - var segmentFormat *legendTxTypes.SwapSegmentFormat - segmentFormat = &legendTxTypes.SwapSegmentFormat{ - FromAccountIndex: 0, - PairIndex: 0, - AssetAId: 1, - AssetAAmount: "10000", - AssetBId: 2, - AssetBMinAmount: "95", - AssetBAmountDelta: "99", - GasAccountIndex: 1, - GasFeeAssetId: 3, - GasFeeAssetAmount: "3", - ExpiredAt: 1654656781000, // milli seconds - Nonce: 1, - } - - res, err := json.Marshal(segmentFormat) - assert.Nil(t, err) - - log.Println(string(res)) -} diff --git a/wasm/legend/test/transferNft_test.go b/wasm/legend/test/transferNft_test.go deleted file mode 100644 index 370470578..000000000 --- a/wasm/legend/test/transferNft_test.go +++ /dev/null @@ -1,33 +0,0 @@ -package test - -import ( - "encoding/json" - "log" - "testing" - - "github.com/stretchr/testify/assert" - - "github.com/bnb-chain/zkbnb-crypto/wasm/legend/legendTxTypes" -) - -func TestTransferNftSegmentFormat(t *testing.T) { - - var segmentFormat *legendTxTypes.TransferNftSegmentFormat - segmentFormat = &legendTxTypes.TransferNftSegmentFormat{ - FromAccountIndex: 0, - ToAccountIndex: 1, - ToAccountNameHash: "ddc6171f9fe33153d95c8394c9135c277eb645401b85eb499393a2aefe6422a6", - NftIndex: 15, - GasAccountIndex: 1, - GasFeeAssetId: 3, - GasFeeAssetAmount: "3", - CallData: "", - ExpiredAt: 1654656781000, // milli seconds - Nonce: 1, - } - - res, err := json.Marshal(segmentFormat) - assert.Nil(t, err) - - log.Println(string(res)) -} diff --git a/wasm/legend/test/transfer_test.go b/wasm/legend/test/transfer_test.go deleted file mode 100644 index ea4b73686..000000000 --- a/wasm/legend/test/transfer_test.go +++ /dev/null @@ -1,35 +0,0 @@ -package test - -import ( - "encoding/json" - "log" - "testing" - - "github.com/stretchr/testify/assert" - - "github.com/bnb-chain/zkbnb-crypto/wasm/legend/legendTxTypes" -) - -func TestTransferSegmentFormat(t *testing.T) { - - var segmentFormat *legendTxTypes.TransferSegmentFormat - segmentFormat = &legendTxTypes.TransferSegmentFormat{ - FromAccountIndex: 0, - ToAccountIndex: 1, - ToAccountNameHash: "ddc6171f9fe33153d95c8394c9135c277eb645401b85eb499393a2aefe6422a6", - AssetId: 0, - AssetAmount: "100", - GasAccountIndex: 1, - GasFeeAssetId: 3, - GasFeeAssetAmount: "3", - Memo: "transfer memo", - CallData: "", - ExpiredAt: 1654656781000, // milli seconds - Nonce: 1, - } - - res, err := json.Marshal(segmentFormat) - assert.Nil(t, err) - - log.Println(string(res)) -} diff --git a/wasm/legend/test/withdrawNft_test.go b/wasm/legend/test/withdrawNft_test.go deleted file mode 100644 index dad2fd897..000000000 --- a/wasm/legend/test/withdrawNft_test.go +++ /dev/null @@ -1,31 +0,0 @@ -package test - -import ( - "encoding/json" - "log" - "testing" - - "github.com/stretchr/testify/assert" - - "github.com/bnb-chain/zkbnb-crypto/wasm/legend/legendTxTypes" -) - -func TestWithdrawNftSegmentFormat(t *testing.T) { - - var segmentFormat *legendTxTypes.WithdrawNftSegmentFormat - segmentFormat = &legendTxTypes.WithdrawNftSegmentFormat{ - AccountIndex: 1, - NftIndex: 15, - ToAddress: "0x507Bd54B4232561BC0Ca106F7b029d064fD6bE4c", - GasAccountIndex: 1, - GasFeeAssetId: 3, - GasFeeAssetAmount: "3", - ExpiredAt: 1654656781000, // milli seconds - Nonce: 1, - } - - res, err := json.Marshal(segmentFormat) - assert.Nil(t, err) - - log.Println(string(res)) -} diff --git a/wasm/legend/test/withdraw_test.go b/wasm/legend/test/withdraw_test.go deleted file mode 100644 index e79d6fd9f..000000000 --- a/wasm/legend/test/withdraw_test.go +++ /dev/null @@ -1,32 +0,0 @@ -package test - -import ( - "encoding/json" - "log" - "testing" - - "github.com/stretchr/testify/assert" - - "github.com/bnb-chain/zkbnb-crypto/wasm/legend/legendTxTypes" -) - -func TestWithdrawSegmentFormat(t *testing.T) { - - var segmentFormat *legendTxTypes.WithdrawSegmentFormat - segmentFormat = &legendTxTypes.WithdrawSegmentFormat{ - FromAccountIndex: 0, - AssetId: 0, - AssetAmount: "100", - GasAccountIndex: 1, - GasFeeAssetId: 3, - GasFeeAssetAmount: "3", - ToAddress: "0x507Bd54B4232561BC0Ca106F7b029d064fD6bE4c", - ExpiredAt: 1654656781000, // milli seconds - Nonce: 1, - } - - res, err := json.Marshal(segmentFormat) - assert.Nil(t, err) - - log.Println(string(res)) -} diff --git a/wasm/main.go b/wasm/main.go new file mode 100644 index 000000000..63251782e --- /dev/null +++ b/wasm/main.go @@ -0,0 +1,63 @@ +/* + * Copyright © 2022 ZkBNB Protocol + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package main + +import ( + "fmt" + + "syscall/js" + + src2 "github.com/bnb-chain/zkbnb-crypto/wasm/src" +) + +/* + zkbnb wasm libraries +*/ + +func main() { + fmt.Println("ZkBNB Crypto Assembly") + // util + js.Global().Set("cleanPackedAmount", src2.CleanPackedAmountUtil()) + js.Global().Set("cleanPackedFee", src2.CleanPackedFeeUtil()) + // account + js.Global().Set("getAccountNameHash", src2.AccountNameHash()) + // eddsa + js.Global().Set("getEddsaPublicKey", src2.GetEddsaPublicKey()) + js.Global().Set("getEddsaCompressedPublicKey", src2.GetEddsaCompressedPublicKey()) + js.Global().Set("generateEddsaKey", src2.GenerateEddsaKey()) + js.Global().Set("eddsaSign", src2.EddsaSign()) + js.Global().Set("eddsaVerify", src2.EddsaVerify()) + + // transaction + // asset + js.Global().Set("signAddLiquidity", src2.AddLiquidityTx()) + js.Global().Set("signRemoveLiquidity", src2.RemoveLiquidityTx()) + js.Global().Set("signSwap", src2.SwapTx()) + js.Global().Set("signTransfer", src2.TransferTx()) + js.Global().Set("signWithdraw", src2.WithdrawTx()) + + // nft + js.Global().Set("signAtomicMatch", src2.AtomicMatchTx()) + js.Global().Set("signCancelOffer", src2.CancelOfferTx()) + js.Global().Set("signCreateCollection", src2.CreateCollectionTx()) + js.Global().Set("signOffer", src2.OfferTx()) + js.Global().Set("signMintNft", src2.MintNftTx()) + js.Global().Set("signTransferNft", src2.TransferNftTx()) + js.Global().Set("signWithdrawNft", src2.WithdrawNftTx()) + <-make(chan bool) +} diff --git a/wasm/legend/src/account.go b/wasm/src/account.go similarity index 98% rename from wasm/legend/src/account.go rename to wasm/src/account.go index a6f054d42..76b19b5a5 100644 --- a/wasm/legend/src/account.go +++ b/wasm/src/account.go @@ -46,7 +46,7 @@ func AccountNameHash() js.Func { if len(args) != 1 { return "invalid swap params" } - // xxx.legend + name := args[0].String() nameHash, err := ComputeAccountNameHash(name) if err != nil { diff --git a/wasm/legend/src/addLiquidity.go b/wasm/src/add_liquidity.go similarity index 88% rename from wasm/legend/src/addLiquidity.go rename to wasm/src/add_liquidity.go index 0e6fddf6b..bbf1df587 100644 --- a/wasm/legend/src/addLiquidity.go +++ b/wasm/src/add_liquidity.go @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Zecrey Protocol + * Copyright © 2022 ZkBNB Protocol * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,7 +24,7 @@ import ( "syscall/js" curve "github.com/bnb-chain/zkbnb-crypto/ecc/ztwistededwards/tebn254" - "github.com/bnb-chain/zkbnb-crypto/wasm/legend/legendTxTypes" + "github.com/bnb-chain/zkbnb-crypto/wasm/txtypes" ) func AddLiquidityTx() js.Func { @@ -38,7 +38,7 @@ func AddLiquidityTx() js.Func { if err != nil { return err.Error() } - txInfo, err := legendTxTypes.ConstructAddLiquidityTxInfo(sk, segmentStr) + txInfo, err := txtypes.ConstructAddLiquidityTxInfo(sk, segmentStr) if err != nil { log.Println("[AddLiquidityTx] unable to construct generic transfer:", err) return err.Error() diff --git a/wasm/legend/src/atomicMatch.go b/wasm/src/atomic_match.go similarity index 88% rename from wasm/legend/src/atomicMatch.go rename to wasm/src/atomic_match.go index ea72bee14..c7daa42df 100644 --- a/wasm/legend/src/atomicMatch.go +++ b/wasm/src/atomic_match.go @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Zecrey Protocol + * Copyright © 2022 ZkBNB Protocol * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,7 +24,7 @@ import ( "syscall/js" curve "github.com/bnb-chain/zkbnb-crypto/ecc/ztwistededwards/tebn254" - "github.com/bnb-chain/zkbnb-crypto/wasm/legend/legendTxTypes" + "github.com/bnb-chain/zkbnb-crypto/wasm/txtypes" ) func AtomicMatchTx() js.Func { @@ -38,7 +38,7 @@ func AtomicMatchTx() js.Func { if err != nil { return err.Error() } - txInfo, err := legendTxTypes.ConstructAtomicMatchTxInfo(sk, segmentStr) + txInfo, err := txtypes.ConstructAtomicMatchTxInfo(sk, segmentStr) if err != nil { log.Println("[AtomicMatchTx] unable to construct generic transfer:", err) return err.Error() diff --git a/wasm/legend/src/balanceHelper.go b/wasm/src/balance_helper.go similarity index 100% rename from wasm/legend/src/balanceHelper.go rename to wasm/src/balance_helper.go diff --git a/wasm/legend/src/cancelOffer.go b/wasm/src/cancel_offer.go similarity index 88% rename from wasm/legend/src/cancelOffer.go rename to wasm/src/cancel_offer.go index ef5e706bc..54ee1e22e 100644 --- a/wasm/legend/src/cancelOffer.go +++ b/wasm/src/cancel_offer.go @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Zecrey Protocol + * Copyright © 2022 ZkBNB Protocol * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,7 +24,7 @@ import ( "syscall/js" curve "github.com/bnb-chain/zkbnb-crypto/ecc/ztwistededwards/tebn254" - "github.com/bnb-chain/zkbnb-crypto/wasm/legend/legendTxTypes" + "github.com/bnb-chain/zkbnb-crypto/wasm/txtypes" ) func CancelOfferTx() js.Func { @@ -38,7 +38,7 @@ func CancelOfferTx() js.Func { if err != nil { return err.Error() } - txInfo, err := legendTxTypes.ConstructCancelOfferTxInfo(sk, segmentStr) + txInfo, err := txtypes.ConstructCancelOfferTxInfo(sk, segmentStr) if err != nil { log.Println("[CancelOfferTx] unable to construct generic transfer:", err) return err.Error() diff --git a/wasm/legend/src/createCollection.go b/wasm/src/create_collection.go similarity index 88% rename from wasm/legend/src/createCollection.go rename to wasm/src/create_collection.go index 6819008b9..8882463a9 100644 --- a/wasm/legend/src/createCollection.go +++ b/wasm/src/create_collection.go @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Zecrey Protocol + * Copyright © 2022 ZkBNB Protocol * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,7 +24,7 @@ import ( "syscall/js" curve "github.com/bnb-chain/zkbnb-crypto/ecc/ztwistededwards/tebn254" - "github.com/bnb-chain/zkbnb-crypto/wasm/legend/legendTxTypes" + "github.com/bnb-chain/zkbnb-crypto/wasm/txtypes" ) func CreateCollectionTx() js.Func { @@ -38,7 +38,7 @@ func CreateCollectionTx() js.Func { if err != nil { return err.Error() } - txInfo, err := legendTxTypes.ConstructCreateCollectionTxInfo(sk, segmentStr) + txInfo, err := txtypes.ConstructCreateCollectionTxInfo(sk, segmentStr) if err != nil { log.Println("[CreateCollectionTx] unable to construct generic transfer:", err) return err.Error() diff --git a/wasm/legend/src/eddsa.go b/wasm/src/eddsa.go similarity index 98% rename from wasm/legend/src/eddsa.go rename to wasm/src/eddsa.go index 02ffe969f..afdef4642 100644 --- a/wasm/legend/src/eddsa.go +++ b/wasm/src/eddsa.go @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Zecrey Protocol + * Copyright © 2022 ZkBNB Protocol * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/wasm/legend/src/mintNft.go b/wasm/src/mint_nft.go similarity index 88% rename from wasm/legend/src/mintNft.go rename to wasm/src/mint_nft.go index 7f9f32ae1..94fcbfeb0 100644 --- a/wasm/legend/src/mintNft.go +++ b/wasm/src/mint_nft.go @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Zecrey Protocol + * Copyright © 2022 ZkBNB Protocol * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,7 +24,7 @@ import ( "syscall/js" curve "github.com/bnb-chain/zkbnb-crypto/ecc/ztwistededwards/tebn254" - "github.com/bnb-chain/zkbnb-crypto/wasm/legend/legendTxTypes" + "github.com/bnb-chain/zkbnb-crypto/wasm/txtypes" ) func MintNftTx() js.Func { @@ -38,7 +38,7 @@ func MintNftTx() js.Func { if err != nil { return err.Error() } - txInfo, err := legendTxTypes.ConstructMintNftTxInfo(sk, segmentStr) + txInfo, err := txtypes.ConstructMintNftTxInfo(sk, segmentStr) if err != nil { log.Println("[MintNftTx] unable to construct generic transfer:", err) return err.Error() diff --git a/wasm/legend/src/offer.go b/wasm/src/offer.go similarity index 88% rename from wasm/legend/src/offer.go rename to wasm/src/offer.go index b306c7196..d7631f08b 100644 --- a/wasm/legend/src/offer.go +++ b/wasm/src/offer.go @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Zecrey Protocol + * Copyright © 2022 ZkBNB Protocol * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,7 +24,7 @@ import ( "syscall/js" curve "github.com/bnb-chain/zkbnb-crypto/ecc/ztwistededwards/tebn254" - "github.com/bnb-chain/zkbnb-crypto/wasm/legend/legendTxTypes" + "github.com/bnb-chain/zkbnb-crypto/wasm/txtypes" ) func OfferTx() js.Func { @@ -38,7 +38,7 @@ func OfferTx() js.Func { if err != nil { return err.Error() } - txInfo, err := legendTxTypes.ConstructOfferTxInfo(sk, segmentStr) + txInfo, err := txtypes.ConstructOfferTxInfo(sk, segmentStr) if err != nil { log.Println("[OfferTx] unable to construct generic transfer:", err) return err.Error() diff --git a/wasm/legend/src/removeLiquidity.go b/wasm/src/remove_liquidity.go similarity index 88% rename from wasm/legend/src/removeLiquidity.go rename to wasm/src/remove_liquidity.go index 24222254d..1cfddc8af 100644 --- a/wasm/legend/src/removeLiquidity.go +++ b/wasm/src/remove_liquidity.go @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Zecrey Protocol + * Copyright © 2022 ZkBNB Protocol * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,7 +24,7 @@ import ( "syscall/js" curve "github.com/bnb-chain/zkbnb-crypto/ecc/ztwistededwards/tebn254" - "github.com/bnb-chain/zkbnb-crypto/wasm/legend/legendTxTypes" + "github.com/bnb-chain/zkbnb-crypto/wasm/txtypes" ) func RemoveLiquidityTx() js.Func { @@ -38,7 +38,7 @@ func RemoveLiquidityTx() js.Func { if err != nil { return err.Error() } - txInfo, err := legendTxTypes.ConstructRemoveLiquidityTxInfo(sk, segmentStr) + txInfo, err := txtypes.ConstructRemoveLiquidityTxInfo(sk, segmentStr) if err != nil { log.Println("[RemoveLiquidityTx] unable to construct generic transfer:", err) return err.Error() diff --git a/wasm/legend/src/swap.go b/wasm/src/swap.go similarity index 88% rename from wasm/legend/src/swap.go rename to wasm/src/swap.go index e74a0d004..db94ffcc1 100644 --- a/wasm/legend/src/swap.go +++ b/wasm/src/swap.go @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Zecrey Protocol + * Copyright © 2022 ZkBNB Protocol * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,7 +24,7 @@ import ( "syscall/js" curve "github.com/bnb-chain/zkbnb-crypto/ecc/ztwistededwards/tebn254" - "github.com/bnb-chain/zkbnb-crypto/wasm/legend/legendTxTypes" + "github.com/bnb-chain/zkbnb-crypto/wasm/txtypes" ) func SwapTx() js.Func { @@ -38,7 +38,7 @@ func SwapTx() js.Func { if err != nil { return err.Error() } - txInfo, err := legendTxTypes.ConstructSwapTxInfo(sk, segmentStr) + txInfo, err := txtypes.ConstructSwapTxInfo(sk, segmentStr) if err != nil { log.Println("[SwapTx] unable to construct generic transfer:", err) return err.Error() diff --git a/wasm/legend/src/transfer.go b/wasm/src/transfer.go similarity index 88% rename from wasm/legend/src/transfer.go rename to wasm/src/transfer.go index 9161bc882..d8f16bbdf 100644 --- a/wasm/legend/src/transfer.go +++ b/wasm/src/transfer.go @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Zecrey Protocol + * Copyright © 2022 ZkBNB Protocol * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,7 +24,7 @@ import ( "syscall/js" curve "github.com/bnb-chain/zkbnb-crypto/ecc/ztwistededwards/tebn254" - "github.com/bnb-chain/zkbnb-crypto/wasm/legend/legendTxTypes" + "github.com/bnb-chain/zkbnb-crypto/wasm/txtypes" ) func TransferTx() js.Func { @@ -38,7 +38,7 @@ func TransferTx() js.Func { if err != nil { return err.Error() } - txInfo, err := legendTxTypes.ConstructTransferTxInfo(sk, segmentStr) + txInfo, err := txtypes.ConstructTransferTxInfo(sk, segmentStr) if err != nil { log.Println("[GenericTransfer] unable to construct generic transfer:", err) return err.Error() diff --git a/wasm/legend/src/transferNft.go b/wasm/src/transfer_nft.go similarity index 88% rename from wasm/legend/src/transferNft.go rename to wasm/src/transfer_nft.go index a863a451f..e0d6f111b 100644 --- a/wasm/legend/src/transferNft.go +++ b/wasm/src/transfer_nft.go @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Zecrey Protocol + * Copyright © 2022 ZkBNB Protocol * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,7 +24,7 @@ import ( "syscall/js" curve "github.com/bnb-chain/zkbnb-crypto/ecc/ztwistededwards/tebn254" - "github.com/bnb-chain/zkbnb-crypto/wasm/legend/legendTxTypes" + "github.com/bnb-chain/zkbnb-crypto/wasm/txtypes" ) func TransferNftTx() js.Func { @@ -38,7 +38,7 @@ func TransferNftTx() js.Func { if err != nil { return err.Error() } - txInfo, err := legendTxTypes.ConstructTransferNftTxInfo(sk, segmentStr) + txInfo, err := txtypes.ConstructTransferNftTxInfo(sk, segmentStr) if err != nil { log.Println("[MintNftTx] unable to construct generic transfer:", err) return err.Error() diff --git a/wasm/legend/src/withdraw.go b/wasm/src/withdraw.go similarity index 88% rename from wasm/legend/src/withdraw.go rename to wasm/src/withdraw.go index 7f4dd33eb..186eae78c 100644 --- a/wasm/legend/src/withdraw.go +++ b/wasm/src/withdraw.go @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Zecrey Protocol + * Copyright © 2022 ZkBNB Protocol * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,7 +24,7 @@ import ( "syscall/js" curve "github.com/bnb-chain/zkbnb-crypto/ecc/ztwistededwards/tebn254" - "github.com/bnb-chain/zkbnb-crypto/wasm/legend/legendTxTypes" + "github.com/bnb-chain/zkbnb-crypto/wasm/txtypes" ) func WithdrawTx() js.Func { @@ -38,7 +38,7 @@ func WithdrawTx() js.Func { if err != nil { return err.Error() } - txInfo, err := legendTxTypes.ConstructWithdrawTxInfo(sk, segmentStr) + txInfo, err := txtypes.ConstructWithdrawTxInfo(sk, segmentStr) if err != nil { log.Println("[WithdrawTx] unable to construct generic transfer:", err) return err.Error() diff --git a/wasm/legend/src/withdrawNft.go b/wasm/src/withdraw_nft.go similarity index 88% rename from wasm/legend/src/withdrawNft.go rename to wasm/src/withdraw_nft.go index 602a8bf38..6dd0a432d 100644 --- a/wasm/legend/src/withdrawNft.go +++ b/wasm/src/withdraw_nft.go @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Zecrey Protocol + * Copyright © 2022 ZkBNB Protocol * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,7 +24,7 @@ import ( "syscall/js" curve "github.com/bnb-chain/zkbnb-crypto/ecc/ztwistededwards/tebn254" - "github.com/bnb-chain/zkbnb-crypto/wasm/legend/legendTxTypes" + "github.com/bnb-chain/zkbnb-crypto/wasm/txtypes" ) func WithdrawNftTx() js.Func { @@ -38,7 +38,7 @@ func WithdrawNftTx() js.Func { if err != nil { return err.Error() } - txInfo, err := legendTxTypes.ConstructWithdrawNftTxInfo(sk, segmentStr) + txInfo, err := txtypes.ConstructWithdrawNftTxInfo(sk, segmentStr) if err != nil { log.Println("[WithdrawNftTx] unable to construct generic transfer:", err) return err.Error() diff --git a/wasm/legend/legendTxTypes/addLiquidityTypes.go b/wasm/txtypes/add_liquidity.go similarity index 97% rename from wasm/legend/legendTxTypes/addLiquidityTypes.go rename to wasm/txtypes/add_liquidity.go index 39cc7d3a6..f31c2e125 100644 --- a/wasm/legend/legendTxTypes/addLiquidityTypes.go +++ b/wasm/txtypes/add_liquidity.go @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Zecrey Protocol + * Copyright © 2022 ZkBNB Protocol * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,7 +15,7 @@ * */ -package legendTxTypes +package txtypes import ( "bytes" @@ -257,3 +257,7 @@ func (txInfo *AddLiquidityTxInfo) Hash(hFunc hash.Hash) (msgHash []byte, err err msgHash = hFunc.Sum(nil) return msgHash, nil } + +func (txInfo *AddLiquidityTxInfo) GetGas() (int64, int64, *big.Int) { + return txInfo.GasAccountIndex, txInfo.GasFeeAssetId, txInfo.GasFeeAssetAmount +} diff --git a/wasm/legend/legendTxTypes/addLiquidityTypes_test.go b/wasm/txtypes/add_liquidity_test.go similarity index 98% rename from wasm/legend/legendTxTypes/addLiquidityTypes_test.go rename to wasm/txtypes/add_liquidity_test.go index f9b0a1692..676170db2 100644 --- a/wasm/legend/legendTxTypes/addLiquidityTypes_test.go +++ b/wasm/txtypes/add_liquidity_test.go @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Zecrey Protocol + * Copyright © 2022 ZkBNB Protocol * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,7 +15,7 @@ * */ -package legendTxTypes +package txtypes import ( "fmt" @@ -235,6 +235,7 @@ func TestValidateAddLiquidityTxInfo(t *testing.T) { GasFeeAssetId: 3, GasFeeAssetAmount: big.NewInt(1), ExpiredAt: time.Now().Add(time.Hour).UnixMilli(), + Nonce: -1, }, }, // true diff --git a/wasm/legend/legendTxTypes/atomicMatchTypes.go b/wasm/txtypes/atomic_match.go similarity index 97% rename from wasm/legend/legendTxTypes/atomicMatchTypes.go rename to wasm/txtypes/atomic_match.go index 5bc61d196..517bd03cb 100644 --- a/wasm/legend/legendTxTypes/atomicMatchTypes.go +++ b/wasm/txtypes/atomic_match.go @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Zecrey Protocol + * Copyright © 2022 ZkBNB Protocol * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,7 +15,7 @@ * */ -package legendTxTypes +package txtypes import ( "bytes" @@ -284,3 +284,7 @@ func (txInfo *AtomicMatchTxInfo) Hash(hFunc hash.Hash) (msgHash []byte, err erro msgHash = hFunc.Sum(nil) return msgHash, nil } + +func (txInfo *AtomicMatchTxInfo) GetGas() (int64, int64, *big.Int) { + return txInfo.GasAccountIndex, txInfo.GasFeeAssetId, txInfo.GasFeeAssetAmount +} diff --git a/wasm/legend/legendTxTypes/atomicMatchTypes_test.go b/wasm/txtypes/atomic_match_test.go similarity index 98% rename from wasm/legend/legendTxTypes/atomicMatchTypes_test.go rename to wasm/txtypes/atomic_match_test.go index c2c2c826c..39db3e8b2 100644 --- a/wasm/legend/legendTxTypes/atomicMatchTypes_test.go +++ b/wasm/txtypes/atomic_match_test.go @@ -1,4 +1,4 @@ -package legendTxTypes +package txtypes import ( "fmt" @@ -137,7 +137,7 @@ func TestValidateAtomicMatchTxInfo(t *testing.T) { GasFeeAssetId: 3, GasFeeAssetAmount: big.NewInt(100), ExpiredAt: time.Now().Add(time.Hour).UnixMilli(), - Nonce: 0, + Nonce: -1, }, }, } diff --git a/wasm/legend/legendTxTypes/cancelOfferTypes.go b/wasm/txtypes/cancel_offer.go similarity index 96% rename from wasm/legend/legendTxTypes/cancelOfferTypes.go rename to wasm/txtypes/cancel_offer.go index 470576196..213beb722 100644 --- a/wasm/legend/legendTxTypes/cancelOfferTypes.go +++ b/wasm/txtypes/cancel_offer.go @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Zecrey Protocol + * Copyright © 2022 ZkBNB Protocol * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,7 +15,7 @@ * */ -package legendTxTypes +package txtypes import ( "bytes" @@ -39,9 +39,6 @@ type CancelOfferSegmentFormat struct { Nonce int64 `json:"nonce"` } -/* - ConstructCancelOfferTxInfo: construct cancel offer tx, sign txInfo -*/ func ConstructCancelOfferTxInfo(sk *PrivateKey, segmentStr string) (txInfo *CancelOfferTxInfo, err error) { var segmentFormat *CancelOfferSegmentFormat err = json.Unmarshal([]byte(segmentStr), &segmentFormat) @@ -204,3 +201,7 @@ func (txInfo *CancelOfferTxInfo) Hash(hFunc hash.Hash) (msgHash []byte, err erro msgHash = hFunc.Sum(nil) return msgHash, nil } + +func (txInfo *CancelOfferTxInfo) GetGas() (int64, int64, *big.Int) { + return txInfo.GasAccountIndex, txInfo.GasFeeAssetId, txInfo.GasFeeAssetAmount +} diff --git a/wasm/legend/legendTxTypes/cancelOfferTypes_test.go b/wasm/txtypes/cancel_offer_test.go similarity index 98% rename from wasm/legend/legendTxTypes/cancelOfferTypes_test.go rename to wasm/txtypes/cancel_offer_test.go index 674c6b8bd..3a98b256d 100644 --- a/wasm/legend/legendTxTypes/cancelOfferTypes_test.go +++ b/wasm/txtypes/cancel_offer_test.go @@ -1,4 +1,4 @@ -package legendTxTypes +package txtypes import ( "fmt" @@ -111,7 +111,7 @@ func TestValidateCancelOfferTxInfo(t *testing.T) { GasFeeAssetId: 3, GasFeeAssetAmount: big.NewInt(100), ExpiredAt: time.Now().Add(time.Hour).UnixMilli(), - Nonce: 0, + Nonce: -1, }, }, // true diff --git a/wasm/legend/legendTxTypes/constants.go b/wasm/txtypes/constants.go similarity index 89% rename from wasm/legend/legendTxTypes/constants.go rename to wasm/txtypes/constants.go index f6930f04d..e4a30cafc 100644 --- a/wasm/legend/legendTxTypes/constants.go +++ b/wasm/txtypes/constants.go @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Zecrey Protocol + * Copyright © 2022 ZkBNB Protocol * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,14 +15,14 @@ * */ -package legendTxTypes +package txtypes import ( + "math" "math/big" "github.com/consensys/gnark-crypto/ecc/bn254/twistededwards/eddsa" - "github.com/bnb-chain/zkbnb-crypto/common" "github.com/bnb-chain/zkbnb-crypto/util" ) @@ -31,14 +31,15 @@ type ( PrivateKey = eddsa.PrivateKey ) -var ( - ChainId = int64(common.ChainId) +const ( + ChainId = 1 ) const ( - NilNonce = 0 - NilExpiredAt = 0 - NilTxAccountIndex = int64(-1) + NilNonce = -1 + NilExpiredAt = math.MaxInt64 + NilAccountIndex = int64(-1) + NilAssetId = int64(-1) ) const ( diff --git a/wasm/legend/legendTxTypes/createCollection.go b/wasm/txtypes/create_collection.go similarity index 96% rename from wasm/legend/legendTxTypes/createCollection.go rename to wasm/txtypes/create_collection.go index 3c0752fa6..87cfa14d6 100644 --- a/wasm/legend/legendTxTypes/createCollection.go +++ b/wasm/txtypes/create_collection.go @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Zecrey Protocol + * Copyright © 2022 ZkBNB Protocol * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,7 +15,7 @@ * */ -package legendTxTypes +package txtypes import ( "bytes" @@ -215,3 +215,7 @@ func (txInfo *CreateCollectionTxInfo) Hash(hFunc hash.Hash) (msgHash []byte, err msgHash = hFunc.Sum(nil) return msgHash, nil } + +func (txInfo *CreateCollectionTxInfo) GetGas() (int64, int64, *big.Int) { + return txInfo.GasAccountIndex, txInfo.GasFeeAssetId, txInfo.GasFeeAssetAmount +} diff --git a/wasm/legend/legendTxTypes/createCollection_test.go b/wasm/txtypes/create_collection_test.go similarity index 98% rename from wasm/legend/legendTxTypes/createCollection_test.go rename to wasm/txtypes/create_collection_test.go index 02347a202..bf4ebe5f4 100644 --- a/wasm/legend/legendTxTypes/createCollection_test.go +++ b/wasm/txtypes/create_collection_test.go @@ -1,4 +1,4 @@ -package legendTxTypes +package txtypes import ( "fmt" @@ -147,7 +147,7 @@ func TestValidateCreateCollectionTxInfo(t *testing.T) { GasFeeAssetId: 3, GasFeeAssetAmount: big.NewInt(100), ExpiredAt: time.Now().Add(time.Hour).UnixMilli(), - Nonce: 0, + Nonce: -1, }, }, // true diff --git a/wasm/legend/legendTxTypes/createPairTypes.go b/wasm/txtypes/create_pair.go similarity index 83% rename from wasm/legend/legendTxTypes/createPairTypes.go rename to wasm/txtypes/create_pair.go index 0db0de906..fdb5e7e83 100644 --- a/wasm/legend/legendTxTypes/createPairTypes.go +++ b/wasm/txtypes/create_pair.go @@ -1,8 +1,9 @@ -package legendTxTypes +package txtypes import ( "errors" "hash" + "math/big" ) type CreatePairTxInfo struct { @@ -30,7 +31,7 @@ func (txInfo *CreatePairTxInfo) VerifySignature(pubKey string) error { } func (txInfo *CreatePairTxInfo) GetFromAccountIndex() int64 { - return NilTxAccountIndex + return NilAccountIndex } func (txInfo *CreatePairTxInfo) GetNonce() int64 { @@ -44,3 +45,7 @@ func (txInfo *CreatePairTxInfo) GetExpiredAt() int64 { func (txInfo *CreatePairTxInfo) Hash(hFunc hash.Hash) (msgHash []byte, err error) { return msgHash, errors.New("not support") } + +func (txInfo *CreatePairTxInfo) GetGas() (int64, int64, *big.Int) { + return NilAccountIndex, NilAssetId, nil +} diff --git a/wasm/legend/legendTxTypes/deposityTxTypes.go b/wasm/txtypes/deposit.go similarity index 83% rename from wasm/legend/legendTxTypes/deposityTxTypes.go rename to wasm/txtypes/deposit.go index e1b43c1ed..da554c05b 100644 --- a/wasm/legend/legendTxTypes/deposityTxTypes.go +++ b/wasm/txtypes/deposit.go @@ -1,4 +1,4 @@ -package legendTxTypes +package txtypes import ( "errors" @@ -31,7 +31,7 @@ func (txInfo *DepositTxInfo) VerifySignature(pubKey string) error { } func (txInfo *DepositTxInfo) GetFromAccountIndex() int64 { - return NilTxAccountIndex + return NilAccountIndex } func (txInfo *DepositTxInfo) GetNonce() int64 { @@ -45,3 +45,7 @@ func (txInfo *DepositTxInfo) GetExpiredAt() int64 { func (txInfo *DepositTxInfo) Hash(hFunc hash.Hash) (msgHash []byte, err error) { return msgHash, errors.New("not support") } + +func (txInfo *DepositTxInfo) GetGas() (int64, int64, *big.Int) { + return NilAccountIndex, NilAssetId, nil +} diff --git a/wasm/legend/legendTxTypes/depositNftTypes.go b/wasm/txtypes/deposit_nft.go similarity index 87% rename from wasm/legend/legendTxTypes/depositNftTypes.go rename to wasm/txtypes/deposit_nft.go index bf1a11f0d..b90041241 100644 --- a/wasm/legend/legendTxTypes/depositNftTypes.go +++ b/wasm/txtypes/deposit_nft.go @@ -1,4 +1,4 @@ -package legendTxTypes +package txtypes import ( "errors" @@ -39,7 +39,7 @@ func (txInfo *DepositNftTxInfo) VerifySignature(pubKey string) error { } func (txInfo *DepositNftTxInfo) GetFromAccountIndex() int64 { - return NilTxAccountIndex + return NilAccountIndex } func (txInfo *DepositNftTxInfo) GetNonce() int64 { @@ -53,3 +53,7 @@ func (txInfo *DepositNftTxInfo) GetExpiredAt() int64 { func (txInfo *DepositNftTxInfo) Hash(hFunc hash.Hash) (msgHash []byte, err error) { return msgHash, errors.New("not support") } + +func (txInfo *DepositNftTxInfo) GetGas() (int64, int64, *big.Int) { + return NilAccountIndex, NilAssetId, nil +} diff --git a/wasm/legend/legendTxTypes/fullExitTypes.go b/wasm/txtypes/fullexit.go similarity index 83% rename from wasm/legend/legendTxTypes/fullExitTypes.go rename to wasm/txtypes/fullexit.go index 949fbae2c..8b834ed16 100644 --- a/wasm/legend/legendTxTypes/fullExitTypes.go +++ b/wasm/txtypes/fullexit.go @@ -1,4 +1,4 @@ -package legendTxTypes +package txtypes import ( "errors" @@ -31,7 +31,7 @@ func (txInfo *FullExitTxInfo) VerifySignature(pubKey string) error { } func (txInfo *FullExitTxInfo) GetFromAccountIndex() int64 { - return NilTxAccountIndex + return NilAccountIndex } func (txInfo *FullExitTxInfo) GetNonce() int64 { @@ -45,3 +45,7 @@ func (txInfo *FullExitTxInfo) GetExpiredAt() int64 { func (txInfo *FullExitTxInfo) Hash(hFunc hash.Hash) (msgHash []byte, err error) { return msgHash, errors.New("not support") } + +func (txInfo *FullExitTxInfo) GetGas() (int64, int64, *big.Int) { + return NilAccountIndex, NilAssetId, nil +} diff --git a/wasm/legend/legendTxTypes/fullExitNftTypes.go b/wasm/txtypes/fullexit_nft.go similarity index 86% rename from wasm/legend/legendTxTypes/fullExitNftTypes.go rename to wasm/txtypes/fullexit_nft.go index 6cf66bc0d..67413530d 100644 --- a/wasm/legend/legendTxTypes/fullExitNftTypes.go +++ b/wasm/txtypes/fullexit_nft.go @@ -1,4 +1,4 @@ -package legendTxTypes +package txtypes import ( "errors" @@ -37,7 +37,7 @@ func (txInfo *FullExitNftTxInfo) VerifySignature(pubKey string) error { } func (txInfo *FullExitNftTxInfo) GetFromAccountIndex() int64 { - return NilTxAccountIndex + return NilAccountIndex } func (txInfo *FullExitNftTxInfo) GetNonce() int64 { @@ -51,3 +51,7 @@ func (txInfo *FullExitNftTxInfo) GetExpiredAt() int64 { func (txInfo *FullExitNftTxInfo) Hash(hFunc hash.Hash) (msgHash []byte, err error) { return msgHash, errors.New("not support") } + +func (txInfo *FullExitNftTxInfo) GetGas() (int64, int64, *big.Int) { + return NilAccountIndex, NilAssetId, nil +} diff --git a/wasm/legend/legendTxTypes/interface.go b/wasm/txtypes/interface.go similarity index 73% rename from wasm/legend/legendTxTypes/interface.go rename to wasm/txtypes/interface.go index b67337c58..7493b53f1 100644 --- a/wasm/legend/legendTxTypes/interface.go +++ b/wasm/txtypes/interface.go @@ -1,6 +1,9 @@ -package legendTxTypes +package txtypes -import "hash" +import ( + "hash" + "math/big" +) type TxInfo interface { GetTxType() int @@ -16,4 +19,6 @@ type TxInfo interface { GetExpiredAt() int64 Hash(hFunc hash.Hash) (msgHash []byte, err error) + + GetGas() (int64, int64, *big.Int) } diff --git a/wasm/legend/legendTxTypes/mintNftTypes.go b/wasm/txtypes/mint_nft.go similarity index 97% rename from wasm/legend/legendTxTypes/mintNftTypes.go rename to wasm/txtypes/mint_nft.go index 4c801f62b..2b518d83c 100644 --- a/wasm/legend/legendTxTypes/mintNftTypes.go +++ b/wasm/txtypes/mint_nft.go @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Zecrey Protocol + * Copyright © 2022 ZkBNB Protocol * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,7 +15,7 @@ * */ -package legendTxTypes +package txtypes import ( "bytes" @@ -47,9 +47,6 @@ type MintNftSegmentFormat struct { Nonce int64 `json:"nonce"` } -/* - ConstructMintNftTxInfo: construct mint nft tx, sign txInfo -*/ func ConstructMintNftTxInfo(sk *PrivateKey, segmentStr string) (txInfo *MintNftTxInfo, err error) { var segmentFormat *MintNftSegmentFormat err = json.Unmarshal([]byte(segmentStr), &segmentFormat) @@ -254,3 +251,7 @@ func (txInfo *MintNftTxInfo) Hash(hFunc hash.Hash) (msgHash []byte, err error) { msgHash = hFunc.Sum(nil) return msgHash, nil } + +func (txInfo *MintNftTxInfo) GetGas() (int64, int64, *big.Int) { + return txInfo.GasAccountIndex, txInfo.GasFeeAssetId, txInfo.GasFeeAssetAmount +} diff --git a/wasm/legend/legendTxTypes/mintNftTypes_test.go b/wasm/txtypes/mint_nft_test.go similarity index 99% rename from wasm/legend/legendTxTypes/mintNftTypes_test.go rename to wasm/txtypes/mint_nft_test.go index 662525695..913ea4b80 100644 --- a/wasm/legend/legendTxTypes/mintNftTypes_test.go +++ b/wasm/txtypes/mint_nft_test.go @@ -1,4 +1,4 @@ -package legendTxTypes +package txtypes import ( "bytes" @@ -232,7 +232,7 @@ func TestValidateMintNftTxInfo(t *testing.T) { GasFeeAssetId: 3, GasFeeAssetAmount: big.NewInt(100), ExpiredAt: time.Now().Add(time.Hour).UnixMilli(), - Nonce: 0, + Nonce: -1, }, }, // true diff --git a/wasm/legend/legendTxTypes/offerTypes.go b/wasm/txtypes/offer.go similarity index 97% rename from wasm/legend/legendTxTypes/offerTypes.go rename to wasm/txtypes/offer.go index 199301090..770de53fd 100644 --- a/wasm/legend/legendTxTypes/offerTypes.go +++ b/wasm/txtypes/offer.go @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Zecrey Protocol + * Copyright © 2022 ZkBNB Protocol * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,7 +15,7 @@ * */ -package legendTxTypes +package txtypes import ( "bytes" @@ -46,9 +46,6 @@ type OfferSegmentFormat struct { TreasuryRate int64 `json:"treasury_rate"` } -/* - ConstructOfferTxInfo: construct offer tx, sign txInfo -*/ func ConstructOfferTxInfo(sk *PrivateKey, segmentStr string) (txInfo *OfferTxInfo, err error) { var segmentFormat *OfferSegmentFormat err = json.Unmarshal([]byte(segmentStr), &segmentFormat) @@ -227,3 +224,7 @@ func (txInfo *OfferTxInfo) Hash(hFunc hash.Hash) (msgHash []byte, err error) { msgHash = hFunc.Sum(nil) return msgHash, nil } + +func (txInfo *OfferTxInfo) GetGas() (int64, int64, *big.Int) { + return NilAccountIndex, NilAssetId, nil +} diff --git a/wasm/legend/legendTxTypes/offerTypes_test.go b/wasm/txtypes/offer_test.go similarity index 96% rename from wasm/legend/legendTxTypes/offerTypes_test.go rename to wasm/txtypes/offer_test.go index ee820c529..fe463089d 100644 --- a/wasm/legend/legendTxTypes/offerTypes_test.go +++ b/wasm/txtypes/offer_test.go @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Zecrey Protocol + * Copyright © 2022 ZkBNB Protocol * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,7 +15,7 @@ * */ -package legendTxTypes +package txtypes import ( "fmt" @@ -115,7 +115,7 @@ func TestValidateOfferTxInfo(t *testing.T) { }, }, { - fmt.Errorf("AssetAmount should not be less than %s", minAssetAmount.String()), + fmt.Errorf("AssetAmount should be larger than %s", minAssetAmount.String()), &OfferTxInfo{ Type: 1, OfferId: 1, diff --git a/wasm/legend/legendTxTypes/registerZnsTypes.go b/wasm/txtypes/register_zns.go similarity index 82% rename from wasm/legend/legendTxTypes/registerZnsTypes.go rename to wasm/txtypes/register_zns.go index fb34e6cd1..a4040c44a 100644 --- a/wasm/legend/legendTxTypes/registerZnsTypes.go +++ b/wasm/txtypes/register_zns.go @@ -1,8 +1,9 @@ -package legendTxTypes +package txtypes import ( "errors" "hash" + "math/big" ) type RegisterZnsTxInfo struct { @@ -28,7 +29,7 @@ func (txInfo *RegisterZnsTxInfo) VerifySignature(pubKey string) error { } func (txInfo *RegisterZnsTxInfo) GetFromAccountIndex() int64 { - return NilTxAccountIndex + return NilAccountIndex } func (txInfo *RegisterZnsTxInfo) GetNonce() int64 { @@ -42,3 +43,7 @@ func (txInfo *RegisterZnsTxInfo) GetExpiredAt() int64 { func (txInfo *RegisterZnsTxInfo) Hash(hFunc hash.Hash) (msgHash []byte, err error) { return msgHash, errors.New("not support") } + +func (txInfo *RegisterZnsTxInfo) GetGas() (int64, int64, *big.Int) { + return NilAccountIndex, NilAssetId, nil +} diff --git a/wasm/legend/legendTxTypes/removeLiquidityTypes.go b/wasm/txtypes/remove_liquidity.go similarity index 97% rename from wasm/legend/legendTxTypes/removeLiquidityTypes.go rename to wasm/txtypes/remove_liquidity.go index 3c373a5ce..a9bb2e318 100644 --- a/wasm/legend/legendTxTypes/removeLiquidityTypes.go +++ b/wasm/txtypes/remove_liquidity.go @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Zecrey Protocol + * Copyright © 2022 ZkBNB Protocol * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,7 +15,7 @@ * */ -package legendTxTypes +package txtypes import ( "bytes" @@ -298,3 +298,7 @@ func (txInfo *RemoveLiquidityTxInfo) Hash(hFunc hash.Hash) (msgHash []byte, err msgHash = hFunc.Sum(nil) return msgHash, nil } + +func (txInfo *RemoveLiquidityTxInfo) GetGas() (int64, int64, *big.Int) { + return txInfo.GasAccountIndex, txInfo.GasFeeAssetId, txInfo.GasFeeAssetAmount +} diff --git a/wasm/legend/legendTxTypes/removeLiquidityTypes_test.go b/wasm/txtypes/remove_liquidity_test.go similarity index 99% rename from wasm/legend/legendTxTypes/removeLiquidityTypes_test.go rename to wasm/txtypes/remove_liquidity_test.go index 5d02d00f5..a70b413c8 100644 --- a/wasm/legend/legendTxTypes/removeLiquidityTypes_test.go +++ b/wasm/txtypes/remove_liquidity_test.go @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Zecrey Protocol + * Copyright © 2022 ZkBNB Protocol * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,7 +15,7 @@ * */ -package legendTxTypes +package txtypes import ( "fmt" @@ -287,6 +287,7 @@ func TestValidateRemoveLiquidityTxInfo(t *testing.T) { GasFeeAssetId: 3, GasFeeAssetAmount: big.NewInt(1), ExpiredAt: time.Now().Add(time.Hour).UnixMilli(), + Nonce: -1, }, }, // true diff --git a/wasm/legend/legendTxTypes/swapTypes.go b/wasm/txtypes/swap.go similarity index 97% rename from wasm/legend/legendTxTypes/swapTypes.go rename to wasm/txtypes/swap.go index f3ba336bc..b88da99ec 100644 --- a/wasm/legend/legendTxTypes/swapTypes.go +++ b/wasm/txtypes/swap.go @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Zecrey Protocol + * Copyright © 2022 ZkBNB Protocol * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,7 +15,7 @@ * */ -package legendTxTypes +package txtypes import ( "bytes" @@ -267,7 +267,7 @@ func (txInfo *SwapTxInfo) Hash(hFunc hash.Hash) (msgHash []byte, err error) { WriteInt64IntoBuf(&buf, packedBAmount) WriteInt64IntoBuf(&buf, txInfo.GasAccountIndex) WriteInt64IntoBuf(&buf, txInfo.GasFeeAssetId) - WriteInt64IntoBuf(&buf, int64(packedFee)) + WriteInt64IntoBuf(&buf, packedFee) WriteInt64IntoBuf(&buf, txInfo.ExpiredAt) WriteInt64IntoBuf(&buf, txInfo.Nonce) WriteInt64IntoBuf(&buf, ChainId) @@ -275,3 +275,7 @@ func (txInfo *SwapTxInfo) Hash(hFunc hash.Hash) (msgHash []byte, err error) { msgHash = hFunc.Sum(nil) return msgHash, nil } + +func (txInfo *SwapTxInfo) GetGas() (int64, int64, *big.Int) { + return txInfo.GasAccountIndex, txInfo.GasFeeAssetId, txInfo.GasFeeAssetAmount +} diff --git a/wasm/legend/legendTxTypes/swapTypes_test.go b/wasm/txtypes/swap_test.go similarity index 88% rename from wasm/legend/legendTxTypes/swapTypes_test.go rename to wasm/txtypes/swap_test.go index 61fd7f795..de7bdf5cc 100644 --- a/wasm/legend/legendTxTypes/swapTypes_test.go +++ b/wasm/txtypes/swap_test.go @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Zecrey Protocol + * Copyright © 2022 ZkBNB Protocol * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,7 +15,7 @@ * */ -package legendTxTypes +package txtypes import ( "fmt" @@ -157,42 +157,6 @@ func TestValidateSwapTxInfo(t *testing.T) { AssetBMinAmount: big.NewInt(0).Add(maxAssetAmount, big.NewInt(1)), }, }, - // AssetBAmountDelta - { - fmt.Errorf("AssetBAmountDelta should not be nil"), - &SwapTxInfo{ - FromAccountIndex: 1, - PairIndex: 1, - AssetAId: 1, - AssetAAmount: big.NewInt(1), - AssetBId: 1, - AssetBMinAmount: big.NewInt(1), - }, - }, - { - fmt.Errorf("AssetBAmountDelta should not be less than %s", minAssetAmount.String()), - &SwapTxInfo{ - FromAccountIndex: 1, - PairIndex: 1, - AssetAId: 1, - AssetAAmount: big.NewInt(1), - AssetBId: 1, - AssetBMinAmount: big.NewInt(1), - AssetBAmountDelta: big.NewInt(-1), - }, - }, - { - fmt.Errorf("AssetBAmountDelta should not be larger than %s", maxAssetAmount.String()), - &SwapTxInfo{ - FromAccountIndex: 1, - PairIndex: 1, - AssetAId: 1, - AssetAAmount: big.NewInt(1), - AssetBId: 1, - AssetBMinAmount: big.NewInt(1), - AssetBAmountDelta: big.NewInt(0).Add(maxAssetAmount, big.NewInt(1)), - }, - }, // GasAccountIndex { fmt.Errorf("GasAccountIndex should not be less than %d", minAccountIndex), @@ -309,6 +273,7 @@ func TestValidateSwapTxInfo(t *testing.T) { GasFeeAssetId: 3, GasFeeAssetAmount: big.NewInt(1), ExpiredAt: time.Now().Add(time.Hour).UnixMilli(), + Nonce: -1, }, }, // true diff --git a/wasm/legend/legendTxTypes/transferTypes.go b/wasm/txtypes/transfer.go similarity index 97% rename from wasm/legend/legendTxTypes/transferTypes.go rename to wasm/txtypes/transfer.go index 700c4f588..1b1dcd938 100644 --- a/wasm/legend/legendTxTypes/transferTypes.go +++ b/wasm/txtypes/transfer.go @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Zecrey Protocol + * Copyright © 2022 ZkBNB Protocol * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,7 +15,7 @@ * */ -package legendTxTypes +package txtypes import ( "bytes" @@ -49,9 +49,6 @@ type TransferSegmentFormat struct { Nonce int64 `json:"nonce"` } -/* - ConstructTransferTxInfo: construct generic transfer tx, sign txInfo -*/ func ConstructTransferTxInfo(sk *PrivateKey, segmentStr string) (txInfo *TransferTxInfo, err error) { var segmentFormat *TransferSegmentFormat err = json.Unmarshal([]byte(segmentStr), &segmentFormat) @@ -259,7 +256,7 @@ func (txInfo *TransferTxInfo) Hash(hFunc hash.Hash) (msgHash []byte, err error) WriteInt64IntoBuf(&buf, packedAmount) WriteInt64IntoBuf(&buf, txInfo.GasAccountIndex) WriteInt64IntoBuf(&buf, txInfo.GasFeeAssetId) - WriteInt64IntoBuf(&buf, int64(packedFee)) + WriteInt64IntoBuf(&buf, packedFee) buf.Write(ffmath.Mod(new(big.Int).SetBytes(txInfo.CallDataHash), curve.Modulus).FillBytes(make([]byte, 32))) WriteInt64IntoBuf(&buf, txInfo.ExpiredAt) WriteInt64IntoBuf(&buf, txInfo.Nonce) @@ -268,3 +265,7 @@ func (txInfo *TransferTxInfo) Hash(hFunc hash.Hash) (msgHash []byte, err error) msgHash = hFunc.Sum(nil) return msgHash, nil } + +func (txInfo *TransferTxInfo) GetGas() (int64, int64, *big.Int) { + return txInfo.GasAccountIndex, txInfo.GasFeeAssetId, txInfo.GasFeeAssetAmount +} diff --git a/wasm/legend/legendTxTypes/transferNftTypes.go b/wasm/txtypes/transfer_nft.go similarity index 97% rename from wasm/legend/legendTxTypes/transferNftTypes.go rename to wasm/txtypes/transfer_nft.go index 55b888392..4392bab67 100644 --- a/wasm/legend/legendTxTypes/transferNftTypes.go +++ b/wasm/txtypes/transfer_nft.go @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Zecrey Protocol + * Copyright © 2022 ZkBNB Protocol * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,7 +15,7 @@ * */ -package legendTxTypes +package txtypes import ( "bytes" @@ -47,9 +47,6 @@ type TransferNftSegmentFormat struct { Nonce int64 `json:"nonce"` } -/* - ConstructTransferNftTxInfo: construct transfer nft tx, sign txInfo -*/ func ConstructTransferNftTxInfo(sk *PrivateKey, segmentStr string) (txInfo *TransferNftTxInfo, err error) { var segmentFormat *TransferNftSegmentFormat err = json.Unmarshal([]byte(segmentStr), &segmentFormat) @@ -245,3 +242,7 @@ func (txInfo *TransferNftTxInfo) Hash(hFunc hash.Hash) (msgHash []byte, err erro msgHash = hFunc.Sum(nil) return msgHash, nil } + +func (txInfo *TransferNftTxInfo) GetGas() (int64, int64, *big.Int) { + return txInfo.GasAccountIndex, txInfo.GasFeeAssetId, txInfo.GasFeeAssetAmount +} diff --git a/wasm/legend/legendTxTypes/transferNftTypes_test.go b/wasm/txtypes/transfer_nft_test.go similarity index 98% rename from wasm/legend/legendTxTypes/transferNftTypes_test.go rename to wasm/txtypes/transfer_nft_test.go index 20387f4fe..00b89d14b 100644 --- a/wasm/legend/legendTxTypes/transferNftTypes_test.go +++ b/wasm/txtypes/transfer_nft_test.go @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Zecrey Protocol + * Copyright © 2022 ZkBNB Protocol * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,7 +15,7 @@ * */ -package legendTxTypes +package txtypes import ( "bytes" @@ -214,7 +214,7 @@ func TestValidateTransferNftTxInfo(t *testing.T) { GasFeeAssetAmount: big.NewInt(100), CallDataHash: bytes.Repeat([]byte{1}, 32), ExpiredAt: time.Now().Add(time.Hour).UnixMilli(), - Nonce: 0, + Nonce: -1, }, }, } diff --git a/wasm/legend/legendTxTypes/transferTypes_test.go b/wasm/txtypes/transfer_test.go similarity index 98% rename from wasm/legend/legendTxTypes/transferTypes_test.go rename to wasm/txtypes/transfer_test.go index 6479935b4..879ed66f4 100644 --- a/wasm/legend/legendTxTypes/transferTypes_test.go +++ b/wasm/txtypes/transfer_test.go @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Zecrey Protocol + * Copyright © 2022 ZkBNB Protocol * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,7 +15,7 @@ * */ -package legendTxTypes +package txtypes import ( "bytes" @@ -196,7 +196,7 @@ func TestValidateTransferTxInfo(t *testing.T) { GasFeeAssetId: 3, GasFeeAssetAmount: big.NewInt(100), ExpiredAt: time.Now().Add(time.Hour).UnixMilli(), - Nonce: 0, + Nonce: -1, }, }, // ToAccountNameHash diff --git a/wasm/legend/legendTxTypes/updatePairRateTypes.go b/wasm/txtypes/update_pair_rate.go similarity index 83% rename from wasm/legend/legendTxTypes/updatePairRateTypes.go rename to wasm/txtypes/update_pair_rate.go index a5f60bfda..13740ab4f 100644 --- a/wasm/legend/legendTxTypes/updatePairRateTypes.go +++ b/wasm/txtypes/update_pair_rate.go @@ -1,8 +1,9 @@ -package legendTxTypes +package txtypes import ( "errors" "hash" + "math/big" ) type UpdatePairRateTxInfo struct { @@ -28,7 +29,7 @@ func (txInfo *UpdatePairRateTxInfo) VerifySignature(pubKey string) error { } func (txInfo *UpdatePairRateTxInfo) GetFromAccountIndex() int64 { - return NilTxAccountIndex + return NilAccountIndex } func (txInfo *UpdatePairRateTxInfo) GetNonce() int64 { @@ -42,3 +43,7 @@ func (txInfo *UpdatePairRateTxInfo) GetExpiredAt() int64 { func (txInfo *UpdatePairRateTxInfo) Hash(hFunc hash.Hash) (msgHash []byte, err error) { return msgHash, errors.New("not support") } + +func (txInfo *UpdatePairRateTxInfo) GetGas() (int64, int64, *big.Int) { + return NilAccountIndex, NilAssetId, nil +} diff --git a/wasm/legend/legendTxTypes/utils.go b/wasm/txtypes/utils.go similarity index 98% rename from wasm/legend/legendTxTypes/utils.go rename to wasm/txtypes/utils.go index 851a75e09..02613ad1f 100644 --- a/wasm/legend/legendTxTypes/utils.go +++ b/wasm/txtypes/utils.go @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Zecrey Protocol + * Copyright © 2022 ZkBNB Protocol * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,7 +15,7 @@ * */ -package legendTxTypes +package txtypes import ( "bytes" diff --git a/wasm/legend/legendTxTypes/withdrawTypes.go b/wasm/txtypes/withdraw.go similarity index 97% rename from wasm/legend/legendTxTypes/withdrawTypes.go rename to wasm/txtypes/withdraw.go index 3fc3843f6..f2349a0c0 100644 --- a/wasm/legend/legendTxTypes/withdrawTypes.go +++ b/wasm/txtypes/withdraw.go @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Zecrey Protocol + * Copyright © 2022 ZkBNB Protocol * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,7 +15,7 @@ * */ -package legendTxTypes +package txtypes import ( "bytes" @@ -227,3 +227,7 @@ func (txInfo *WithdrawTxInfo) Hash(hFunc hash.Hash) (msgHash []byte, err error) msgHash = hFunc.Sum(nil) return msgHash, nil } + +func (txInfo *WithdrawTxInfo) GetGas() (int64, int64, *big.Int) { + return txInfo.GasAccountIndex, txInfo.GasFeeAssetId, txInfo.GasFeeAssetAmount +} diff --git a/wasm/legend/legendTxTypes/withdrawNftTypes.go b/wasm/txtypes/withdraw_nft.go similarity index 96% rename from wasm/legend/legendTxTypes/withdrawNftTypes.go rename to wasm/txtypes/withdraw_nft.go index 996f889c6..c1c58a6dd 100644 --- a/wasm/legend/legendTxTypes/withdrawNftTypes.go +++ b/wasm/txtypes/withdraw_nft.go @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Zecrey Protocol + * Copyright © 2022 ZkBNB Protocol * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,7 +15,7 @@ * */ -package legendTxTypes +package txtypes import ( "bytes" @@ -220,3 +220,7 @@ func (txInfo *WithdrawNftTxInfo) Hash(hFunc hash.Hash) (msgHash []byte, err erro msgHash = hFunc.Sum(nil) return msgHash, nil } + +func (txInfo *WithdrawNftTxInfo) GetGas() (int64, int64, *big.Int) { + return txInfo.GasAccountIndex, txInfo.GasFeeAssetId, txInfo.GasFeeAssetAmount +} diff --git a/wasm/legend/legendTxTypes/withdrawNftTypes_test.go b/wasm/txtypes/withdraw_nft_test.go similarity index 99% rename from wasm/legend/legendTxTypes/withdrawNftTypes_test.go rename to wasm/txtypes/withdraw_nft_test.go index e38c2590e..22561e937 100644 --- a/wasm/legend/legendTxTypes/withdrawNftTypes_test.go +++ b/wasm/txtypes/withdraw_nft_test.go @@ -1,4 +1,4 @@ -package legendTxTypes +package txtypes import ( "bytes" @@ -194,7 +194,7 @@ func TestValidateWithdrawNftTxInfo(t *testing.T) { GasFeeAssetId: 3, GasFeeAssetAmount: big.NewInt(100), ExpiredAt: time.Now().Add(time.Hour).UnixMilli(), - Nonce: 0, + Nonce: -1, }, }, // true diff --git a/wasm/legend/legendTxTypes/withdrawTypes_test.go b/wasm/txtypes/withdraw_test.go similarity index 96% rename from wasm/legend/legendTxTypes/withdrawTypes_test.go rename to wasm/txtypes/withdraw_test.go index d31d18556..1ef342d93 100644 --- a/wasm/legend/legendTxTypes/withdrawTypes_test.go +++ b/wasm/txtypes/withdraw_test.go @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Zecrey Protocol + * Copyright © 2022 ZkBNB Protocol * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,7 +15,7 @@ * */ -package legendTxTypes +package txtypes import ( "fmt" @@ -68,7 +68,7 @@ func TestValidateWithdrawTxInfo(t *testing.T) { }, }, { - fmt.Errorf("AssetAmount should not be less than %s", minAssetAmount.String()), + fmt.Errorf("AssetAmount should be larger than %s", minAssetAmount.String()), &WithdrawTxInfo{ FromAccountIndex: 1, AssetId: 1, @@ -168,7 +168,7 @@ func TestValidateWithdrawTxInfo(t *testing.T) { ToAddress: "0x299d17c8b4e9967385dc9a3bb78f2a43f5a13bd0", GasFeeAssetAmount: big.NewInt(100), ExpiredAt: time.Now().Add(time.Hour).UnixMilli(), - Nonce: 0, + Nonce: -1, }, }, // ToAddress