mirror of
https://github.com/arnaucube/hermez-node.git
synced 2026-02-07 11:26:44 +01:00
Update importers of eth, use variable length feeIdxCoordinator
This commit is contained in:
@@ -22,6 +22,11 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
// RollupConstMaxFeeIdxCoordinator is the maximum number of tokens the
|
||||||
|
// coordinator can use to collect fees (determines the number of tokens
|
||||||
|
// that the coordinator can collect fees from). This value is
|
||||||
|
// determined by the circuit.
|
||||||
|
RollupConstMaxFeeIdxCoordinator = 64
|
||||||
// RollupConstReservedIDx First 256 indexes reserved, first user index will be the 256
|
// RollupConstReservedIDx First 256 indexes reserved, first user index will be the 256
|
||||||
RollupConstReservedIDx = 255
|
RollupConstReservedIDx = 255
|
||||||
// RollupConstExitIDx IDX 1 is reserved for exits
|
// RollupConstExitIDx IDX 1 is reserved for exits
|
||||||
@@ -174,7 +179,7 @@ type RollupEventForgeBatch struct {
|
|||||||
|
|
||||||
// RollupEventUpdateForgeL1L2BatchTimeout is an event of the Rollup Smart Contract
|
// RollupEventUpdateForgeL1L2BatchTimeout is an event of the Rollup Smart Contract
|
||||||
type RollupEventUpdateForgeL1L2BatchTimeout struct {
|
type RollupEventUpdateForgeL1L2BatchTimeout struct {
|
||||||
NewForgeL1L2BatchTimeout uint8
|
NewForgeL1L2BatchTimeout int64
|
||||||
}
|
}
|
||||||
|
|
||||||
// RollupEventUpdateFeeAddToken is an event of the Rollup Smart Contract
|
// RollupEventUpdateFeeAddToken is an event of the Rollup Smart Contract
|
||||||
@@ -216,9 +221,9 @@ type RollupForgeBatchArgs struct {
|
|||||||
NewLastIdx int64
|
NewLastIdx int64
|
||||||
NewStRoot *big.Int
|
NewStRoot *big.Int
|
||||||
NewExitRoot *big.Int
|
NewExitRoot *big.Int
|
||||||
L1CoordinatorTxs []*common.L1Tx
|
L1CoordinatorTxs []common.L1Tx
|
||||||
L1CoordinatorTxsAuths [][]byte // Authorization for accountCreations for each L1CoordinatorTx
|
L1CoordinatorTxsAuths [][]byte // Authorization for accountCreations for each L1CoordinatorTx
|
||||||
L2TxsData []*common.L2Tx
|
L2TxsData []common.L2Tx
|
||||||
FeeIdxCoordinator []common.Idx
|
FeeIdxCoordinator []common.Idx
|
||||||
// Circuit selector
|
// Circuit selector
|
||||||
VerifierIdx uint8
|
VerifierIdx uint8
|
||||||
@@ -262,7 +267,7 @@ type RollupInterface interface {
|
|||||||
RollupL1UserTxERC777(fromBJJ *babyjub.PublicKey, fromIdx int64, loadAmount *big.Int, amount *big.Int, tokenID uint32, toIdx int64) (*types.Transaction, error)
|
RollupL1UserTxERC777(fromBJJ *babyjub.PublicKey, fromIdx int64, loadAmount *big.Int, amount *big.Int, tokenID uint32, toIdx int64) (*types.Transaction, error)
|
||||||
|
|
||||||
// Governance Public Functions
|
// Governance Public Functions
|
||||||
RollupUpdateForgeL1L2BatchTimeout(newForgeL1L2BatchTimeout uint8) (*types.Transaction, error)
|
RollupUpdateForgeL1L2BatchTimeout(newForgeL1L2BatchTimeout int64) (*types.Transaction, error)
|
||||||
RollupUpdateFeeAddToken(newFeeAddToken *big.Int) (*types.Transaction, error)
|
RollupUpdateFeeAddToken(newFeeAddToken *big.Int) (*types.Transaction, error)
|
||||||
|
|
||||||
// Viewers
|
// Viewers
|
||||||
@@ -285,13 +290,13 @@ type RollupInterface interface {
|
|||||||
type RollupClient struct {
|
type RollupClient struct {
|
||||||
client *EthereumClient
|
client *EthereumClient
|
||||||
address ethCommon.Address
|
address ethCommon.Address
|
||||||
tokenAddress ethCommon.Address
|
tokenHEZAddress ethCommon.Address
|
||||||
gasLimit uint64
|
gasLimit uint64
|
||||||
contractAbi abi.ABI
|
contractAbi abi.ABI
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewRollupClient creates a new RollupClient
|
// NewRollupClient creates a new RollupClient
|
||||||
func NewRollupClient(client *EthereumClient, address ethCommon.Address, tokenAddress ethCommon.Address) (*RollupClient, error) {
|
func NewRollupClient(client *EthereumClient, address ethCommon.Address, tokenHEZAddress ethCommon.Address) (*RollupClient, error) {
|
||||||
contractAbi, err := abi.JSON(strings.NewReader(string(Hermez.HermezABI)))
|
contractAbi, err := abi.JSON(strings.NewReader(string(Hermez.HermezABI)))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -299,7 +304,7 @@ func NewRollupClient(client *EthereumClient, address ethCommon.Address, tokenAdd
|
|||||||
return &RollupClient{
|
return &RollupClient{
|
||||||
client: client,
|
client: client,
|
||||||
address: address,
|
address: address,
|
||||||
tokenAddress: tokenAddress,
|
tokenHEZAddress: tokenHEZAddress,
|
||||||
gasLimit: 1000000, //nolint:gomnd
|
gasLimit: 1000000, //nolint:gomnd
|
||||||
contractAbi: contractAbi,
|
contractAbi: contractAbi,
|
||||||
}, nil
|
}, nil
|
||||||
@@ -321,7 +326,7 @@ func (c *RollupClient) RollupForgeBatch(args *RollupForgeBatchArgs) (*types.Tran
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
nLevels := rollupConst.Verifiers[args.VerifierIdx].NLevels
|
nLevels := rollupConst.Verifiers[args.VerifierIdx].NLevels
|
||||||
lenBytes := nLevels / 8
|
lenBytes := nLevels / 8 //nolint:gomnd
|
||||||
newLastIdx := big.NewInt(int64(args.NewLastIdx))
|
newLastIdx := big.NewInt(int64(args.NewLastIdx))
|
||||||
var l1CoordinatorBytes []byte
|
var l1CoordinatorBytes []byte
|
||||||
for i := 0; i < len(args.L1CoordinatorTxs); i++ {
|
for i := 0; i < len(args.L1CoordinatorTxs); i++ {
|
||||||
@@ -342,8 +347,15 @@ func (c *RollupClient) RollupForgeBatch(args *RollupForgeBatchArgs) (*types.Tran
|
|||||||
l2DataBytes = append(l2DataBytes, bytesl2[:]...)
|
l2DataBytes = append(l2DataBytes, bytesl2[:]...)
|
||||||
}
|
}
|
||||||
var feeIdxCoordinator []byte
|
var feeIdxCoordinator []byte
|
||||||
for i := 0; i < len(args.FeeIdxCoordinator); i++ {
|
if len(args.FeeIdxCoordinator) > RollupConstMaxFeeIdxCoordinator {
|
||||||
feeIdx := args.FeeIdxCoordinator[i]
|
return nil, fmt.Errorf("len(args.FeeIdxCoordinator) > %v",
|
||||||
|
RollupConstMaxFeeIdxCoordinator)
|
||||||
|
}
|
||||||
|
for i := 0; i < RollupConstMaxFeeIdxCoordinator; i++ {
|
||||||
|
feeIdx := common.Idx(0)
|
||||||
|
if i < len(args.FeeIdxCoordinator) {
|
||||||
|
feeIdx = args.FeeIdxCoordinator[i]
|
||||||
|
}
|
||||||
bytesFeeIdx, err := feeIdx.Bytes()
|
bytesFeeIdx, err := feeIdx.Bytes()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -358,14 +370,16 @@ func (c *RollupClient) RollupForgeBatch(args *RollupForgeBatchArgs) (*types.Tran
|
|||||||
return tx, nil
|
return tx, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// RollupAddToken is the interface to call the smart contract function
|
// RollupAddToken is the interface to call the smart contract function.
|
||||||
|
// `feeAddToken` is the amount of HEZ tokens that will be paid to add the
|
||||||
|
// token. `feeAddToken` must match the public value of the smart contract.
|
||||||
func (c *RollupClient) RollupAddToken(tokenAddress ethCommon.Address, feeAddToken *big.Int) (*types.Transaction, error) {
|
func (c *RollupClient) RollupAddToken(tokenAddress ethCommon.Address, feeAddToken *big.Int) (*types.Transaction, error) {
|
||||||
var tx *types.Transaction
|
var tx *types.Transaction
|
||||||
var err error
|
var err error
|
||||||
if tx, err = c.client.CallAuth(
|
if tx, err = c.client.CallAuth(
|
||||||
c.gasLimit,
|
c.gasLimit,
|
||||||
func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) {
|
func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) {
|
||||||
tokens, err := ERC777.NewERC777(c.tokenAddress, ec)
|
tokens, err := ERC777.NewERC777(c.tokenHEZAddress, ec)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -440,6 +454,9 @@ func (c *RollupClient) RollupL1UserTxERC20ETH(fromBJJ *babyjub.PublicKey, fromId
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
amountF, err := common.NewFloat16(amount)
|
amountF, err := common.NewFloat16(amount)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
if tokenID == 0 {
|
if tokenID == 0 {
|
||||||
auth.Value = loadAmount
|
auth.Value = loadAmount
|
||||||
}
|
}
|
||||||
@@ -458,7 +475,7 @@ func (c *RollupClient) RollupL1UserTxERC777(fromBJJ *babyjub.PublicKey, fromIdx
|
|||||||
if tx, err = c.client.CallAuth(
|
if tx, err = c.client.CallAuth(
|
||||||
c.gasLimit,
|
c.gasLimit,
|
||||||
func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) {
|
func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) {
|
||||||
tokens, err := ERC777.NewERC777(c.tokenAddress, ec)
|
tokens, err := ERC777.NewERC777(c.tokenHEZAddress, ec)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -527,7 +544,7 @@ func (c *RollupClient) RollupRegisterTokensCount() (*big.Int, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// RollupUpdateForgeL1L2BatchTimeout is the interface to call the smart contract function
|
// RollupUpdateForgeL1L2BatchTimeout is the interface to call the smart contract function
|
||||||
func (c *RollupClient) RollupUpdateForgeL1L2BatchTimeout(newForgeL1L2BatchTimeout uint8) (*types.Transaction, error) {
|
func (c *RollupClient) RollupUpdateForgeL1L2BatchTimeout(newForgeL1L2BatchTimeout int64) (*types.Transaction, error) {
|
||||||
var tx *types.Transaction
|
var tx *types.Transaction
|
||||||
var err error
|
var err error
|
||||||
if tx, err = c.client.CallAuth(
|
if tx, err = c.client.CallAuth(
|
||||||
@@ -537,7 +554,7 @@ func (c *RollupClient) RollupUpdateForgeL1L2BatchTimeout(newForgeL1L2BatchTimeou
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return hermez.UpdateForgeL1L2BatchTimeout(auth, newForgeL1L2BatchTimeout)
|
return hermez.UpdateForgeL1L2BatchTimeout(auth, uint8(newForgeL1L2BatchTimeout))
|
||||||
},
|
},
|
||||||
); err != nil {
|
); err != nil {
|
||||||
return nil, fmt.Errorf("Failed update ForgeL1L2BatchTimeout: %w", err)
|
return nil, fmt.Errorf("Failed update ForgeL1L2BatchTimeout: %w", err)
|
||||||
@@ -651,12 +668,10 @@ func (c *RollupClient) RollupEventsByBlock(blockNum int64) (*RollupEvents, *ethC
|
|||||||
var L1UserTx RollupEventL1UserTx
|
var L1UserTx RollupEventL1UserTx
|
||||||
err := c.contractAbi.Unpack(&L1UserTxAux, "L1UserTxEvent", vLog.Data)
|
err := c.contractAbi.Unpack(&L1UserTxAux, "L1UserTxEvent", vLog.Data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
L1Tx, err := common.L1TxFromBytes(L1UserTxAux.L1UserTx)
|
L1Tx, err := common.L1TxFromBytes(L1UserTxAux.L1UserTx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
L1UserTx.ToForgeL1TxsNum = new(big.Int).SetBytes(vLog.Topics[1][:]).Int64()
|
L1UserTx.ToForgeL1TxsNum = new(big.Int).SetBytes(vLog.Topics[1][:]).Int64()
|
||||||
@@ -677,12 +692,17 @@ func (c *RollupClient) RollupEventsByBlock(blockNum int64) (*RollupEvents, *ethC
|
|||||||
forgeBatch.EthTxHash = vLog.TxHash
|
forgeBatch.EthTxHash = vLog.TxHash
|
||||||
rollupEvents.ForgeBatch = append(rollupEvents.ForgeBatch, forgeBatch)
|
rollupEvents.ForgeBatch = append(rollupEvents.ForgeBatch, forgeBatch)
|
||||||
case logHermezUpdateForgeL1L2BatchTimeout:
|
case logHermezUpdateForgeL1L2BatchTimeout:
|
||||||
var updateForgeL1L2BatchTimeout RollupEventUpdateForgeL1L2BatchTimeout
|
var updateForgeL1L2BatchTimeout struct {
|
||||||
|
NewForgeL1L2BatchTimeout uint8
|
||||||
|
}
|
||||||
err := c.contractAbi.Unpack(&updateForgeL1L2BatchTimeout, "UpdateForgeL1L2BatchTimeout", vLog.Data)
|
err := c.contractAbi.Unpack(&updateForgeL1L2BatchTimeout, "UpdateForgeL1L2BatchTimeout", vLog.Data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
rollupEvents.UpdateForgeL1L2BatchTimeout = append(rollupEvents.UpdateForgeL1L2BatchTimeout, updateForgeL1L2BatchTimeout)
|
rollupEvents.UpdateForgeL1L2BatchTimeout = append(rollupEvents.UpdateForgeL1L2BatchTimeout,
|
||||||
|
RollupEventUpdateForgeL1L2BatchTimeout{
|
||||||
|
NewForgeL1L2BatchTimeout: int64(updateForgeL1L2BatchTimeout.NewForgeL1L2BatchTimeout),
|
||||||
|
})
|
||||||
case logHermezUpdateFeeAddToken:
|
case logHermezUpdateFeeAddToken:
|
||||||
var updateFeeAddToken RollupEventUpdateFeeAddToken
|
var updateFeeAddToken RollupEventUpdateFeeAddToken
|
||||||
err := c.contractAbi.Unpack(&updateFeeAddToken, "UpdateFeeAddToken", vLog.Data)
|
err := c.contractAbi.Unpack(&updateFeeAddToken, "UpdateFeeAddToken", vLog.Data)
|
||||||
@@ -719,15 +739,20 @@ func (c *RollupClient) RollupForgeBatchArgs(ethTxHash ethCommon.Hash) (*RollupFo
|
|||||||
if err := method.Inputs.Unpack(&aux, txData[4:]); err != nil {
|
if err := method.Inputs.Unpack(&aux, txData[4:]); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
var rollupForgeBatchArgs RollupForgeBatchArgs
|
rollupForgeBatchArgs := RollupForgeBatchArgs{
|
||||||
rollupForgeBatchArgs.L1Batch = aux.L1Batch
|
L1Batch: aux.L1Batch,
|
||||||
rollupForgeBatchArgs.NewExitRoot = aux.NewExitRoot
|
NewExitRoot: aux.NewExitRoot,
|
||||||
rollupForgeBatchArgs.NewLastIdx = aux.NewLastIdx.Int64()
|
NewLastIdx: aux.NewLastIdx.Int64(),
|
||||||
rollupForgeBatchArgs.NewStRoot = aux.NewStRoot
|
NewStRoot: aux.NewStRoot,
|
||||||
rollupForgeBatchArgs.ProofA = aux.ProofA
|
ProofA: aux.ProofA,
|
||||||
rollupForgeBatchArgs.ProofB = aux.ProofB
|
ProofB: aux.ProofB,
|
||||||
rollupForgeBatchArgs.ProofC = aux.ProofC
|
ProofC: aux.ProofC,
|
||||||
rollupForgeBatchArgs.VerifierIdx = aux.VerifierIdx
|
VerifierIdx: aux.VerifierIdx,
|
||||||
|
L1CoordinatorTxs: []common.L1Tx{},
|
||||||
|
L1CoordinatorTxsAuths: [][]byte{},
|
||||||
|
L2TxsData: []common.L2Tx{},
|
||||||
|
FeeIdxCoordinator: []common.Idx{},
|
||||||
|
}
|
||||||
numTxsL1 := len(aux.EncodedL1CoordinatorTx) / common.L1CoordinatorTxBytesLen
|
numTxsL1 := len(aux.EncodedL1CoordinatorTx) / common.L1CoordinatorTxBytesLen
|
||||||
for i := 0; i < numTxsL1; i++ {
|
for i := 0; i < numTxsL1; i++ {
|
||||||
bytesL1Coordinator := aux.EncodedL1CoordinatorTx[i*common.L1CoordinatorTxBytesLen : (i+1)*common.L1CoordinatorTxBytesLen]
|
bytesL1Coordinator := aux.EncodedL1CoordinatorTx[i*common.L1CoordinatorTxBytesLen : (i+1)*common.L1CoordinatorTxBytesLen]
|
||||||
@@ -742,7 +767,7 @@ func (c *RollupClient) RollupForgeBatchArgs(ethTxHash ethCommon.Hash) (*RollupFo
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
rollupForgeBatchArgs.L1CoordinatorTxs = append(rollupForgeBatchArgs.L1CoordinatorTxs, l1Tx)
|
rollupForgeBatchArgs.L1CoordinatorTxs = append(rollupForgeBatchArgs.L1CoordinatorTxs, *l1Tx)
|
||||||
rollupForgeBatchArgs.L1CoordinatorTxsAuths = append(rollupForgeBatchArgs.L1CoordinatorTxsAuths, signature)
|
rollupForgeBatchArgs.L1CoordinatorTxsAuths = append(rollupForgeBatchArgs.L1CoordinatorTxsAuths, signature)
|
||||||
}
|
}
|
||||||
rollupConsts, err := c.RollupConstants()
|
rollupConsts, err := c.RollupConstants()
|
||||||
@@ -757,7 +782,7 @@ func (c *RollupClient) RollupForgeBatchArgs(ethTxHash ethCommon.Hash) (*RollupFo
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
rollupForgeBatchArgs.L2TxsData = append(rollupForgeBatchArgs.L2TxsData, l2Tx)
|
rollupForgeBatchArgs.L2TxsData = append(rollupForgeBatchArgs.L2TxsData, *l2Tx)
|
||||||
}
|
}
|
||||||
lenFeeIdxCoordinatorBytes := int(nLevels / 8) //nolint:gomnd
|
lenFeeIdxCoordinatorBytes := int(nLevels / 8) //nolint:gomnd
|
||||||
numFeeIdxCoordinator := len(aux.FeeIdxCoordinator) / lenFeeIdxCoordinatorBytes
|
numFeeIdxCoordinator := len(aux.FeeIdxCoordinator) / lenFeeIdxCoordinatorBytes
|
||||||
@@ -769,11 +794,13 @@ func (c *RollupClient) RollupForgeBatchArgs(ethTxHash ethCommon.Hash) (*RollupFo
|
|||||||
} else {
|
} else {
|
||||||
copy(paddedFeeIdx[:], aux.FeeIdxCoordinator[i*lenFeeIdxCoordinatorBytes:(i+1)*lenFeeIdxCoordinatorBytes])
|
copy(paddedFeeIdx[:], aux.FeeIdxCoordinator[i*lenFeeIdxCoordinatorBytes:(i+1)*lenFeeIdxCoordinatorBytes])
|
||||||
}
|
}
|
||||||
FeeIdxCoordinator, err := common.IdxFromBytes(paddedFeeIdx[:])
|
feeIdxCoordinator, err := common.IdxFromBytes(paddedFeeIdx[:])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
rollupForgeBatchArgs.FeeIdxCoordinator = append(rollupForgeBatchArgs.FeeIdxCoordinator, FeeIdxCoordinator)
|
if feeIdxCoordinator != common.Idx(0) {
|
||||||
|
rollupForgeBatchArgs.FeeIdxCoordinator = append(rollupForgeBatchArgs.FeeIdxCoordinator, feeIdxCoordinator)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return &rollupForgeBatchArgs, nil
|
return &rollupForgeBatchArgs, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -71,8 +71,7 @@ func TestRollupRegisterTokensCount(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestAddToken(t *testing.T) {
|
func TestAddToken(t *testing.T) {
|
||||||
var feeAddToken = new(big.Int)
|
feeAddToken := big.NewInt(10)
|
||||||
feeAddToken = big.NewInt(10)
|
|
||||||
// Addtoken ERC20
|
// Addtoken ERC20
|
||||||
registerTokensCount, err := rollupClient.RollupRegisterTokensCount()
|
registerTokensCount, err := rollupClient.RollupRegisterTokensCount()
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
@@ -125,21 +124,22 @@ func TestRollupForgeBatch(t *testing.T) {
|
|||||||
|
|
||||||
// Forge
|
// Forge
|
||||||
args := new(RollupForgeBatchArgs)
|
args := new(RollupForgeBatchArgs)
|
||||||
feeIdxCoordinatorBytes, err := hex.DecodeString("00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000")
|
// feeIdxCoordinatorBytes, err := hex.DecodeString("00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000")
|
||||||
require.Nil(t, err)
|
// require.Nil(t, err)
|
||||||
lenFeeIdxCoordinatorBytes := int(4)
|
// lenFeeIdxCoordinatorBytes := int(4)
|
||||||
numFeeIdxCoordinator := len(feeIdxCoordinatorBytes) / lenFeeIdxCoordinatorBytes
|
// numFeeIdxCoordinator := len(feeIdxCoordinatorBytes) / lenFeeIdxCoordinatorBytes
|
||||||
for i := 0; i < numFeeIdxCoordinator; i++ {
|
// for i := 0; i < numFeeIdxCoordinator; i++ {
|
||||||
var paddedFeeIdx [6]byte
|
// var paddedFeeIdx [6]byte
|
||||||
if lenFeeIdxCoordinatorBytes < common.IdxBytesLen {
|
// if lenFeeIdxCoordinatorBytes < common.IdxBytesLen {
|
||||||
copy(paddedFeeIdx[6-lenFeeIdxCoordinatorBytes:], feeIdxCoordinatorBytes[i*lenFeeIdxCoordinatorBytes:(i+1)*lenFeeIdxCoordinatorBytes])
|
// copy(paddedFeeIdx[6-lenFeeIdxCoordinatorBytes:], feeIdxCoordinatorBytes[i*lenFeeIdxCoordinatorBytes:(i+1)*lenFeeIdxCoordinatorBytes])
|
||||||
} else {
|
// } else {
|
||||||
copy(paddedFeeIdx[:], feeIdxCoordinatorBytes[i*lenFeeIdxCoordinatorBytes:(i+1)*lenFeeIdxCoordinatorBytes])
|
// copy(paddedFeeIdx[:], feeIdxCoordinatorBytes[i*lenFeeIdxCoordinatorBytes:(i+1)*lenFeeIdxCoordinatorBytes])
|
||||||
}
|
// }
|
||||||
FeeIdxCoordinator, err := common.IdxFromBytes(paddedFeeIdx[:])
|
// FeeIdxCoordinator, err := common.IdxFromBytes(paddedFeeIdx[:])
|
||||||
require.Nil(t, err)
|
// require.Nil(t, err)
|
||||||
args.FeeIdxCoordinator = append(args.FeeIdxCoordinator, FeeIdxCoordinator)
|
// args.FeeIdxCoordinator = append(args.FeeIdxCoordinator, FeeIdxCoordinator)
|
||||||
}
|
// }
|
||||||
|
args.FeeIdxCoordinator = []common.Idx{} // When encoded, 64 times the 0 idx means that no idx to collect fees is specified.
|
||||||
l1CoordinatorBytes, err := hex.DecodeString("1c660323607bb113e586183609964a333d07ebe4bef3be82ec13af453bae9590bd7711cdb6abf42f176eadfbe5506fbef5e092e5543733f91b0061d9a7747fa10694a915a6470fa230de387b51e6f4db0b09787867778687b55197ad6d6a86eac000000001")
|
l1CoordinatorBytes, err := hex.DecodeString("1c660323607bb113e586183609964a333d07ebe4bef3be82ec13af453bae9590bd7711cdb6abf42f176eadfbe5506fbef5e092e5543733f91b0061d9a7747fa10694a915a6470fa230de387b51e6f4db0b09787867778687b55197ad6d6a86eac000000001")
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
numTxsL1 := len(l1CoordinatorBytes) / common.L1CoordinatorTxBytesLen
|
numTxsL1 := len(l1CoordinatorBytes) / common.L1CoordinatorTxBytesLen
|
||||||
@@ -152,11 +152,12 @@ func TestRollupForgeBatch(t *testing.T) {
|
|||||||
signature = append(signature, r[:]...)
|
signature = append(signature, r[:]...)
|
||||||
signature = append(signature, s[:]...)
|
signature = append(signature, s[:]...)
|
||||||
signature = append(signature, v)
|
signature = append(signature, v)
|
||||||
L1Tx, err := common.L1TxFromCoordinatorBytes(bytesL1Coordinator)
|
l1Tx, err := common.L1TxFromCoordinatorBytes(bytesL1Coordinator)
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
args.L1CoordinatorTxs = append(args.L1CoordinatorTxs, L1Tx)
|
args.L1CoordinatorTxs = append(args.L1CoordinatorTxs, *l1Tx)
|
||||||
args.L1CoordinatorTxsAuths = append(args.L1CoordinatorTxsAuths, signature)
|
args.L1CoordinatorTxsAuths = append(args.L1CoordinatorTxsAuths, signature)
|
||||||
}
|
}
|
||||||
|
args.L2TxsData = []common.L2Tx{}
|
||||||
newStateRoot := new(big.Int)
|
newStateRoot := new(big.Int)
|
||||||
newStateRoot.SetString("18317824016047294649053625209337295956588174734569560016974612130063629505228", 10)
|
newStateRoot.SetString("18317824016047294649053625209337295956588174734569560016974612130063629505228", 10)
|
||||||
newExitRoot := new(big.Int)
|
newExitRoot := new(big.Int)
|
||||||
@@ -202,7 +203,7 @@ func TestRollupForgeBatchArgs(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestRollupUpdateForgeL1L2BatchTimeout(t *testing.T) {
|
func TestRollupUpdateForgeL1L2BatchTimeout(t *testing.T) {
|
||||||
newForgeL1L2BatchTimeout := uint8(222)
|
newForgeL1L2BatchTimeout := int64(222)
|
||||||
_, err := rollupClient.RollupUpdateForgeL1L2BatchTimeout(newForgeL1L2BatchTimeout)
|
_, err := rollupClient.RollupUpdateForgeL1L2BatchTimeout(newForgeL1L2BatchTimeout)
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
|
|
||||||
|
|||||||
@@ -484,7 +484,7 @@ func (s *Synchronizer) rollupSync(blockNum int64) (*rollupData, error) {
|
|||||||
var token common.Token
|
var token common.Token
|
||||||
|
|
||||||
token.TokenID = common.TokenID(evtAddToken.TokenID)
|
token.TokenID = common.TokenID(evtAddToken.TokenID)
|
||||||
token.EthAddr = evtAddToken.Address
|
token.EthAddr = evtAddToken.TokenAddress
|
||||||
token.EthBlockNum = blockNum
|
token.EthBlockNum = blockNum
|
||||||
|
|
||||||
// TODO: Add external information consulting SC about it using Address
|
// TODO: Add external information consulting SC about it using Address
|
||||||
@@ -584,17 +584,17 @@ func getL1UserTx(eventsL1UserTx []eth.RollupEventL1UserTx, blockNum int64) ([]co
|
|||||||
for _, evtL1UserTx := range eventsL1UserTx {
|
for _, evtL1UserTx := range eventsL1UserTx {
|
||||||
// Fill aditional Tx fields
|
// Fill aditional Tx fields
|
||||||
toForge := evtL1UserTx.ToForgeL1TxsNum
|
toForge := evtL1UserTx.ToForgeL1TxsNum
|
||||||
evtL1UserTx.L1Tx.ToForgeL1TxsNum = &toForge
|
evtL1UserTx.L1UserTx.ToForgeL1TxsNum = &toForge
|
||||||
evtL1UserTx.L1Tx.Position = evtL1UserTx.Position
|
evtL1UserTx.L1UserTx.Position = evtL1UserTx.Position
|
||||||
evtL1UserTx.L1Tx.UserOrigin = true
|
evtL1UserTx.L1UserTx.UserOrigin = true
|
||||||
evtL1UserTx.L1Tx.EthBlockNum = blockNum
|
evtL1UserTx.L1UserTx.EthBlockNum = blockNum
|
||||||
nL1Tx, err := common.NewL1Tx(&evtL1UserTx.L1Tx)
|
nL1Tx, err := common.NewL1Tx(&evtL1UserTx.L1UserTx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
evtL1UserTx.L1Tx = *nL1Tx
|
evtL1UserTx.L1UserTx = *nL1Tx
|
||||||
|
|
||||||
l1Txs = append(l1Txs, evtL1UserTx.L1Tx)
|
l1Txs = append(l1Txs, evtL1UserTx.L1UserTx)
|
||||||
}
|
}
|
||||||
return l1Txs, nil
|
return l1Txs, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -599,12 +599,42 @@ func (c *Client) CtlAddL1TxUser(l1Tx *common.L1Tx) {
|
|||||||
}
|
}
|
||||||
queue.L1TxQueue = append(queue.L1TxQueue, *l1Tx)
|
queue.L1TxQueue = append(queue.L1TxQueue, *l1Tx)
|
||||||
r.Events.L1UserTx = append(r.Events.L1UserTx, eth.RollupEventL1UserTx{
|
r.Events.L1UserTx = append(r.Events.L1UserTx, eth.RollupEventL1UserTx{
|
||||||
L1Tx: *l1Tx,
|
L1UserTx: *l1Tx,
|
||||||
ToForgeL1TxsNum: r.State.LastToForgeL1TxsNum,
|
ToForgeL1TxsNum: r.State.LastToForgeL1TxsNum,
|
||||||
Position: len(queue.L1TxQueue) - 1,
|
Position: len(queue.L1TxQueue) - 1,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RollupL1UserTxERC20ETH is the interface to call the smart contract function
|
||||||
|
func (c *Client) RollupL1UserTxERC20ETH(fromBJJ *babyjub.PublicKey, fromIdx int64, loadAmount *big.Int, amount *big.Int, tokenID uint32, toIdx int64) (*types.Transaction, error) {
|
||||||
|
log.Error("TODO")
|
||||||
|
return nil, errTODO
|
||||||
|
}
|
||||||
|
|
||||||
|
// RollupL1UserTxERC777 is the interface to call the smart contract function
|
||||||
|
func (c *Client) RollupL1UserTxERC777(fromBJJ *babyjub.PublicKey, fromIdx int64, loadAmount *big.Int, amount *big.Int, tokenID uint32, toIdx int64) (*types.Transaction, error) {
|
||||||
|
log.Error("TODO")
|
||||||
|
return nil, errTODO
|
||||||
|
}
|
||||||
|
|
||||||
|
// RollupRegisterTokensCount is the interface to call the smart contract function
|
||||||
|
func (c *Client) RollupRegisterTokensCount() (*big.Int, error) {
|
||||||
|
log.Error("TODO")
|
||||||
|
return nil, errTODO
|
||||||
|
}
|
||||||
|
|
||||||
|
// RollupWithdrawCircuit is the interface to call the smart contract function
|
||||||
|
func (c *Client) RollupWithdrawCircuit(proofA, proofC [2]*big.Int, proofB [2][2]*big.Int, tokenID uint32, numExitRoot, idx int64, amount *big.Int, instantWithdraw bool) (*types.Transaction, error) {
|
||||||
|
log.Error("TODO")
|
||||||
|
return nil, errTODO
|
||||||
|
}
|
||||||
|
|
||||||
|
// RollupWithdrawMerkleProof is the interface to call the smart contract function
|
||||||
|
func (c *Client) RollupWithdrawMerkleProof(babyPubKey *babyjub.PublicKey, tokenID uint32, numExitRoot, idx int64, amount *big.Int, siblings []*big.Int, instantWithdraw bool) (*types.Transaction, error) {
|
||||||
|
log.Error("TODO")
|
||||||
|
return nil, errTODO
|
||||||
|
}
|
||||||
|
|
||||||
type transactionData struct {
|
type transactionData struct {
|
||||||
Name string
|
Name string
|
||||||
Value interface{}
|
Value interface{}
|
||||||
@@ -710,72 +740,11 @@ func (c *Client) RollupAddToken(tokenAddress ethCommon.Address, feeAddToken *big
|
|||||||
|
|
||||||
r.State.TokenMap[tokenAddress] = true
|
r.State.TokenMap[tokenAddress] = true
|
||||||
r.State.TokenList = append(r.State.TokenList, tokenAddress)
|
r.State.TokenList = append(r.State.TokenList, tokenAddress)
|
||||||
r.Events.AddToken = append(r.Events.AddToken, eth.RollupEventAddToken{Address: tokenAddress,
|
r.Events.AddToken = append(r.Events.AddToken, eth.RollupEventAddToken{TokenAddress: tokenAddress,
|
||||||
TokenID: uint32(len(r.State.TokenList) - 1)})
|
TokenID: uint32(len(r.State.TokenList) - 1)})
|
||||||
return r.addTransaction(newTransaction("addtoken", tokenAddress)), nil
|
return r.addTransaction(newTransaction("addtoken", tokenAddress)), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// RollupWithdrawSNARK is the interface to call the smart contract function
|
|
||||||
// func (c *Client) RollupWithdrawSNARK() (*types.Transaction, error) { // TODO (Not defined in Hermez.sol)
|
|
||||||
// return nil, errTODO
|
|
||||||
// }
|
|
||||||
|
|
||||||
// RollupWithdraw is the interface to call the smart contract function
|
|
||||||
func (c *Client) RollupWithdraw(tokenID int64, balance *big.Int, babyPubKey *babyjub.PublicKey, numExitRoot int64, siblings []*big.Int, idx int64, instantWithdraw bool) (tx *types.Transaction, err error) {
|
|
||||||
c.rw.Lock()
|
|
||||||
defer c.rw.Unlock()
|
|
||||||
cpy := c.nextBlock().copy()
|
|
||||||
defer func() { c.revertIfErr(err, cpy) }()
|
|
||||||
if c.addr == nil {
|
|
||||||
return nil, eth.ErrAccountNil
|
|
||||||
}
|
|
||||||
|
|
||||||
log.Error("TODO")
|
|
||||||
return nil, errTODO
|
|
||||||
}
|
|
||||||
|
|
||||||
// RollupForceExit is the interface to call the smart contract function
|
|
||||||
func (c *Client) RollupForceExit(fromIdx int64, amountF common.Float16, tokenID int64) (tx *types.Transaction, err error) {
|
|
||||||
c.rw.Lock()
|
|
||||||
defer c.rw.Unlock()
|
|
||||||
cpy := c.nextBlock().copy()
|
|
||||||
defer func() { c.revertIfErr(err, cpy) }()
|
|
||||||
if c.addr == nil {
|
|
||||||
return nil, eth.ErrAccountNil
|
|
||||||
}
|
|
||||||
|
|
||||||
log.Error("TODO")
|
|
||||||
return nil, errTODO
|
|
||||||
}
|
|
||||||
|
|
||||||
// RollupForceTransfer is the interface to call the smart contract function
|
|
||||||
func (c *Client) RollupForceTransfer(fromIdx int64, amountF common.Float16, tokenID, toIdx int64) (tx *types.Transaction, err error) {
|
|
||||||
c.rw.Lock()
|
|
||||||
defer c.rw.Unlock()
|
|
||||||
cpy := c.nextBlock().copy()
|
|
||||||
defer func() { c.revertIfErr(err, cpy) }()
|
|
||||||
if c.addr == nil {
|
|
||||||
return nil, eth.ErrAccountNil
|
|
||||||
}
|
|
||||||
|
|
||||||
log.Error("TODO")
|
|
||||||
return nil, errTODO
|
|
||||||
}
|
|
||||||
|
|
||||||
// RollupCreateAccountDepositTransfer is the interface to call the smart contract function
|
|
||||||
func (c *Client) RollupCreateAccountDepositTransfer(babyPubKey babyjub.PublicKey, loadAmountF, amountF common.Float16, tokenID int64, toIdx int64) (tx *types.Transaction, err error) {
|
|
||||||
c.rw.Lock()
|
|
||||||
defer c.rw.Unlock()
|
|
||||||
cpy := c.nextBlock().copy()
|
|
||||||
defer func() { c.revertIfErr(err, cpy) }()
|
|
||||||
if c.addr == nil {
|
|
||||||
return nil, eth.ErrAccountNil
|
|
||||||
}
|
|
||||||
|
|
||||||
log.Error("TODO")
|
|
||||||
return nil, errTODO
|
|
||||||
}
|
|
||||||
|
|
||||||
// RollupGetCurrentTokens is the interface to call the smart contract function
|
// RollupGetCurrentTokens is the interface to call the smart contract function
|
||||||
func (c *Client) RollupGetCurrentTokens() (*big.Int, error) {
|
func (c *Client) RollupGetCurrentTokens() (*big.Int, error) {
|
||||||
c.rw.RLock()
|
c.rw.RLock()
|
||||||
@@ -785,89 +754,6 @@ func (c *Client) RollupGetCurrentTokens() (*big.Int, error) {
|
|||||||
return nil, errTODO
|
return nil, errTODO
|
||||||
}
|
}
|
||||||
|
|
||||||
// RollupDepositTransfer is the interface to call the smart contract function
|
|
||||||
func (c *Client) RollupDepositTransfer(fromIdx int64, loadAmountF, amountF common.Float16, tokenID int64, toIdx int64) (tx *types.Transaction, err error) {
|
|
||||||
c.rw.Lock()
|
|
||||||
defer c.rw.Unlock()
|
|
||||||
cpy := c.nextBlock().copy()
|
|
||||||
defer func() { c.revertIfErr(err, cpy) }()
|
|
||||||
if c.addr == nil {
|
|
||||||
return nil, eth.ErrAccountNil
|
|
||||||
}
|
|
||||||
|
|
||||||
log.Error("TODO")
|
|
||||||
return nil, errTODO
|
|
||||||
}
|
|
||||||
|
|
||||||
// RollupDeposit is the interface to call the smart contract function
|
|
||||||
func (c *Client) RollupDeposit(fromIdx int64, loadAmountF common.Float16, tokenID int64) (tx *types.Transaction, err error) {
|
|
||||||
c.rw.Lock()
|
|
||||||
defer c.rw.Unlock()
|
|
||||||
cpy := c.nextBlock().copy()
|
|
||||||
defer func() { c.revertIfErr(err, cpy) }()
|
|
||||||
if c.addr == nil {
|
|
||||||
return nil, eth.ErrAccountNil
|
|
||||||
}
|
|
||||||
|
|
||||||
log.Error("TODO")
|
|
||||||
return nil, errTODO
|
|
||||||
}
|
|
||||||
|
|
||||||
// RollupCreateAccountDepositFromRelayer is the interface to call the smart contract function
|
|
||||||
func (c *Client) RollupCreateAccountDepositFromRelayer(accountCreationAuthSig []byte, babyPubKey babyjub.PublicKey, loadAmountF common.Float16) (tx *types.Transaction, err error) {
|
|
||||||
c.rw.Lock()
|
|
||||||
defer c.rw.Unlock()
|
|
||||||
cpy := c.nextBlock().copy()
|
|
||||||
defer func() { c.revertIfErr(err, cpy) }()
|
|
||||||
if c.addr == nil {
|
|
||||||
return nil, eth.ErrAccountNil
|
|
||||||
}
|
|
||||||
|
|
||||||
log.Error("TODO")
|
|
||||||
return nil, errTODO
|
|
||||||
}
|
|
||||||
|
|
||||||
// RollupCreateAccountDeposit is the interface to call the smart contract function
|
|
||||||
func (c *Client) RollupCreateAccountDeposit(babyPubKey babyjub.PublicKey, loadAmountF common.Float16, tokenID int64) (tx *types.Transaction, err error) {
|
|
||||||
c.rw.Lock()
|
|
||||||
defer c.rw.Unlock()
|
|
||||||
cpy := c.nextBlock().copy()
|
|
||||||
defer func() { c.revertIfErr(err, cpy) }()
|
|
||||||
if c.addr == nil {
|
|
||||||
return nil, eth.ErrAccountNil
|
|
||||||
}
|
|
||||||
|
|
||||||
log.Error("TODO")
|
|
||||||
return nil, errTODO
|
|
||||||
}
|
|
||||||
|
|
||||||
// RollupGetTokenAddress is the interface to call the smart contract function
|
|
||||||
// func (c *Client) RollupGetTokenAddress(tokenID int64) (*ethCommon.Address, error) {
|
|
||||||
// c.rw.RLock()
|
|
||||||
// defer c.rw.RUnlock()
|
|
||||||
//
|
|
||||||
// log.Error("TODO")
|
|
||||||
// return nil, errTODO
|
|
||||||
// }
|
|
||||||
|
|
||||||
// RollupGetL1TxFromQueue is the interface to call the smart contract function
|
|
||||||
// func (c *Client) RollupGetL1TxFromQueue(queue int64, position int64) ([]byte, error) {
|
|
||||||
// c.rw.RLock()
|
|
||||||
// defer c.rw.RUnlock()
|
|
||||||
//
|
|
||||||
// log.Error("TODO")
|
|
||||||
// return nil, errTODO
|
|
||||||
// }
|
|
||||||
|
|
||||||
// RollupGetQueue is the interface to call the smart contract function
|
|
||||||
// func (c *Client) RollupGetQueue(queue int64) ([]byte, error) {
|
|
||||||
// c.rw.RLock()
|
|
||||||
// defer c.rw.RUnlock()
|
|
||||||
//
|
|
||||||
// log.Error("TODO")
|
|
||||||
// return nil, errTODO
|
|
||||||
// }
|
|
||||||
|
|
||||||
// RollupUpdateForgeL1L2BatchTimeout is the interface to call the smart contract function
|
// RollupUpdateForgeL1L2BatchTimeout is the interface to call the smart contract function
|
||||||
func (c *Client) RollupUpdateForgeL1L2BatchTimeout(newForgeL1Timeout int64) (tx *types.Transaction, err error) {
|
func (c *Client) RollupUpdateForgeL1L2BatchTimeout(newForgeL1Timeout int64) (tx *types.Transaction, err error) {
|
||||||
c.rw.Lock()
|
c.rw.Lock()
|
||||||
|
|||||||
@@ -180,7 +180,7 @@ func TestClientRollup(t *testing.T) {
|
|||||||
NewExitRoot: big.NewInt(100),
|
NewExitRoot: big.NewInt(100),
|
||||||
L1CoordinatorTxs: []common.L1Tx{},
|
L1CoordinatorTxs: []common.L1Tx{},
|
||||||
L2TxsData: []common.L2Tx{},
|
L2TxsData: []common.L2Tx{},
|
||||||
FeeIdxCoordinator: make([]common.Idx, eth.RollupConstFeeIdxCoordinatorLen),
|
FeeIdxCoordinator: []common.Idx{},
|
||||||
VerifierIdx: 0,
|
VerifierIdx: 0,
|
||||||
L1Batch: true,
|
L1Batch: true,
|
||||||
})
|
})
|
||||||
@@ -217,7 +217,7 @@ func TestClientRollup(t *testing.T) {
|
|||||||
NewExitRoot: big.NewInt(100),
|
NewExitRoot: big.NewInt(100),
|
||||||
L1CoordinatorTxs: []common.L1Tx{},
|
L1CoordinatorTxs: []common.L1Tx{},
|
||||||
L2TxsData: []common.L2Tx{},
|
L2TxsData: []common.L2Tx{},
|
||||||
FeeIdxCoordinator: make([]common.Idx, eth.RollupConstFeeIdxCoordinatorLen),
|
FeeIdxCoordinator: []common.Idx{},
|
||||||
VerifierIdx: 0,
|
VerifierIdx: 0,
|
||||||
L1Batch: true,
|
L1Batch: true,
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user