Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add protocol account (#3) #5

Merged
merged 1 commit into from
Mar 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions circuit/asset_delta.go
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,15 @@ func GetAssetDeltasAndNftDeltaFromAtomicMatch(
},
EmptyAccountAssetDeltaConstraints(),
}
// protocol account
deltas[6] = [NbAccountAssetsPerAccount]AccountAssetDeltaConstraints{
// asset A
{
BalanceDelta: txInfo.BuyOffer.ProtocolAmount,
OfferCanceledOrFinalized: types.ZeroInt,
},
EmptyAccountAssetDeltaConstraints(),
}
nftDelta = NftDeltaConstraints{
CreatorAccountIndex: nftBefore.CreatorAccountIndex,
OwnerAccountIndex: txInfo.BuyOffer.AccountIndex,
Expand All @@ -429,13 +438,13 @@ func GetAssetDeltasAndNftDeltaFromAtomicMatch(
NftContentType: nftBefore.NftContentType,
}

gasDeltas[0].AssetId = txInfo.BuyOffer.AssetId
gasDeltas[0].BalanceDelta = txInfo.BuyOffer.ProtocolAmount
//gasDeltas[0].AssetId = txInfo.BuyOffer.AssetId
//gasDeltas[0].BalanceDelta = txInfo.BuyOffer.ProtocolAmount

gasDeltas[1].AssetId = txInfo.GasFeeAssetId
gasDeltas[1].BalanceDelta = txInfo.GasFeeAssetAmount
gasDeltas[0].AssetId = txInfo.GasFeeAssetId
gasDeltas[0].BalanceDelta = txInfo.GasFeeAssetAmount

for i := 2; i < NbGasAssetsPerTx; i++ {
for i := 1; i < NbGasAssetsPerTx; i++ {
gasDeltas[i] = EmptyGasDeltaConstraints(txInfo.GasFeeAssetId)
}

Expand Down
1 change: 1 addition & 0 deletions circuit/tx_constraints.go
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,7 @@ func EmptyTx(stateRoot []byte) (oTx *Tx) {
types.EmptyAccount(0, make([]byte, 32)),
types.EmptyAccount(0, make([]byte, 32)),
types.EmptyAccount(0, make([]byte, 32)),
types.EmptyAccount(0, make([]byte, 32)),
},
NftRootBefore: make([]byte, 32),
NftBefore: types.EmptyNft(0),
Expand Down
80 changes: 44 additions & 36 deletions circuit/types/atomic_match.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,40 +22,43 @@ import (
)

type AtomicMatchTx struct {
AccountIndex int64
BuyOffer *OfferTx
SellOffer *OfferTx
RoyaltyAmount int64
GasAccountIndex int64
GasFeeAssetId int64
GasFeeAssetAmount int64
BuyChanelAmount int64
SellChanelAmount int64
AccountIndex int64
BuyOffer *OfferTx
SellOffer *OfferTx
RoyaltyAmount int64
GasAccountIndex int64
GasFeeAssetId int64
GasFeeAssetAmount int64
BuyChanelAmount int64
SellChanelAmount int64
ProtocolAccountIndex int64
}

type AtomicMatchTxConstraints struct {
AccountIndex Variable
BuyOffer OfferTxConstraints
SellOffer OfferTxConstraints
RoyaltyAmount Variable
GasAccountIndex Variable
GasFeeAssetId Variable
GasFeeAssetAmount Variable
BuyChanelAmount Variable
SellChanelAmount Variable
AccountIndex Variable
BuyOffer OfferTxConstraints
SellOffer OfferTxConstraints
RoyaltyAmount Variable
GasAccountIndex Variable
GasFeeAssetId Variable
GasFeeAssetAmount Variable
BuyChanelAmount Variable
SellChanelAmount Variable
ProtocolAccountIndex Variable
}

func EmptyAtomicMatchTxWitness() (witness AtomicMatchTxConstraints) {
return AtomicMatchTxConstraints{
AccountIndex: ZeroInt,
BuyOffer: EmptyOfferTxWitness(),
SellOffer: EmptyOfferTxWitness(),
RoyaltyAmount: ZeroInt,
GasAccountIndex: ZeroInt,
GasFeeAssetId: ZeroInt,
GasFeeAssetAmount: ZeroInt,
BuyChanelAmount: ZeroInt,
SellChanelAmount: ZeroInt,
AccountIndex: ZeroInt,
BuyOffer: EmptyOfferTxWitness(),
SellOffer: EmptyOfferTxWitness(),
RoyaltyAmount: ZeroInt,
GasAccountIndex: ZeroInt,
GasFeeAssetId: ZeroInt,
GasFeeAssetAmount: ZeroInt,
BuyChanelAmount: ZeroInt,
SellChanelAmount: ZeroInt,
ProtocolAccountIndex: ZeroInt,
}
}

Expand All @@ -77,15 +80,16 @@ func ComputeHashFromSellOfferTx(api API, tx OfferTxConstraints) (hashVal Variabl

func SetAtomicMatchTxWitness(tx *AtomicMatchTx) (witness AtomicMatchTxConstraints) {
witness = AtomicMatchTxConstraints{
AccountIndex: tx.AccountIndex,
BuyOffer: SetOfferTxWitness(tx.BuyOffer),
SellOffer: SetOfferTxWitness(tx.SellOffer),
RoyaltyAmount: tx.RoyaltyAmount,
GasAccountIndex: tx.GasAccountIndex,
GasFeeAssetId: tx.GasFeeAssetId,
GasFeeAssetAmount: tx.GasFeeAssetAmount,
BuyChanelAmount: tx.BuyChanelAmount,
SellChanelAmount: tx.SellChanelAmount,
AccountIndex: tx.AccountIndex,
BuyOffer: SetOfferTxWitness(tx.BuyOffer),
SellOffer: SetOfferTxWitness(tx.SellOffer),
RoyaltyAmount: tx.RoyaltyAmount,
GasAccountIndex: tx.GasAccountIndex,
GasFeeAssetId: tx.GasFeeAssetId,
GasFeeAssetAmount: tx.GasFeeAssetAmount,
BuyChanelAmount: tx.BuyChanelAmount,
SellChanelAmount: tx.SellChanelAmount,
ProtocolAccountIndex: tx.ProtocolAccountIndex,
}
return witness
}
Expand Down Expand Up @@ -134,6 +138,7 @@ func VerifyAtomicMatchTx(
creatorAccount := 3
buyChanelAccount := 4
sellChanelAccount := 5
protocolAccount := 6

pubData = CollectPubDataFromAtomicMatch(api, *tx)
// verify params
Expand All @@ -146,6 +151,7 @@ func VerifyAtomicMatchTx(
IsVariableEqual(api, flag, tx.BuyOffer.AssetId, accountsBefore[creatorAccount].AssetsInfo[0].AssetId)
IsVariableEqual(api, flag, tx.BuyOffer.AssetId, accountsBefore[buyChanelAccount].AssetsInfo[0].AssetId)
IsVariableEqual(api, flag, tx.BuyOffer.AssetId, accountsBefore[sellChanelAccount].AssetsInfo[0].AssetId)
IsVariableEqual(api, flag, tx.BuyOffer.AssetId, accountsBefore[protocolAccount].AssetsInfo[0].AssetId)
IsVariableEqual(api, flag, tx.SellOffer.AssetId, accountsBefore[sellAccount].AssetsInfo[0].AssetId)
IsVariableEqual(api, flag, tx.GasFeeAssetId, accountsBefore[fromAccount].AssetsInfo[0].AssetId)
IsVariableLessOrEqual(api, flag, blockCreatedAt, tx.BuyOffer.ExpiredAt)
Expand Down Expand Up @@ -185,6 +191,8 @@ func VerifyAtomicMatchTx(
IsVariableEqual(api, flag, tx.BuyOffer.ChanelAccountIndex, accountsBefore[buyChanelAccount].AccountIndex)
// sellChanelAccount
IsVariableEqual(api, flag, tx.SellOffer.ChanelAccountIndex, accountsBefore[sellChanelAccount].AccountIndex)
// sellChanelAccount
IsVariableEqual(api, flag, tx.ProtocolAccountIndex, accountsBefore[protocolAccount].AccountIndex)

// verify buy offer id
buyOfferIdBits := api.ToBinary(tx.BuyOffer.OfferId, 24)
Expand Down
2 changes: 1 addition & 1 deletion circuit/types/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const (
DefaultInt = int64(-1)

NbAccountAssetsPerAccount = 2
NbAccountsPerTx = 6
NbAccountsPerTx = 7
NbGasAssetsPerTx = 2 // at most two assets transferred to gas account

NbRoots = 2 // account root, nft root
Expand Down