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

Feat(eth-implicit-accounts): Stabilize protocol change #11765

Merged
merged 28 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
86f290d
Fix(issue-29): Implement emulation for ERC-20 totalSupply function
birchmd Jul 1, 2024
e8d54f3
Fix(issue-5): Disallow registering eth-implicit accounts
birchmd Jul 1, 2024
cfb46f7
Fix(issue-6): Require deposit on address registrar calls
birchmd Jul 1, 2024
cb2c7dd
Fix(issue-32): Allow emulation of base token transfers to self
birchmd Jul 1, 2024
67d4153
Fix(issue-8): Require the relayer to attach at least as much gas as i…
birchmd Jul 1, 2024
6e335f9
Fix(issue-18): Enable integer overflow checks
birchmd Jul 1, 2024
9b8731a
Fix(issue-21): Include memo in ft_transfer when emulating ERC-20 toke…
birchmd Jul 1, 2024
055e802
Fix(issue-25): Upgrade Near SDK to 5.1
birchmd Jul 2, 2024
0a79d24
Fix(issue-4): Amounts greater than or equal to 1e6 are forbidden in y…
birchmd Jul 2, 2024
9240311
Fix(issue-28): Set proper doc comment on chain id
birchmd Jul 2, 2024
2a9ddb2
Fix(issue-7): Do not require external callers to pay for Near spent d…
birchmd Jul 2, 2024
922579d
Fix(issue-3): Prevent simultaneous in-flight transactions. Rational: …
birchmd Jul 2, 2024
a871e74
Fix(issue-2): Do not increment the nonce in the case of relayer error…
birchmd Jul 2, 2024
5e7f63b
Fix(issue-6): Refund user's deposit when there is a duplicate entry o…
birchmd Jul 8, 2024
0fe499b
Fix(issue-1): Refund an external caller's deposit when the cross-cont…
birchmd Jul 8, 2024
96e1363
Merge branch 'master' into fix/eth_wallet/audit
birchmd Jul 9, 2024
7979143
Feat(eth-wallet): Refund relayers for emulated base token transfers
birchmd Jul 9, 2024
cc07e70
Feat(wallet-contract): also refund the relayer for emulated ERC-20 tr…
birchmd Jul 10, 2024
34b9a2a
Chore(eth-wallet): Update wallet contract binaries
birchmd Jul 10, 2024
f00ffd9
Merge branch 'master' into fix/eth_wallet/audit
birchmd Jul 10, 2024
f58c531
Feat(eth-implicit-accounts): Stabilize protocol change
birchmd Jul 9, 2024
b1fff0c
Fix typo
birchmd Jul 15, 2024
c09b16f
Merge branch 'master' into fix/eth_wallet/audit
birchmd Jul 15, 2024
ba06adc
Fix(pytest): compare against testnet deployment by default. This is n…
birchmd Jul 15, 2024
195adef
Revert "Fix(pytest): compare against testnet deployment by default. T…
birchmd Jul 16, 2024
c6b44dc
Relax PEER_MIN_ALLOWED_PROTOCOL_VERSION by 1
staffik Jul 16, 2024
3c4379c
upgradeable relax
staffik Jul 16, 2024
fae3a0c
Merge branch 'master' into fix/eth_wallet/audit
birchmd Jul 16, 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Protocol Changes
* Congestion Control [NEP-0539](https://github.com/near/NEPs/pull/539)
* Stateless Validation [NEP-0509](https://github.com/near/NEPs/pull/509)
* Eth-Implicit Accounts [NEP-0518](https://github.com/near/NEPs/pull/518)

### Non-protocol Changes

Expand Down
4 changes: 2 additions & 2 deletions chain/chain/src/tests/simple_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ fn build_chain() {
if cfg!(feature = "nightly") {
insta::assert_snapshot!(hash, @"C3zeKRZubVungxfrSdq379TSCYnuz2YzjEkcJTdm3pU4");
} else {
insta::assert_snapshot!(hash, @"EKBbsbiindwuPwbiARE9LevUffurNhprbSaUjgPKCwEq");
insta::assert_snapshot!(hash, @"EeGa9BFTyrPoM56iZBteXZfhq86g4k1tjMCPprqYyfKF");
}

for i in 1..5 {
Expand All @@ -52,7 +52,7 @@ fn build_chain() {
if cfg!(feature = "nightly") {
insta::assert_snapshot!(hash, @"EjLaoHRiAdRp2NcDqwbMcAYYxGfcv5R7GuYUNfRpaJvB");
} else {
insta::assert_snapshot!(hash, @"9Ag5sa6bF9knuJKe9XECTKZi7HwtDhCSxCZ8P9AdSvWH");
insta::assert_snapshot!(hash, @"Em7E1W5xPMTToyiGbRAES2iAKJQDsZ5m8ymvy4S7adxu");
}
}

Expand Down
4 changes: 2 additions & 2 deletions chain/jsonrpc/jsonrpc-tests/res/genesis_config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"protocol_version": 69,
"protocol_version": 70,
"genesis_time": "1970-01-01T00:00:00.000000000Z",
"chain_id": "sample",
"genesis_height": 0,
Expand Down Expand Up @@ -75,4 +75,4 @@
"num_chunk_validator_seats": 300,
"chunk_producer_assignment_changes_limit": 5,
"records": []
}
}
2 changes: 1 addition & 1 deletion core/parameters/res/runtime_configs/parameters.snap
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ ed25519_verify true
alt_bn128 true
function_call_weight true
vm_kind NearVm
eth_implicit_accounts false
eth_implicit_accounts true
yield_resume true
discard_custom_sections false
max_congestion_incoming_gas 20_000_000_000_000_000
Expand Down
4 changes: 2 additions & 2 deletions core/parameters/src/config_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ static CONFIG_DIFFS: &[(ProtocolVersion, &str)] = &[
(68, include_config!("68.yaml")),
// Stateless Validation.
(69, include_config!("69.yaml")),
(129, include_config!("129.yaml")),
// Introduce ETH-implicit accounts.
(138, include_config!("138.yaml")),
(70, include_config!("70.yaml")),
(129, include_config!("129.yaml")),
(141, include_config!("141.yaml")),
(143, include_config!("143.yaml")),
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ expression: config_view
"ed25519_verify": true,
"alt_bn128": true,
"function_call_weight": true,
"eth_implicit_accounts": false,
"eth_implicit_accounts": true,
"yield_resume_host_functions": true,
"limit_config": {
"max_gas_burnt": 300000000000000,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ expression: config_view
"disable_9393_fix": false,
"discard_custom_sections": false,
"storage_get_mode": "FlatStorage",
"fix_contract_loading_cost": true,
"fix_contract_loading_cost": false,
"implicit_account_creation": true,
"math_extension": true,
"ed25519_verify": true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ expression: config_view
"ed25519_verify": true,
"alt_bn128": true,
"function_call_weight": true,
"eth_implicit_accounts": false,
"eth_implicit_accounts": true,
"yield_resume_host_functions": true,
"limit_config": {
"max_gas_burnt": 300000000000000,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ expression: config_view
"disable_9393_fix": false,
"discard_custom_sections": false,
"storage_get_mode": "FlatStorage",
"fix_contract_loading_cost": true,
"fix_contract_loading_cost": false,
"implicit_account_creation": true,
"math_extension": true,
"ed25519_verify": true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ expression: "&view"
"ed25519_verify": true,
"alt_bn128": true,
"function_call_weight": true,
"eth_implicit_accounts": false,
"eth_implicit_accounts": true,
"yield_resume_host_functions": true,
"limit_config": {
"max_gas_burnt": 300000000000000,
Expand Down
6 changes: 3 additions & 3 deletions core/primitives-core/src/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ impl ProtocolFeature {
| ProtocolFeature::ChangePartialWitnessDataPartsRequired
| ProtocolFeature::BiggerCombinedTransactionLimit
| ProtocolFeature::HigherSendingCost => 69,
ProtocolFeature::EthImplicitAccounts => 70,

// This protocol version is reserved for use in resharding tests. An extra resharding
// is simulated on top of the latest shard layout in production. Note that later
Expand All @@ -255,7 +256,6 @@ impl ProtocolFeature {
ProtocolFeature::FixContractLoadingCost => 129,
#[cfg(feature = "protocol_feature_reject_blocks_with_outdated_protocol_version")]
ProtocolFeature::RejectBlocksWithOutdatedProtocolVersions => 132,
ProtocolFeature::EthImplicitAccounts => 138,
#[cfg(feature = "protocol_feature_nonrefundable_transfer_nep491")]
ProtocolFeature::NonrefundableStorage => 140,
#[cfg(feature = "protocol_feature_bls12381")]
Expand All @@ -274,7 +274,7 @@ impl ProtocolFeature {
/// Current protocol version used on the mainnet.
/// Some features (e. g. FixStorageUsage) require that there is at least one epoch with exactly
/// the corresponding version
const STABLE_PROTOCOL_VERSION: ProtocolVersion = 69;
const STABLE_PROTOCOL_VERSION: ProtocolVersion = 70;

/// Largest protocol version supported by the current binary.
pub const PROTOCOL_VERSION: ProtocolVersion = if cfg!(feature = "statelessnet_protocol") {
Expand All @@ -291,7 +291,7 @@ pub const PROTOCOL_VERSION: ProtocolVersion = if cfg!(feature = "statelessnet_pr

/// Both, outgoing and incoming tcp connections to peers, will be rejected if `peer's`
/// protocol version is lower than this.
pub const PEER_MIN_ALLOWED_PROTOCOL_VERSION: ProtocolVersion = STABLE_PROTOCOL_VERSION - 2;
pub const PEER_MIN_ALLOWED_PROTOCOL_VERSION: ProtocolVersion = STABLE_PROTOCOL_VERSION - 3;

#[macro_export]
macro_rules! checked_feature {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ expression: "&view"
"ed25519_verify": true,
"alt_bn128": true,
"function_call_weight": true,
"eth_implicit_accounts": false,
"eth_implicit_accounts": true,
"yield_resume_host_functions": true,
"limit_config": {
"max_gas_burnt": 300000000000000,
Expand Down
6 changes: 6 additions & 0 deletions pytest/tests/sanity/upgradable.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ def get_proto_version(exe: pathlib.Path) -> int:
# increasing the protocol version by 2.
ok = (head_proto in (test_proto, test_proto + 1, test_proto + 2) and
test_proto in (main_proto, main_proto + 1, main_proto + 2))
elif head_proto == 70:
# Before stateless validation launch (protocol version 69) on mainnet,
# we have protocol version 70 stabilized in master, while mainnet protocol version is still 67.
ok = (head_proto in (test_proto, test_proto + 1, test_proto + 2,
test_proto + 3) and test_proto
in (main_proto, main_proto + 1, main_proto + 2, main_proto + 3))
else:
# Otherwise only allow increasing the protocol version by 1.
ok = (head_proto in (test_proto, test_proto + 1) and
Expand Down
13 changes: 7 additions & 6 deletions runtime/near-wallet-contract/implementation/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions runtime/near-wallet-contract/implementation/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,16 @@ aurora-engine-transactions = { version = "1.1", default-features = false, featur
base64 = "0.21"
ethabi = { version = "18", default-features = false }
hex = "0.4"
near-contract-standards = "5.0"
near-sdk = { version = "5.0" }
near-contract-standards = "5.1"
near-sdk = { version = "5.1" }
once_cell = "1.18"
serde = { version = "1", features = ["derive"] }

# dev-dependencies
anyhow = "1"
aurora-engine-types = { version = "1.1", default-features = false }
near-crypto = "0.21"
near-gas = "0.2"
near-workspaces = "0.10"
rlp = { version = "0.5", default-features = false }
serde_json = "1"
Expand All @@ -36,3 +37,4 @@ members = [

[profile.release]
panic = 'abort'
overflow-checks = true # keep overflow checks
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use near_sdk::{
borsh::{BorshDeserialize, BorshSerialize},
env, near_bindgen,
store::{lookup_map::Entry, LookupMap},
AccountId, BorshStorageKey, PanicOnDefault,
AccountId, BorshStorageKey, NearToken, PanicOnDefault,
};

type Address = [u8; 20];
Expand Down Expand Up @@ -33,7 +33,33 @@ impl AddressRegistrar {
/// previously registered one then the mapping is NOT updated and `None`
/// is returned. Otherwise, the mapping is stored and the address is
/// returned as a hex-encoded string with `0x` prefix.
#[payable]
pub fn register(&mut self, account_id: AccountId) -> Option<String> {
// It is not allowed to register eth-implicit accounts because the purpose
// of the registry is to allow looking up the named account associated with
// an address obtained via hashing, but eth-implicit accounts are already
// parsable as addresses.
if is_eth_implicit(&account_id) {
let log_message = format!("Refuse to register eth-implicit account {account_id}");
env::log_str(&log_message);
return None;
}

// Must store the address and the account id
let bytes_to_store = 20 + (account_id.len() as u128);
let required_deposit =
NearToken::from_yoctonear(env::storage_byte_cost().as_yoctonear() * bytes_to_store);
let given_deposit = env::attached_deposit();
// The caller must pay for the storage cost of registering.
if given_deposit < required_deposit {
let message = format!(
"Insufficient deposit to cover storage cost. Given={} Expected={}",
given_deposit.as_yoctonear(),
required_deposit.as_yoctonear(),
);
env::panic_str(&message);
}

let address = account_id_to_address(&account_id);

match self.addresses.entry(address) {
Expand All @@ -51,6 +77,9 @@ impl AddressRegistrar {
account_id
);
env::log_str(&log_message);
// Transfer the deposit back to the caller since no storage was updated.
let refund_promise = env::promise_batch_create(&env::predecessor_account_id());
env::promise_batch_action_transfer(refund_promise, given_deposit);
None
}
}
Expand Down Expand Up @@ -88,3 +117,8 @@ fn account_id_to_address(account_id: &AccountId) -> Address {
result.copy_from_slice(&hash[12..32]);
result
}

fn is_eth_implicit(account_id: &AccountId) -> bool {
let id = account_id.as_str();
id.len() == 42 && id.starts_with("0x") && id[2..].chars().all(|c| c.is_ascii_hexdigit())
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ serde_json.workspace = true
anyhow.workspace = true
aurora-engine-types.workspace = true
near-crypto.workspace = true
near-gas.workspace = true
near-workspaces.workspace = true
rlp.workspace = true
sha3.workspace = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ pub enum Error {
AccountId(AccountIdError),
Relayer(RelayerError),
User(UserError),
Caller(CallerError),
}

/// Errors that should never happen when the Eth Implicit accounts feature
Expand Down Expand Up @@ -39,6 +38,8 @@ pub enum RelayerError {
InvalidTarget,
/// Relayers should always check the transaction is signed with the correct chain id.
InvalidChainId,
/// Relayers should always attach at least as much gas as the user requested.
InsufficientGas,
}

/// Errors that arise from problems in the data signed by the user
Expand Down Expand Up @@ -71,17 +72,6 @@ pub enum UnsupportedAction {
Stake,
}

/// Errors that arise from external accounts calling the Wallet Contract.
/// The `rlp_execute` function is intentionally public so that any account
/// can pay for the fees on behalf of a Wallet Contract key holder.
/// These errors are not a big deal from the perspective of the Wallet Contract
/// because the cost for executing such erroneous transactions are paid for
/// by that external caller.
#[derive(Debug, PartialEq, Eq, Clone)]
pub enum CallerError {
InsufficientAttachedValue,
}

impl From<aurora_engine_transactions::Error> for Error {
fn from(value: aurora_engine_transactions::Error) -> Self {
Self::Relayer(RelayerError::TxParsing(value))
Expand Down Expand Up @@ -109,6 +99,7 @@ impl fmt::Display for RelayerError {
}
Self::InvalidNonce => f.write_str("Error: invalid nonce value"),
Self::InvalidChainId => f.write_str("Error: invalid chain id value"),
Self::InsufficientGas => f.write_str("Error: insufficient prepaid gas"),
}
}
}
Expand Down Expand Up @@ -142,24 +133,13 @@ impl fmt::Display for UserError {
}
}

impl fmt::Display for CallerError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::InsufficientAttachedValue => {
f.write_str("Error: external calls must attach Near to pay for their transactions")
}
}
}
}

impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::AccountNonceExhausted => f.write_str("Error: no nonce values remain"),
Self::AccountId(e) => e.fmt(f),
Self::Relayer(e) => e.fmt(f),
Self::User(e) => e.fmt(f),
Self::Caller(e) => e.fmt(f),
}
}
}
Expand Down
Loading
Loading