Skip to content

Commit

Permalink
Rename Ethereum -> the EVM. (FuelLabs#1930)
Browse files Browse the repository at this point in the history
  • Loading branch information
adlerjohn authored Jun 13, 2022
1 parent f38ce32 commit e927004
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 22 deletions.
4 changes: 2 additions & 2 deletions docs/src/basics/blockchain_types.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ These are provided via the standard library ([`lib-std`](https://github.com/Fuel

## `Address` Type

The `Address` type is a type-safe wrapper around the primitive `b256` type. Unlike Ethereum, an address **never** refers to a deployed smart contract (see the `ContractId` type below). An `Address` can be either the hash of a public key (effectively an [externally owned account](https://ethereum.org/en/whitepaper/#ethereum-accounts) if you're coming from Ethereum) or the hash of a [predicate](../sway-program-types/predicates.md). Addresses own UTXOs.
The `Address` type is a type-safe wrapper around the primitive `b256` type. Unlike the EVM, an address **never** refers to a deployed smart contract (see the `ContractId` type below). An `Address` can be either the hash of a public key (effectively an [externally owned account](https://ethereum.org/en/whitepaper/#ethereum-accounts) if you're coming from the EVM) or the hash of a [predicate](../sway-program-types/predicates.md). Addresses own UTXOs.

An `Address` is implemented as follows.

Expand All @@ -26,7 +26,7 @@ let forty_two: b256 = my_address.into();

## `ContractId` Type

The `ContractId` type is a type-safe wrapper around the primitive `b256` type. A contract's ID is a unique, deterministic identifier analogous to a contract's address on Ethereum. Contracts cannot own UTXOs but can own assets.
The `ContractId` type is a type-safe wrapper around the primitive `b256` type. A contract's ID is a unique, deterministic identifier analogous to a contract's address in the EVM. Contracts cannot own UTXOs but can own assets.

A `ContractId` is implemented as follows.

Expand Down
4 changes: 2 additions & 2 deletions docs/src/blockchain-development/access_control.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Smart contracts require the ability to restrict access to and identify certain u

## `msg_sender`

To deliver an experience akin to Ethereum's access control, the `std` library provides a `msg_sender` function, which identifies a unique caller based upon the call and/or transaction input data.
To deliver an experience akin to the EVM's access control, the `std` library provides a `msg_sender` function, which identifies a unique caller based upon the call and/or transaction input data.

```sway
{{#include ../../../examples/msg_sender/src/main.sw}}
Expand All @@ -14,4 +14,4 @@ The `msg_sender` function works as follows:

- If the caller is a contract, then `Result::Ok(Sender)` is returned with the `ContractId` sender variant.
- If the caller is external (i.e. from a script), then all coin input owners in the transaction are checked. If all owners are the same, then `Result::Ok(Sender)` is returned with the `Address` sender variant.
- If the caller is external and coin input owners are different, then the caller cannot be determined and a `Result::Err(AuthError)` is returned.
- If the caller is external and coin input owners are different, then the caller cannot be determined and a `Result::Err(AuthError)` is returned.
6 changes: 3 additions & 3 deletions docs/src/blockchain-development/calling_contracts.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ fn main() {

## Handling Re-entrancy

A common attack vector for smart contracts is [re-entrancy](https://docs.soliditylang.org/en/v0.8.4/security-considerations.html#re-entrancy). Similar to the Ethereum Virtual Machine, the FuelVM allows for re-entrancy.
A common attack vector for smart contracts is [re-entrancy](https://docs.soliditylang.org/en/v0.8.4/security-considerations.html#re-entrancy). Similar to the EVM, the FuelVM allows for re-entrancy.

A _stateless_ re-entrancy guard is included in the Sway standard library. The guard will panic (revert) at run time if re-entrancy is detected.

Expand All @@ -97,9 +97,9 @@ impl ContractB for Contract {
}
```

## Differences from Ethereum
## Differences from the EVM

While the Fuel contract calling paradigm is similar to Ethereum's (using an ABI, forwarding gas and data), it differs in _two_ key ways:
While the Fuel contract calling paradigm is similar to the EVM's (using an ABI, forwarding gas and data), it differs in _two_ key ways:

1. [**Native assets**](./native_assets.md): FuelVM calls can forward any native asset not just base asset.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Hashing and Cryptography

The Sway standard library provides easy access to a selection of cryptographic hash functions (`sha256` and Ethereum-compatible `keccak256`), and Ethereum-compatible `secp256k1`-based signature recovery operations.
The Sway standard library provides easy access to a selection of cryptographic hash functions (`sha256` and EVM-compatible `keccak256`), and EVM-compatible `secp256k1`-based signature recovery operations.

## Hashing

Expand Down
2 changes: 1 addition & 1 deletion docs/src/blockchain-development/identifiers.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Identifiers

Addresses in Sway are similar to Ethereum addresses. The two major differences are:
Addresses in Sway are similar to EVM addresses. The two major differences are:

1. Sway addresses are 32 bytes long (instead of 20), and
1. are computed with the SHA-256 hash of the public key instead of the keccak-256 hash.
Expand Down
4 changes: 2 additions & 2 deletions docs/src/blockchain-development/native_assets.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ The FuelVM has built-in support for working with multiple assets.

What does this mean in practice?

As in Ethereum, sending ETH to an address or contract is an operation built into the FuelVM, meaning it doesn't rely on the existence of some token smart contract to update balances to track ownership.
As in the EVM, sending ETH to an address or contract is an operation built into the FuelVM, meaning it doesn't rely on the existence of some token smart contract to update balances to track ownership.

However, unlike Ethereum, the process for sending _any_ native asset is the same. This means that while you would still need a smart contract to handle the minting and burning of fungible tokens, the sending and receiving of these tokens can be done independently of the token contract.
However, unlike the EVM, the process for sending _any_ native asset is the same. This means that while you would still need a smart contract to handle the minting and burning of fungible tokens, the sending and receiving of these tokens can be done independently of the token contract.

## Liquidity Pool Example

Expand Down
2 changes: 1 addition & 1 deletion docs/src/sway-program-types/scripts.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ An example use case for a script would be a router that trades funds through mul

## Scripts and the SDKs

Unlike Ethereum transactions which can call a contract directly (but can only call a single contract), Fuel transactions execute a script, which may call zero or more contracts. The Rust and TypeScript SDKs provide functions to call contract methods as if they were calling contracts directly. Under the hood, the SDKs wrap all contract calls with scripts that contain minimal code to simply make the call and forward script data as call parameters.
Unlike EVM transactions which can call a contract directly (but can only call a single contract), Fuel transactions execute a script, which may call zero or more contracts. The Rust and TypeScript SDKs provide functions to call contract methods as if they were calling contracts directly. Under the hood, the SDKs wrap all contract calls with scripts that contain minimal code to simply make the call and forward script data as call parameters.
9 changes: 3 additions & 6 deletions test-sig-gen-util/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use secp256k1::{PublicKey, Secp256k1, SecretKey};
use sha3::{Digest, Keccak256};
use std::str::FromStr;

// A keccak-256 method for generating ethereum signatures
// A keccak-256 method for generating EVM signatures
fn keccak_hash<B>(data: B) -> Bytes32
where
B: AsRef<[u8]>,
Expand All @@ -32,7 +32,7 @@ fn main() -> Result<()> {
let public = Bytes64::try_from(&public[1..]).expect("Failed to parse public key!");
// 64 byte fuel address is the sha-256 hash of the public key.
let address = Hasher::hash(&public[..]);
let ethereum_pubkeyhash = keccak_hash(&public[..]);
let evm_pubkeyhash = keccak_hash(&public[..]);

let message = b"The gift of words is the gift of deception and illusion.";
let e = Hasher::hash(&message[..]);
Expand All @@ -42,10 +42,7 @@ fn main() -> Result<()> {
tracing::info!("Secret Key: {:?}", secret);
tracing::info!("Public Key: {:?}", public);
tracing::info!("Fuel Address (sha2-256): {:?}", address);
tracing::info!(
"Ethereum pubkey hash (keccak256): {:?}",
ethereum_pubkeyhash
);
tracing::info!("EVM pubkey hash (keccak256): {:?}", evm_pubkeyhash);
tracing::info!("Message Hash: {:?}", e);
tracing::info!("Signature: {:?}", sig);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ fn main() -> bool {
Secret Key: SecretKey(3b940b5586823dfd02ae3b461bb4336b5ecbaefd6627aa922efc048fec0c881c)
Public Key: 1d152307c6b72b0ed0418b0e70cd80e7f5295b8d86f5722d3f5213fbd2394f36b7ce9c3e45905178455900b44abb308f3ef480481a4b2ee3f70aca157fde396a
Fuel Address (sha2-256): 6ba48099f6b75cae5a403863ace6ee8dc03f75e7aebc58b819667477358ae677
Ethereum pubkey hash (keccak256): e4eab8f844a8d11b205fd137a1b7ea5ede26f651909505d99cf8b5c0d4c8e9c1
EVM pubkey hash (keccak256): e4eab8f844a8d11b205fd137a1b7ea5ede26f651909505d99cf8b5c0d4c8e9c1
Message Hash: 8ddb13a2ab58f413bd3121e1ddc8b83a328f3b830d19a7c471f0be652d23bb0e
Signature: 82115ed208d8fe8dd522d88ca77812b34d270d6bb6326ff511297766a3af1166c07204f554a00e49a2ee69f0979dc4feef07f7dba8d779d388fb2a53bc9bcde4
*/

// Get the expected ethereum address
// Get the expected EVM address
let pubkeyhash = 0xe4eab8f844a8d11b205fd137a1b7ea5ede26f651909505d99cf8b5c0d4c8e9c1;
let ethereum_address = ~EvmAddress::from(pubkeyhash);
let evm_address = ~EvmAddress::from(pubkeyhash);

let msg_hash = 0x8ddb13a2ab58f413bd3121e1ddc8b83a328f3b830d19a7c471f0be652d23bb0e;

Expand All @@ -34,5 +34,5 @@ fn main() -> bool {
let result: Result<EvmAddress, EcRecoverError> = ec_recover_evm_address(signature, msg_hash);
let recovered_address = result.unwrap();

recovered_address == ethereum_address
recovered_address == evm_address
}

0 comments on commit e927004

Please sign in to comment.