Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[EVM] Add bridging interface to EVM contract - stable cadence port #5716

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
f45b0d4
add bridging interface to COA
sisyphusSmiling Apr 12, 2024
eea11a0
fix updated EVM dependency aliasing
sisyphusSmiling Apr 15, 2024
4f5de06
update EVM bridging interfaces for Cadence 0.42
sisyphusSmiling Apr 15, 2024
0f00313
remove entitlement from EVM & fix bootstrap
sisyphusSmiling Apr 16, 2024
b37e4c3
fix casting statement in EVM contract
sisyphusSmiling Apr 16, 2024
d07704a
fix accepted NFT & Vault conformance types in EVM contract
sisyphusSmiling Apr 16, 2024
46b39cf
fix change_contract_code_migration
sisyphusSmiling Apr 16, 2024
8e04ecb
commit fvm_test.go patch thanks to @m-peter
sisyphusSmiling Apr 16, 2024
9d0eb93
fix stdlib.ContractCode var mutation scope pointed out by @m-peter
sisyphusSmiling Apr 16, 2024
f55c14b
add BridgeAccessorUpdated event & BridgeAccessor setter to EVM contract
sisyphusSmiling Apr 17, 2024
37ee20c
fix failing fvm tests
sisyphusSmiling Apr 17, 2024
f3b72b2
cherry-pick fix
janezpodhostnik Apr 18, 2024
f617988
update EVM contract with 1.0 bridging interface
sisyphusSmiling Apr 18, 2024
1777bef
update state commitments
sisyphusSmiling Apr 18, 2024
27d9116
fix execution tests with updated state commitments
sisyphusSmiling Apr 18, 2024
6e45ab5
Merge branch 'feature/stable-cadence' into janez/add-pre-1-bridge-int…
sisyphusSmiling Apr 19, 2024
d2ab8e0
Merge branch 'feature/stable-cadence' into janez/add-pre-1-bridge-int…
janezpodhostnik Apr 24, 2024
273ddca
Merge branch 'feature/stable-cadence' into janez/add-pre-1-bridge-int…
janezpodhostnik Apr 26, 2024
ae64dbc
fix test
janezpodhostnik Apr 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion engine/execution/state/bootstrap/bootstrap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func TestBootstrapLedger(t *testing.T) {
}

func TestBootstrapLedger_ZeroTokenSupply(t *testing.T) {
expectedStateCommitmentBytes, _ := hex.DecodeString("87002823a7d14ddd8cd71296433ff1fe6ee139a0318dcb7b5fa7a320047ae43b")
expectedStateCommitmentBytes, _ := hex.DecodeString("e6f94b1e9887b475720aa2277300f9838d2c8c7bff619ce27d54be4788d9851e")
expectedStateCommitment, err := flow.ToStateCommitment(expectedStateCommitmentBytes)
require.NoError(t, err)

Expand Down
59 changes: 32 additions & 27 deletions fvm/evm/stdlib/contract.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ contract EVM {
access(all) entitlement Call
access(all) entitlement Deploy
access(all) entitlement Owner
access(all) entitlement Bridge

access(all)
event CadenceOwnedAccountCreated(addressBytes: [UInt8; 20])
Expand Down Expand Up @@ -322,21 +323,21 @@ contract EVM {
access(all)
fun depositNFT(
nft: @{NonFungibleToken.NFT},
feeProvider: &{FungibleToken.Provider}
feeProvider: auth(FungibleToken.Withdraw) &{FungibleToken.Provider}
) {
EVM.borrowBridgeAccessor().depositNFT(nft: <-nft, to: self.address(), feeProvider: feeProvider)
}

/// Bridges the given NFT from the EVM environment, requiring a Provider from which to withdraw a fee to fulfill
/// the bridge request. Note: the caller should own the requested NFT in EVM
access(all)
access(Owner | Bridge)
fun withdrawNFT(
type: Type,
id: UInt256,
feeProvider: &{FungibleToken.Provider}
feeProvider: auth(FungibleToken.Withdraw) &{FungibleToken.Provider}
): @{NonFungibleToken.NFT} {
return <- EVM.borrowBridgeAccessor().withdrawNFT(
caller: &self as &CadenceOwnedAccount,
caller: &self as auth(Call) &CadenceOwnedAccount,
type: type,
id: id,
feeProvider: feeProvider
Expand All @@ -348,26 +349,22 @@ contract EVM {
access(all)
fun depositTokens(
vault: @{FungibleToken.Vault},
feeProvider: &{FungibleToken.Provider}
feeProvider: auth(FungibleToken.Withdraw) &{FungibleToken.Provider}
) {
EVM.borrowBridgeAccessor().depositTokens(
vault: <-vault,
to: self.address(),
feeProvider: feeProvider
)
EVM.borrowBridgeAccessor().depositTokens(vault: <-vault, to: self.address(), feeProvider: feeProvider)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
EVM.borrowBridgeAccessor().depositTokens(vault: <-vault, to: self.address(), feeProvider: feeProvider)
EVM.borrowBridgeAccessor().depositTokens(
vault: <-vault,
to: self.address(),
feeProvider: feeProvider
)

}

/// Bridges the given fungible tokens from the EVM environment, requiring a Provider from which to withdraw a
/// fee to fulfill the bridge request. Note: the caller should own the requested tokens & sufficient balance of
/// requested tokens in EVM
access(all)
access(Owner | Bridge)
fun withdrawTokens(
type: Type,
amount: UInt256,
feeProvider: &{FungibleToken.Provider}
feeProvider: auth(FungibleToken.Withdraw) &{FungibleToken.Provider}
): @{FungibleToken.Vault} {
return <- EVM.borrowBridgeAccessor().withdrawTokens(
caller: &self as &CadenceOwnedAccount,
caller: &self as auth(Call) &CadenceOwnedAccount,
type: type,
amount: amount,
feeProvider: feeProvider
Expand Down Expand Up @@ -582,37 +579,37 @@ contract EVM {
resource interface BridgeAccessor {

/// Endpoint enabling the bridging of an NFT to EVM
access(all)
access(Bridge)
fun depositNFT(
nft: @{NonFungibleToken.NFT},
to: EVMAddress,
feeProvider: &{FungibleToken.Provider}
feeProvider: auth(FungibleToken.Withdraw) &{FungibleToken.Provider}
)

/// Endpoint enabling the bridging of an NFT from EVM
access(all)
access(Bridge)
fun withdrawNFT(
caller: &CadenceOwnedAccount,
caller: auth(Call) &CadenceOwnedAccount,
type: Type,
id: UInt256,
feeProvider: &{FungibleToken.Provider}
feeProvider: auth(FungibleToken.Withdraw) &{FungibleToken.Provider}
): @{NonFungibleToken.NFT}

/// Endpoint enabling the bridging of a fungible token vault to EVM
access(all)
access(Bridge)
fun depositTokens(
vault: @{FungibleToken.Vault},
to: EVMAddress,
feeProvider: &{FungibleToken.Provider}
feeProvider: auth(FungibleToken.Withdraw) &{FungibleToken.Provider}
)

/// Endpoint enabling the bridging of fungible tokens from EVM
access(all)
access(Bridge)
fun withdrawTokens(
caller: &CadenceOwnedAccount,
caller: auth(Call) &CadenceOwnedAccount,
type: Type,
amount: UInt256,
feeProvider: &{FungibleToken.Provider}
feeProvider: auth(FungibleToken.Withdraw) &{FungibleToken.Provider}
): @{FungibleToken.Vault}
}

Expand All @@ -621,20 +618,28 @@ contract EVM {
resource interface BridgeRouter {

/// Returns a reference to the BridgeAccessor designated for internal bridge requests
access(all) view fun borrowBridgeAccessor(): &{BridgeAccessor}
access(Bridge) view fun borrowBridgeAccessor(): auth(Bridge) &{BridgeAccessor}

/// Sets the BridgeAccessor Capability in the BridgeRouter
access(all) fun setBridgeAccessor(_ accessor: Capability<&{BridgeAccessor}>) {
access(Bridge) fun setBridgeAccessor(_ accessor: Capability<auth(Bridge) &{BridgeAccessor}>) {
pre {
accessor.check(): "Invalid BridgeAccessor Capability provided"
emit BridgeAccessorUpdated(
routerType: self.getType(),
routerUUID: self.uuid,
routerAddress: self.owner?.address ?? panic("Router must have an owner to be identified"),
accessorType: accessor.borrow()!.getType(),
accessorUUID: accessor.borrow()!.uuid,
accessorAddress: accessor.address
)
}
}
}

/// Returns a reference to the BridgeAccessor designated for internal bridge requests
access(self)
view fun borrowBridgeAccessor(): &{BridgeAccessor} {
return self.account.storage.borrow<&{BridgeRouter}>(from: /storage/evmBridgeRouter)
view fun borrowBridgeAccessor(): auth(Bridge) &{BridgeAccessor} {
return self.account.storage.borrow<auth(Bridge) &{BridgeRouter}>(from: /storage/evmBridgeRouter)
?.borrowBridgeAccessor()
?? panic("Could not borrow reference to the EVM bridge")
}
Expand Down
6 changes: 3 additions & 3 deletions utils/unittest/execution_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const ServiceAccountPrivateKeySignAlgo = crypto.ECDSAP256
const ServiceAccountPrivateKeyHashAlgo = hash.SHA2_256

// Pre-calculated state commitment with root account with the above private key
const GenesisStateCommitmentHex = "3083504c73c70c527903726c7e1811e3f767b8d83da2d0c1aa433cd0c97a4f3b"
const GenesisStateCommitmentHex = "92ca07adaa707b88b5904184bdfa61ec73510095460bb18cae087fc3fd3d5d16"

var GenesisStateCommitment flow.StateCommitment

Expand Down Expand Up @@ -87,10 +87,10 @@ func genesisCommitHexByChainID(chainID flow.ChainID) string {
return GenesisStateCommitmentHex
}
if chainID == flow.Testnet {
return "4bd716d5d5aa783b3020c8e9d9094d11dfd9103a899d50f75a3cb0ce7bc2b83b"
return "b85eb5e6c4c4b011f0d69ce114cd18375d2a50ab3e8cf57665662f2d196b4ded"
}
if chainID == flow.Sandboxnet {
return "e1c08b17f9e5896f03fe28dd37ca396c19b26628161506924fbf785834646ea1"
}
return "25854b600d6f84010acb5877842375605340cfc1ba7be9ba7f5830acb5c1b19e"
return "065bc6c49a12fcacb7c7f2289bf4432a02c1057d77f14e0b01c2899f40b4199e"
}
Loading