Skip to content

Commit

Permalink
added a guard so contracts callers cannot create custom EVM receipts …
Browse files Browse the repository at this point in the history
…for deposits
  • Loading branch information
jorgemmsilva committed Oct 25, 2023
1 parent 11aa6d0 commit acda2a7
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions packages/vm/core/accounts/impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,20 +73,23 @@ func transferAllowanceTo(ctx isc.Sandbox) dict.Dict {
allowance := ctx.AllowanceAvailable().Clone()
ctx.TransferAllowedFunds(targetAccount)

if targetAccount.Kind() == isc.AgentIDKindEthereumAddress {
evmAcc := targetAccount.(*isc.EthereumAddressAgentID).EthAddress().Bytes()
// issue an "custom" etherum tx so the funds appear on the explorer
ctx.Call(
evm.Contract.Hname(),
evm.FuncNewL1Deposit.Hname(),
dict.Dict{
evm.FieldAddress: evmAcc,
evm.FieldAssets: allowance.Bytes(),
evm.FieldAgentIDDepositOriginator: ctx.Caller().Bytes(),
},
nil,
)
if targetAccount.Kind() != isc.AgentIDKindEthereumAddress {
return nil // done
}
if !ctx.Caller().Equals(ctx.Request().SenderAccount()) {
return nil // only issue "custom EVM tx" when this function is called directly by the request sender
}
// issue a "custom EVM tx" so the funds appear on the explorer
ctx.Call(
evm.Contract.Hname(),
evm.FuncNewL1Deposit.Hname(),
dict.Dict{
evm.FieldAddress: targetAccount.(*isc.EthereumAddressAgentID).EthAddress().Bytes(),
evm.FieldAssets: allowance.Bytes(),
evm.FieldAgentIDDepositOriginator: ctx.Caller().Bytes(),
},
nil,
)
ctx.Log().Debugf("accounts.transferAllowanceTo.success: target: %s\n%s", targetAccount, ctx.AllowanceAvailable())
return nil
}
Expand Down

0 comments on commit acda2a7

Please sign in to comment.