From 5fc26bb832c715cfd2628585d41bb82209ecdfe4 Mon Sep 17 00:00:00 2001 From: Determinant Date: Thu, 20 Aug 2020 00:44:56 -0400 Subject: ... --- plugin/evm/block.go | 65 +++++++++++++++++++++++++++++------------------------ plugin/evm/vm.go | 1 + 2 files changed, 37 insertions(+), 29 deletions(-) diff --git a/plugin/evm/block.go b/plugin/evm/block.go index 1cbf0b7..d75ea1d 100644 --- a/plugin/evm/block.go +++ b/plugin/evm/block.go @@ -4,6 +4,7 @@ package evm import ( + "errors" "fmt" "github.com/ava-labs/coreth/core/types" @@ -62,39 +63,45 @@ func (b *Block) Parent() snowman.Block { // Verify implements the snowman.Block interface func (b *Block) Verify() error { vm := b.vm - if b.ethBlock.Hash() == vm.genesisHash { - return nil - } - p := b.Parent() - path := []*Block{} - inputs := new(ids.Set) - for { - if p.Status() == choices.Accepted || p.(*Block).ethBlock.Hash() == vm.genesisHash { - break + tx := vm.getAtomicTx(b.ethBlock) + switch atx := tx.UnsignedTx.(type) { + case *UnsignedImportTx: + if b.ethBlock.Hash() == vm.genesisHash { + return nil } - if ret, hit := vm.blockAtomicInputCache.Get(p.ID()); hit { - inputs = ret.(*ids.Set) - break + p := b.Parent() + path := []*Block{} + inputs := new(ids.Set) + for { + if p.Status() == choices.Accepted || p.(*Block).ethBlock.Hash() == vm.genesisHash { + break + } + if ret, hit := vm.blockAtomicInputCache.Get(p.ID()); hit { + inputs = ret.(*ids.Set) + break + } + path = append(path, p.(*Block)) + p = p.Parent().(*Block) } - path = append(path, p.(*Block)) - p = p.Parent().(*Block) - } - for i := len(path) - 1; i >= 0; i-- { - inputsCopy := new(ids.Set) - p := path[i] - atx := vm.getAtomicTx(p.ethBlock) - inputs.Union(atx.UnsignedTx.(UnsignedAtomicTx).InputUTXOs()) - inputsCopy.Union(*inputs) - vm.blockAtomicInputCache.Put(p.ID(), inputsCopy) - } - tx := b.vm.getAtomicTx(b.ethBlock) - atx := tx.UnsignedTx.(*UnsignedImportTx) - for _, in := range atx.InputUTXOs().List() { - if inputs.Contains(in) { - return errInvalidBlock + for i := len(path) - 1; i >= 0; i-- { + inputsCopy := new(ids.Set) + p := path[i] + atx := vm.getAtomicTx(p.ethBlock) + inputs.Union(atx.UnsignedTx.(UnsignedAtomicTx).InputUTXOs()) + inputsCopy.Union(*inputs) + vm.blockAtomicInputCache.Put(p.ID(), inputsCopy) } + for _, in := range atx.InputUTXOs().List() { + if inputs.Contains(in) { + return errInvalidBlock + } + } + case *UnsignedExportTx: + default: + return errors.New("unknown atomic tx type") } - if atx.SemanticVerify(b.vm, tx) != nil { + + if tx.UnsignedTx.(UnsignedAtomicTx).SemanticVerify(vm, tx) != nil { return errInvalidBlock } diff --git a/plugin/evm/vm.go b/plugin/evm/vm.go index 38646c9..fffc0d5 100644 --- a/plugin/evm/vm.go +++ b/plugin/evm/vm.go @@ -116,6 +116,7 @@ func init() { errs := wrappers.Errs{} errs.Add( Codec.RegisterType(&UnsignedImportTx{}), + Codec.RegisterType(&UnsignedExportTx{}), Codec.RegisterType(&secp256k1fx.TransferInput{}), Codec.RegisterType(&secp256k1fx.Input{}), Codec.RegisterType(&secp256k1fx.Credential{}), -- cgit v1.2.3