I know that when smart contracts run in Ethereum, there are parts that create and runtime, and use function selector to find and execute body of function.
I have built geth on my computer from a source code, and then modified to print the running opcode.
After that, I compiled the following smart country contents and made a js file.
contract A {
uint num;
constructor (uint n) public {
num = n;
}
function add(uint n) public {
num += n;
}
function nums() public view returns (uint) {
return num;
}
}
js file is like,
var aBin="608060405234801561001057600080fd5b506040516101293803806101298339818101604052602081101561003357600080fd5b8101908080519060200190929190505050806000819055505060cf8061005a6000396000f3fe6080604052348015600f57600080fd5b506004361060325760003560e01c80631003e2d2146037578063d5b13259146062575b600080fd5b606060048036036020811015604b57600080fd5b8101908080359060200190929190505050607e565b005b60686090565b6040518082815260200191505060405180910390f35b80600080828254019250508190555050565b6000805490509056fea264697066735822122021d02222a0c22422593d1d3ea567fddf11eff7a3a15eeb52997e7e8fc164ea6464736f6c63430006010033"
var aAbi =[{"inputs": [{"internalType": "uint256","name": "n","type": "uint256" }], "stateMutability": "no npayable","type": "constructor"}, {"inputs": [{"internalType": "uint256", "name": "n","type": "uint256"}], "name": "add","outputs": [],"stateMutability": "nonpayable","type": "function"},{"inputs": [],"name": "num s","outputs": [{"internalType": "uint256","name": "", "type": "uint256"}],"stateMutability": "view","type" : "function"}]
And,
> loadScript("test1/A.js")
true
> var aAbi = aAbi
undefined
> var aBin = '0x'+aBin
undefined
> var conA = eth.contract(aAbi)
undefined
> personal.unlockAccount(eth.accounts[0], "*mypassword*")
true
> var contractA = conA.new(2,{from:eth.accounts[0], data:aBin, gas:'7000000'})
when I try to execute add function,
> contractA.add.call(1)
Opcodes looks like this
[op: PUSH1, operation: 943840]
[op: PUSH1, operation: 943840]
[op: MSTORE, operation: 93ee00]
[op: CALLVALUE, operation: 93c020]
[op: DUP1, operation: 94c830]
[op: ISZERO, operation: 9398f0]
[op: PUSH1, operation: 943840]
[op: JUMPI, operation: 93f570]
[op: JUMPDEST, operation: 93f720]
[op: POP, operation: 93ebe0]
[op: PUSH1, operation: 943840]
[op: CALLDATASIZE, operation: 93c500]
[op: LT, operation: 938d10]
[op: PUSH1, operation: 943840]
[op: JUMPI, operation: 93f570]
[op: PUSH1, operation: 943840]
[op: CALLDATALOAD, operation: 93c2d0]
[op: PUSH1, operation: 943840]
[]
If you look at the output opcode, it was finished before reach to function selector.
If performed correctly, ADD opcode should exist but is not visible in the output results.
What do I have to do to execute function?