[core] fix: Move existing CXReceipt check to top

pull/4165/head
MaxMustermann2 3 years ago
parent ada5699cc4
commit 500cabfae2
No known key found for this signature in database
GPG Key ID: 4F4AB9DB6FF24C94
  1. 12
      core/vm/contracts_write.go

@ -230,6 +230,12 @@ func (c *crossShardXferPrecompile) RunWriteCapable(
contract *Contract, contract *Contract,
input []byte, input []byte,
) ([]byte, error) { ) ([]byte, error) {
// make sure that cxReceipt is already nil to
// prevent multiple calls to the precompile
// in the same transaction
if evm.CXReceipt != nil {
return nil, errors.New("cannot call cross shard precompile again in same tx")
}
fromAddress, toAddress, fromShardID, toShardID, value, err := fromAddress, toAddress, fromShardID, toShardID, value, err :=
parseCrossShardXferData(evm, contract, input) parseCrossShardXferData(evm, contract, input)
if err != nil { if err != nil {
@ -257,9 +263,6 @@ func (c *crossShardXferPrecompile) RunWriteCapable(
return nil, errors.New("not enough balance received") return nil, errors.New("not enough balance received")
} }
evm.Transfer(evm.StateDB, contract.Address(), toAddress, value, types.SubtractionOnly) evm.Transfer(evm.StateDB, contract.Address(), toAddress, value, types.SubtractionOnly)
// make sure that cxreceipt is already nil to prevent multiple calls to the precompile
// in the same transaction
if evm.CXReceipt == nil {
// step 2 -> make a cross link // step 2 -> make a cross link
// note that the transaction hash is added by state_processor.go to this receipt // note that the transaction hash is added by state_processor.go to this receipt
// and that the receiving shard does not care about the `From` but we use the original // and that the receiving shard does not care about the `From` but we use the original
@ -271,9 +274,6 @@ func (c *crossShardXferPrecompile) RunWriteCapable(
ToShardID: toShardID, ToShardID: toShardID,
Amount: value, Amount: value,
} }
} else {
return nil, errors.New("cannot call cross shard precompile again in same tx")
}
return nil, nil return nil, nil
} }

Loading…
Cancel
Save