Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

[FIX] Refine isContract call to support Present design #158

Closed
wants to merge 1 commit into from
Closed
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
25 changes: 15 additions & 10 deletions lib/statemanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -883,15 +883,20 @@ StateManager.prototype.createFakeTransactionWithCorrectNonce = function(rawTx, f

// If we're calling a contract, check to make sure the address specified is a contract address
if (_transactionIsContractCall(rawTx)) {
self.getCode(to.hex(rawTx.to), 'latest', function(err, code) {
if (err) {
callback(err);
} else if (code === '0x0') {
callback(new TXRejectedError(`Attempting to run transaction which calls a contract function, but recipient address ${to.hex(rawTx.to)} is not a contract address`))
} else {
callback(null, tx)
}
});
// Contract just being deployed, code yet to exist at adress
if (!rawTx.to || rawTx.to === '0x0' || rawTx.to === '0x' || rawTx.to === '0') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW, I think contract deployment only happens when the to field is completely missing. It's completely valid to send a transaction with data to address zero.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That said, to is a DATA field (per the RPC wiki), so the zero-length value of 0x should probably also be considered a contract deployment.

callback(null, tx)
} else {
self.getCode(to.hex(rawTx.to), 'latest', function(err, code) {
if (err) {
callback(err);
} else if (code === '0x0') {
callback(new TXRejectedError(`Attempting to run transaction which calls a contract function, but recipient address ${to.hex(rawTx.to)} is not a contract address`))
} else {
callback(null, tx)
}
});
}
} else {
callback(null, tx)
}
Expand All @@ -903,6 +908,6 @@ var _transactionIsContractCall = function(rawTx) {
let recipient = to.hex(rawTx.to || '0x0')
let data = to.hex(rawTx.data || '0x0')

return recipient !== '0x0' && data !== '0x0'
return recipient === '0x0' || recipient === '0x' || recipient === '0' || data !== '0x0'
}
module.exports = StateManager;