Skip to content

Commit

Permalink
Node::execute() double check contract is actually locked
Browse files Browse the repository at this point in the history
  • Loading branch information
madMAx43v3r committed Aug 2, 2024
1 parent fe41507 commit 1ca011a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
6 changes: 3 additions & 3 deletions include/mmx/Node.h
Original file line number Diff line number Diff line change
Expand Up @@ -236,9 +236,9 @@ class Node : public NodeBase {
struct execution_context_t {
uint32_t height = 0;
std::shared_ptr<vm::StorageCache> storage;
std::unordered_map<addr_t, std::vector<hash_t>> mutate_map;
std::unordered_map<hash_t, std::unordered_set<hash_t>> wait_map;
std::unordered_map<hash_t, std::shared_ptr<waitcond_t>> signal_map;
std::unordered_map<addr_t, std::vector<hash_t>> mutate_map; // [contract => TX ids]
std::unordered_map<hash_t, std::unordered_set<hash_t>> wait_map; // [TX id => TX ids]
std::unordered_map<hash_t, std::shared_ptr<waitcond_t>> signal_map; // [TX id => condition]
void wait(const hash_t& txid) const;
void signal(const hash_t& txid) const;
void setup_wait(const hash_t& txid, const addr_t& address);
Expand Down
10 changes: 10 additions & 0 deletions src/Node_validate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,16 @@ void Node::execute( std::shared_ptr<const Transaction> tx,
const std::string& method_name,
exec_error_t& error, const bool is_public) const
{
{
auto iter = context->mutate_map.find(engine->contract);
if(iter == context->mutate_map.end()) {
throw std::logic_error("contract not locked");
}
const auto& list = iter->second;
if(std::find(list.begin(), list.end(), tx->id) == list.end()) {
throw std::logic_error("transaction did not lock contract: " + engine->contract.to_string());
}
}
const auto binary = get_contract_as<contract::Binary>(executable->binary, &engine->gas_used, engine->gas_limit);
if(!binary) {
throw std::logic_error("no such binary: " + executable->binary.to_string());
Expand Down

0 comments on commit 1ca011a

Please sign in to comment.