aboutsummaryrefslogblamecommitdiff
path: root/plugin/evm/import_tx.go
blob: 995e488a1adb8f050a26b92b3646bd680dbef26e (plain) (tree)
1
2
3
4
5
6
7
8
9
10





                                                     
             


                                               
 
                                            
                                       
                                        
                                                
                                              
                                                       

                                                   

 

                                           




                                                                              
                                 
                                                                  

                                                                

                                                                                         



                                                                 










                                                       
                                         





                                   




                                                                               


                                           
                                      

                                         



                                                  

         



                                                    






                                                   
                                                                         


                                               




                                            



                                           
                                                                                                

                                     


                                   
                                                

                                     
                                                          








                                                             
                                                         







                                                                            
                                                                                   
                                              




                           
                                               
                                                  
                                                                        
                
                                             


                                           
                                       
                                  
                           

         
                                                                                                           



                                                                                  
                                                     
                                                     



                                          
                                                               





                                                                      
                                                            






                                                                                
                                                                                





                                                      
                                                                       




                                                                          

                                                                                   
                                                                                
                                      


                                              

                                                           



                                 


                                                 
                                               
                                        
         

                                                          

                               
                                                                                    
 








                                                                               
// (c) 2019-2020, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.

package evm

import (
	"fmt"
	"math/big"

	"github.com/ava-labs/coreth/core/state"

	"github.com/ava-labs/gecko/database"
	"github.com/ava-labs/gecko/ids"
	"github.com/ava-labs/gecko/snow"
	"github.com/ava-labs/gecko/utils/crypto"
	"github.com/ava-labs/gecko/utils/math"
	"github.com/ava-labs/gecko/vms/components/avax"
	"github.com/ava-labs/gecko/vms/secp256k1fx"
	"github.com/ava-labs/go-ethereum/common"
)

// UnsignedImportTx is an unsigned ImportTx
type UnsignedImportTx struct {
	avax.Metadata
	// true iff this transaction has already passed syntactic verification
	syntacticallyVerified bool
	// ID of the network on which this tx was issued
	NetworkID uint32 `serialize:"true" json:"networkID"`
	// ID of this blockchain.
	BlockchainID ids.ID `serialize:"true" json:"blockchainID"`
	// Which chain to consume the funds from
	SourceChain ids.ID `serialize:"true" json:"sourceChain"`
	// Inputs that consume UTXOs produced on the chain
	ImportedInputs []*avax.TransferableInput `serialize:"true" json:"importedInputs"`
	// Outputs
	Outs []EVMOutput `serialize:"true" json:"outputs"`
	// Memo field contains arbitrary bytes, up to maxMemoSize
	Memo []byte `serialize:"true" json:"memo"`
}

// InputUTXOs returns the UTXOIDs of the imported funds
func (tx *UnsignedImportTx) InputUTXOs() ids.Set {
	set := ids.Set{}
	for _, in := range tx.ImportedInputs {
		set.Add(in.InputID())
	}
	return set
}

// Verify this transaction is well-formed
func (tx *UnsignedImportTx) Verify(
	avmID ids.ID,
	ctx *snow.Context,
	feeAmount uint64,
	feeAssetID ids.ID,
) error {
	switch {
	case tx == nil:
		return errNilTx
	case tx.syntacticallyVerified: // already passed syntactic verification
		return nil
	case tx.SourceChain.IsZero():
		return errWrongChainID
	case !tx.SourceChain.Equals(avmID):
		return errWrongChainID
	case len(tx.ImportedInputs) == 0:
		return errNoImportInputs
	case tx.NetworkID != ctx.NetworkID:
		return errWrongNetworkID
	case !ctx.ChainID.Equals(tx.BlockchainID):
		return errWrongBlockchainID
	}

	for _, out := range tx