aboutsummaryrefslogtreecommitdiff
path: root/plugin/evm/export_tx.go
diff options
context:
space:
mode:
authorDeterminant <[email protected]>2020-08-20 02:21:57 -0400
committerDeterminant <[email protected]>2020-08-20 02:21:57 -0400
commitb3fb1dc6ed3c5610c03abdd6f2ff7bf164fb83ca (patch)
treefd8de359333b11f9178b05b054c9bbd3380bd903 /plugin/evm/export_tx.go
parenta054d19f05a31a0421d6fe1bc534da46921481d5 (diff)
add flow check for ExportTx
Diffstat (limited to 'plugin/evm/export_tx.go')
-rw-r--r--plugin/evm/export_tx.go32
1 files changed, 30 insertions, 2 deletions
diff --git a/plugin/evm/export_tx.go b/plugin/evm/export_tx.go
index 4f47a16..8b3c4f8 100644
--- a/plugin/evm/export_tx.go
+++ b/plugin/evm/export_tx.go
@@ -91,8 +91,36 @@ func (tx *UnsignedExportTx) SemanticVerify(
return permError{err}
}
- // TODO: credential check
- // TODO: flow check
+ f := crypto.FactorySECP256K1R{}
+ for i, cred := range stx.Creds {
+ if err := cred.Verify(); err != nil {
+ return permError{err}
+ }
+ pubKey, err := f.RecoverPublicKey(tx.UnsignedBytes(), cred.(*secp256k1fx.Credential).Sigs[0][:])
+ if err != nil {
+ return permError{err}
+ }
+ if tx.Ins[i].Address != PublicKeyToEthAddress(pubKey) {
+ return permError{errPublicKeySignatureMismatch}
+ }
+ }
+
+ // do flow-checking
+ fc := avax.NewFlowChecker()
+ fc.Produce(vm.ctx.AVAXAssetID, vm.txFee)
+
+ for _, out := range tx.ExportedOutputs {
+ fc.Produce(out.AssetID(), out.Output().Amount())
+ }
+
+ for _, in := range tx.Ins {
+ fc.Consume(vm.ctx.AVAXAssetID, in.Amount)
+ }
+
+ if err := fc.Verify(); err != nil {
+ return permError{err}
+ }
+
// TODO: verify UTXO outputs via gRPC
return nil
}