Skip to content

Commit

Permalink
update EVM contract against flow-go stdlib contract
Browse files Browse the repository at this point in the history
  • Loading branch information
sisyphusSmiling committed Jun 19, 2024
1 parent da6999f commit c36b98d
Showing 1 changed file with 40 additions and 10 deletions.
50 changes: 40 additions & 10 deletions cadence/contracts/standards/EVM.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ contract EVM {
payload: String,
// code indicating a specific validation (201-300) or execution (301-400) error
errorCode: UInt16,
// a human-readable message about the error (if any)
errorMessage: String,
// the amount of gas transaction used
gasConsumed: UInt64,
// if transaction was a deployment contains a newly deployed contract address
Expand All @@ -59,23 +61,30 @@ contract EVM {
// block height in which transaction was inclued
blockHeight: UInt64,
// block hash in which transaction was included
blockHash: String
blockHash: String,
/// captures the hex encoded data that is returned from
/// the evm. For contract deployments
/// it returns the code deployed to
/// the address provided in the contractAddress field.
/// in case of revert, the smart contract custom error message
/// is also returned here (see EIP-140 for more details).
returnedData: String
)

access(all)
event CadenceOwnedAccountCreated(addressBytes: [UInt8; 20])
event CadenceOwnedAccountCreated(address: String)

/// FLOWTokensDeposited is emitted when FLOW tokens is bridged
/// into the EVM environment. Note that this event is not emitted
/// for transfer of flow tokens between two EVM addresses.
access(all)
event FLOWTokensDeposited(addressBytes: [UInt8; 20], amount: UFix64)
event FLOWTokensDeposited(address: String, amount: UFix64)

/// FLOWTokensWithdrawn is emitted when FLOW tokens are bridged
/// out of the EVM environment. Note that this event is not emitted
/// for transfer of flow tokens between two EVM addresses.
access(all)
event FLOWTokensWithdrawn(addressBytes: [UInt8; 20], amount: UFix64)
event FLOWTokensWithdrawn(address: String, amount: UFix64)

/// BridgeAccessorUpdated is emitted when the BridgeAccessor Capability
/// is updated in the stored BridgeRouter along with identifying
Expand Down Expand Up @@ -147,7 +156,7 @@ contract EVM {
from: <-from,
to: self.bytes
)
emit FLOWTokensDeposited(addressBytes: self.bytes, amount: amount)
emit FLOWTokensDeposited(address: self.toString(), amount: amount)
}

/// Serializes the address to a hex string without the 0x prefix
Expand Down Expand Up @@ -258,6 +267,10 @@ contract EVM {
access(all)
let errorCode: UInt64

/// error message
access(all)
let errorMessage: String

/// returns the amount of gas metered during
/// evm execution
access(all)
Expand All @@ -267,6 +280,8 @@ contract EVM {
/// the evm for the call. For coa.deploy
/// calls it returns the code deployed to
/// the address provided in the contractAddress field.
/// in case of revert, the smart contract custom error message
/// is also returned here (see EIP-140 for more details).
access(all)
let data: [UInt8]

Expand All @@ -279,12 +294,14 @@ contract EVM {
init(
status: Status,
errorCode: UInt64,
errorMessage: String,
gasUsed: UInt64,
data: [UInt8],
contractAddress: [UInt8; 20]?
) {
self.status = status
self.errorCode = errorCode
self.errorMessage = errorMessage
self.gasUsed = gasUsed
self.data = data

Expand Down Expand Up @@ -366,7 +383,7 @@ contract EVM {
from: self.addressBytes,
amount: balance.attoflow
) as! @FlowToken.Vault
emit FLOWTokensWithdrawn(addressBytes: self.addressBytes, amount: balance.inFLOW())
emit FLOWTokensWithdrawn(address: self.address().toString(), amount: balance.inFLOW())
return <-vault
}

Expand Down Expand Up @@ -465,7 +482,8 @@ contract EVM {
let acc <-create CadenceOwnedAccount()
let addr = InternalEVM.createCadenceOwnedAccount(uuid: acc.uuid)
acc.initAddress(addressBytes: addr)
emit CadenceOwnedAccountCreated(addressBytes: addr)

emit CadenceOwnedAccountCreated(address: acc.address().toString())
return <-acc
}

Expand Down Expand Up @@ -608,8 +626,20 @@ contract EVM {
// constructing key list
let keyList = Crypto.KeyList()
for signature in signatureSet {
let key = acc.keys.get(keyIndex: signature.keyIndex)!
assert(!key.isRevoked, message: "revoked key is used")
let keyRef = acc.keys.get(keyIndex: signature.keyIndex)
if keyRef == nil {
return ValidationResult(
isValid: false,
problem: "invalid key index"
)
}
let key = keyRef!
if key.isRevoked {
return ValidationResult(
isValid: false,
problem: "account key is revoked"
)
}
keyList.add(
key.publicKey,
hashAlgorithm: key.hashAlgorithm,
Expand Down Expand Up @@ -753,4 +783,4 @@ contract EVM {
?.borrowBridgeAccessor()
?? panic("Could not borrow reference to the EVM bridge")
}
}
}

0 comments on commit c36b98d

Please sign in to comment.