Skip to content

Commit

Permalink
EVM invoke WIP (1)
Browse files Browse the repository at this point in the history
  • Loading branch information
valdok committed Sep 18, 2023
1 parent 756ed92 commit 32d33c7
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 17 deletions.
23 changes: 9 additions & 14 deletions core/block_crypt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1535,6 +1535,7 @@ namespace beam
v.m_To = m_To;
v.m_Nonce = m_Nonce;
v.m_Amount = m_Amount;
v.m_Subsidy = m_Subsidy;
}

void TxKernelEvmInvoke::HashSelfForMsg(ECC::Hash::Processor& hp) const
Expand All @@ -1544,7 +1545,8 @@ namespace beam
<< m_From
<< m_To
<< m_Nonce
<< m_Amount;
<< m_Amount
<< static_cast<Amount>(m_Subsidy);
}

void TxKernelEvmInvoke::TestValid(Height hScheme, ECC::Point::Native& exc, const TxKernel* pParent /* = nullptr */) const
Expand All @@ -1558,27 +1560,20 @@ namespace beam
pComm[0].ImportNnzStrict(m_Commitment);
exc += pComm[0];

bool bFromBlock = (m_From == Zero);
bool bToBlock = (m_To == Zero);

if (m_Amount && (bFromBlock != bToBlock))
if (m_Subsidy)
{
bool isPositive;
Amount val = SplitAmountSigned(m_Subsidy, isPositive);

ECC::Mode::Scope scope(ECC::Mode::Fast);

pComm[1] = ECC::Context::get().H * m_Amount;
if (bFromBlock)
pComm[1] = ECC::Context::get().H * val;
if (isPositive)
pComm[1] = -pComm[1];

pComm[0] += pComm[1];
}


if (bFromBlock)
{
if (!m_Signature.IsValid(m_Internal.m_ID, pComm[0]))
TxBase::Fail_Signature();
}
else
{
auto& s = Cast::Down<ECC::SignatureBase>(m_Signature);

Expand Down
3 changes: 2 additions & 1 deletion core/block_crypt.h
Original file line number Diff line number Diff line change
Expand Up @@ -1249,9 +1249,10 @@ namespace beam
:public TxKernelContractControl
{
ECC::uintBig m_From;
ECC::uintBig m_To;
uintBig_t<20> m_To;
uint64_t m_Nonce; // not necessary
Amount m_Amount;
AmountSigned m_Subsidy;

typedef std::unique_ptr<TxKernelEvmInvoke> Ptr;

Expand Down
6 changes: 4 additions & 2 deletions core/serialization_adapters.h
Original file line number Diff line number Diff line change
Expand Up @@ -1714,7 +1714,8 @@ namespace detail
& val.m_From
& val.m_To
& val.m_Nonce
& val.m_Amount;
& val.m_Amount
& val.m_Subsidy;
return ar;
}

Expand All @@ -1726,7 +1727,8 @@ namespace detail
& val.m_From
& val.m_To
& val.m_Nonce
& val.m_Amount;
& val.m_Amount
& val.m_Subsidy;
}

/// beam::Transaction serialization
Expand Down

0 comments on commit 32d33c7

Please sign in to comment.