Skip to content

Commit

Permalink
Merge pull request #100 from onflow/update-previewnet-deployment
Browse files Browse the repository at this point in the history
Update previewnet deployment
  • Loading branch information
sisyphusSmiling authored Aug 5, 2024
2 parents c27bdfd + be5f7fd commit 62aa778
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 61 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ addresses:

|Contracts|PreviewNet|Testnet|Mainnet|
|---|---|---|---|
|All Cadence Bridge contracts|`0x715c57f7a59bc39b`|`0xdfc20aee650fcbdf`|TBD|
|[`FlowEVMBridgeFactory.sol`](./solidity/src/FlowBridgeFactory.sol)|`0xf23c8619603434f7f71659820193c8e491feb1d9`|TBD|TBD|
|[`FlowEVMBridgeDeploymentRegistry.sol`](./solidity/src/FlowEVMBridgeDeploymentRegistry.sol)|`0x544ef4ed9209ebe6989bed9e543632512afb25de`|TBD|TBD|
|[`FlowEVMBridgedERC20Deployer.sol`](./solidity/src/FlowEVMBridgedERC20Deployer.sol)|`0xc5577d2935ef0556b37358d8b92aa578f1e7564e`|TBD|TBD|
|[`FlowEVMBridgedERC721Deployer.sol`](./solidity/src/FlowEVMBridgedERC721Deployer.sol)|`0xd5bf043e8d5e6e007ebfdefebef7f4c96de5d40a`|TBD|TBD|
|All Cadence Bridge contracts|`0x7792cfb75d8dfdd8`|`0xdfc20aee650fcbdf`|TBD|
|[`FlowEVMBridgeFactory.sol`](./solidity/src/FlowBridgeFactory.sol)|`0xb0885c08995a053d8dcadce1c66b2fb11e40b868`|TBD|TBD|
|[`FlowEVMBridgeDeploymentRegistry.sol`](./solidity/src/FlowEVMBridgeDeploymentRegistry.sol)|`0xfadbc0c156f6679d1ac9eb271d4e55dce7de8802`|TBD|TBD|
|[`FlowEVMBridgedERC20Deployer.sol`](./solidity/src/FlowEVMBridgedERC20Deployer.sol)|`0x9d5fe779e35d1f13abd875dd6c2b49f20e813054`|TBD|TBD|
|[`FlowEVMBridgedERC721Deployer.sol`](./solidity/src/FlowEVMBridgedERC721Deployer.sol)|`0x211f54ca1e325a3946ed67aeefcc6cc32b1e833d`|TBD|TBD|

## Interacting with the bridge

Expand Down
102 changes: 71 additions & 31 deletions cadence/contracts/standards/EVM.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import "FlowToken"
access(all)
contract EVM {

// Entitlements enabling finer-graned access control on a CadenceOwnedAccount
// Entitlements enabling finer-grained access control on a CadenceOwnedAccount
access(all) entitlement Validate
access(all) entitlement Withdraw
access(all) entitlement Call
Expand All @@ -21,33 +21,33 @@ contract EVM {
// height or number of the block
height: UInt64,
// hash of the block
hash: String,
hash: [UInt8; 32],
// timestamp of the block creation
timestamp: UInt64,
// total Flow supply
totalSupply: Int,
// all gas used in the block by transactions included
totalGasUsed: UInt64,
// parent block hash
parentHash: String,
// hash of all the transaction receipts
receiptRoot: String,
// all the transactions included in the block
transactionHashes: [String]
parentHash: [UInt8; 32],
// root hash of all the transaction receipts
receiptRoot: [UInt8; 32],
// root hash of all the transaction hashes
transactionHashRoot: [UInt8; 32],
)

/// Transaction executed event is emitted everytime a transaction
/// Transaction executed event is emitted every time a transaction
/// is executed by the EVM (even if failed).
access(all)
event TransactionExecuted(
// hash of the transaction
hash: String,
hash: [UInt8; 32],
// index of the transaction in a block
index: UInt16,
// type of the transaction
type: UInt8,
// RLP and hex encoded transaction payload
payload: String,
// RLP encoded transaction payload
payload: [UInt8],
// code indicating a specific validation (201-300) or execution (301-400) error
errorCode: UInt16,
// a human-readable message about the error (if any)
Expand All @@ -56,19 +56,22 @@ contract EVM {
gasConsumed: UInt64,
// if transaction was a deployment contains a newly deployed contract address
contractAddress: String,
// RLP and hex encoded logs
logs: String,
// block height in which transaction was inclued
// RLP encoded logs
logs: [UInt8],
// block height in which transaction was included
blockHeight: UInt64,
// block hash in which transaction was included
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
returnedData: [UInt8],
/// captures the input and output of the calls (rlp encoded) to the extra
/// precompiled contracts (e.g. Cadence Arch) during the transaction execution.
/// This data helps to replay the transactions without the need to
/// have access to the full cadence state data.
precompiledCalls: [UInt8]
)

access(all)
Expand All @@ -78,26 +81,28 @@ contract EVM {
/// into the EVM environment. Note that this event is not emitted
/// for transfer of flow tokens between two EVM addresses.
/// Similar to the FungibleToken.Deposited event
/// this event includes a depositedUUID that captures the
/// this event includes a depositedUUID that captures the
/// uuid of the source vault.
access(all)
event FLOWTokensDeposited(
address: String,
amount: UFix64,
depositedUUID: UInt64
address: String,
amount: UFix64,
depositedUUID: UInt64,
balanceAfterInAttoFlow: UInt
)

/// 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.
/// similar to the FungibleToken.Withdrawn events
/// this event includes a withdrawnUUID that captures the
/// this event includes a withdrawnUUID that captures the
/// uuid of the returning vault.
access(all)
event FLOWTokensWithdrawn(
address: String,
amount: UFix64,
withdrawnUUID: UInt64
address: String,
amount: UFix64,
withdrawnUUID: UInt64,
balanceAfterInAttoFlow: UInt
)

/// BridgeAccessorUpdated is emitted when the BridgeAccessor Capability
Expand Down Expand Up @@ -172,9 +177,10 @@ contract EVM {
to: self.bytes
)
emit FLOWTokensDeposited(
address: self.toString(),
amount: amount,
depositedUUID: depositedUUID
address: self.toString(),
amount: amount,
depositedUUID: depositedUUID,
balanceAfterInAttoFlow: self.balance().attoflow
)
}

Expand All @@ -201,7 +207,7 @@ contract EVM {
}
// Strip the 0x prefix if it exists
var withoutPrefix = (asHex[1] == "x" ? asHex.slice(from: 2, upTo: asHex.length) : asHex).toLower()
let bytes = withoutPrefix.decodeHex().toConstantSized<[UInt8;20]>()!
let bytes = withoutPrefix.decodeHex().toConstantSized<[UInt8; 20]>()!
return EVMAddress(bytes: bytes)
}

Expand Down Expand Up @@ -405,7 +411,8 @@ contract EVM {
emit FLOWTokensWithdrawn(
address: self.address().toString(),
amount: balance.inFLOW(),
withdrawnUUID: vault.uuid
withdrawnUUID: vault.uuid,
balanceAfterInAttoFlow: self.balance().attoflow
)
return <-vault
}
Expand Down Expand Up @@ -806,4 +813,37 @@ contract EVM {
?.borrowBridgeAccessor()
?? panic("Could not borrow reference to the EVM bridge")
}
}

/// The Heartbeat resource controls the block production.
/// It is stored in the storage and used in the Flow protocol to call the heartbeat function once per block.
access(all)
resource Heartbeat {
/// heartbeat calls commit block proposals and forms new blocks including all the
/// recently executed transactions.
/// The Flow protocol makes sure to call this function once per block as a system call.
access(all)
fun heartbeat() {
InternalEVM.commitBlockProposal()
}
}

/// setupHeartbeat creates a heartbeat resource and saves it to storage.
/// The function is called once during the contract initialization.
///
/// The heartbeat resource is used to control the block production,
/// and used in the Flow protocol to call the heartbeat function once per block.
///
/// The function can be called by anyone, but only once:
/// the function will fail if the resource already exists.
///
/// The resulting resource is stored in the account storage,
/// and is only accessible by the account, not the caller of the function.
access(all)
fun setupHeartbeat() {
self.account.storage.save(<-create Heartbeat(), to: /storage/EVMHeartbeat)
}

init() {
self.setupHeartbeat()
}
}
5 changes: 3 additions & 2 deletions cadence/tests/flow_evm_bridge_utils_tests.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,12 @@ fun setup() {
Test.expect(err, Test.beNil())
let deploymentResult = executeTransaction(
"../transactions/evm/deploy.cdc",
[getCompiledFactoryBytecode(), 15_000_000, 0.0],
[getCompiledFactoryBytecode(), UInt64(15_000_000), 0.0],
bridgeAccount
)
Test.expect(deploymentResult, Test.beSucceeded())
let evts = Test.eventsOfType(Type<EVM.TransactionExecuted>())
Test.assertEqual(2, evts.length)
Test.assertEqual(3, evts.length)
let factoryAddressHex = getEVMAddressHexFromEvents(evts, idx: 0)
err = Test.deployContract(
name: "FlowEVMBridgeUtils",
Expand Down
Loading

0 comments on commit 62aa778

Please sign in to comment.