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

Fix verify_log_entry call #53

Merged
merged 1 commit into from
May 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 3 additions & 5 deletions eth-connector/src/connector.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
use crate::{connector_impl::FinishDepositCallArgs, Proof, WithdrawResult};
use crate::{connector_impl::FinishDepositCallArgs, Proof, VerifyProofArgs, WithdrawResult};
use aurora_engine_types::types::Address;
use near_contract_standards::storage_management::StorageBalance;
use near_sdk::json_types::U64;
use near_sdk::{
borsh, ext_contract,
json_types::{Base64VecU8, U128},
AccountId, Balance, Promise, PromiseOrValue,
borsh, ext_contract, json_types::U128, AccountId, Balance, Promise, PromiseOrValue,
};

#[ext_contract(ext_deposit)]
Expand Down Expand Up @@ -37,7 +35,7 @@ pub trait FundsFinish {
#[ext_contract(ext_proof_verifier)]
pub trait ProofVerifier {
#[result_serializer(borsh)]
fn verify_log_entry(&self, #[serializer(borsh)] raw_proof: Base64VecU8) -> bool;
fn verify_log_entry(&self, #[serializer(borsh)] args: VerifyProofArgs) -> bool;
}

#[ext_contract(ext_ft_statistic)]
Expand Down
13 changes: 4 additions & 9 deletions eth-connector/src/connector_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ use near_sdk::{
};

/// NEAR Gas for calling `finish_deposit` promise. Used in the `deposit` logic.
pub const GAS_FOR_FINISH_DEPOSIT: Gas = Gas(50_000_000_000_000);
pub const GAS_FOR_FINISH_DEPOSIT: Gas = Gas(50 * Gas::ONE_TERA.0);
/// NEAR Gas for calling `verify_log_entry` promise. Used in the `deposit` logic.
// Note: Is 40 TGas always enough?
const GAS_FOR_VERIFY_LOG_ENTRY: Gas = Gas(40_000_000_000_000);
const GAS_FOR_VERIFY_LOG_ENTRY: Gas = Gas(40 * Gas::ONE_TERA.0);

/// transfer eth-connector call args
#[derive(Debug, Clone, BorshSerialize, BorshDeserialize, PartialEq, Eq)]
Expand Down Expand Up @@ -84,7 +84,7 @@ impl AdminControlled for EthConnector {
}

impl EthConnector {
pub(crate) fn deposit(&mut self, proof: &Proof) -> Promise {
pub(crate) fn deposit(&mut self, proof: Proof) -> Promise {
mrLSD marked this conversation as resolved.
Show resolved Hide resolved
let current_account_id = env::current_account_id();

// Check is current flow paused. If it's owner account just skip it.
Expand Down Expand Up @@ -118,11 +118,6 @@ impl EthConnector {
self.prover_account,
);

// Do not skip bridge call. This is only used for development and diagnostics.
let skip_bridge_call = false.try_to_vec().unwrap();
mrLSD marked this conversation as resolved.
Show resolved Hide resolved
let mut proof_to_verify = proof.try_to_vec().unwrap();
proof_to_verify.extend(skip_bridge_call);

// Finalize deposit
let finish_deposit_data = match event.token_message_data {
// Deposit to NEAR accounts
Expand Down Expand Up @@ -161,7 +156,7 @@ impl EthConnector {

ext_proof_verifier::ext(self.prover_account.clone())
.with_static_gas(GAS_FOR_VERIFY_LOG_ENTRY)
.verify_log_entry(proof_to_verify.into())
.verify_log_entry(proof.into())
.then(
ext_funds_finish::ext(current_account_id)
.with_static_gas(GAS_FOR_FINISH_DEPOSIT)
Expand Down
24 changes: 12 additions & 12 deletions eth-connector/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::connector_impl::{
EthConnector, FinishDepositCallArgs, TransferCallCallArgs, WithdrawResult,
};
use crate::deposit_event::FtTransferMessageData;
use crate::proof::Proof;
use crate::proof::{Proof, VerifyProofArgs};
use crate::types::{panic_err, SdkUnwrap};
use aurora_engine_types::types::Address;
use near_contract_standards::fungible_token::core::FungibleTokenCore;
Expand Down Expand Up @@ -40,8 +40,8 @@ pub mod migration;
pub mod proof;
pub mod types;

const GAS_FOR_RESOLVE_TRANSFER: Gas = Gas(5_000_000_000_000);
const GAS_FOR_FT_TRANSFER_CALL: Gas = Gas(25_000_000_000_000 + GAS_FOR_RESOLVE_TRANSFER.0);
const GAS_FOR_RESOLVE_TRANSFER: Gas = Gas(5 * Gas::ONE_TERA.0);
const GAS_FOR_FT_TRANSFER_CALL: Gas = Gas(25 * Gas::ONE_TERA.0 + GAS_FOR_RESOLVE_TRANSFER.0);

/// Eth-connector contract data. It's stored in the storage.
/// Contains:
Expand Down Expand Up @@ -170,7 +170,6 @@ impl EthConnectorContract {
account_with_access_right: AccountId,
owner_id: &AccountId,
) -> Self {
require!(!env::state_exists(), "Already initialized");
mrLSD marked this conversation as resolved.
Show resolved Hide resolved
metadata.assert_valid();

// Get initial Eth Connector arguments
Expand Down Expand Up @@ -208,7 +207,8 @@ impl EthConnectorContract {
#[cfg(feature = "integration-test")]
#[result_serializer(borsh)]
#[must_use]
pub fn verify_log_entry() -> bool {
#[allow(unused_variables)]
pub fn verify_log_entry(#[serializer(borsh)] proof_args: &VerifyProofArgs) -> bool {
log!("Call from verify_log_entry");
true
}
Expand Down Expand Up @@ -547,8 +547,8 @@ impl EngineConnectorWithdraw for EthConnectorContract {

#[near_bindgen]
impl Deposit for EthConnectorContract {
fn deposit(&mut self, #[serializer(borsh)] raw_proof: Proof) -> Promise {
self.connector.deposit(&raw_proof)
fn deposit(&mut self, #[serializer(borsh)] proof: Proof) -> Promise {
self.connector.deposit(proof)
mrLSD marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down Expand Up @@ -577,15 +577,15 @@ impl FundsFinish for EthConnectorContract {
deposit_call.msg.map_or_else(
|| PromiseOrValue::Value(None),
|msg| {
let data: TransferCallCallArgs = TransferCallCallArgs::try_from_slice(&msg)
let args = TransferCallCallArgs::try_from_slice(&msg)
.map_err(|_| crate::errors::ERR_BORSH_DESERIALIZE)
.sdk_unwrap();
let promise = self.internal_ft_transfer_call(
env::predecessor_account_id(),
data.receiver_id,
data.amount.into(),
data.memo,
data.msg,
args.receiver_id,
args.amount.into(),
args.memo,
args.msg,
);
match promise {
PromiseOrValue::Promise(p) => PromiseOrValue::Promise(p),
Expand Down
25 changes: 25 additions & 0 deletions eth-connector/src/proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,31 @@ impl Proof {
}
}

#[derive(BorshDeserialize, BorshSerialize)]
pub struct VerifyProofArgs {
pub log_index: u64,
pub log_entry_data: Vec<u8>,
pub receipt_index: u64,
pub receipt_data: Vec<u8>,
pub header_data: Vec<u8>,
pub proof: Vec<Vec<u8>>,
pub skip_bridge_call: bool,
}

impl From<Proof> for VerifyProofArgs {
fn from(value: Proof) -> Self {
Self {
log_index: value.log_index,
log_entry_data: value.log_entry_data,
receipt_index: value.receipt_index,
receipt_data: value.receipt_data,
header_data: value.header_data,
proof: value.proof,
skip_bridge_call: false,
}
}
}

#[cfg(test)]
mod tests {
use super::Proof;
Expand Down