current position:Home>Check the Ethereum source code and find that the precompiled contract ecrecover has a devil number
Check the Ethereum source code and find that the precompiled contract ecrecover has a devil number
2022-02-03 20:53:38 【Q & A of Denglian community】
Check the Ethereum source code to find the precompiled contract ecrecover That is, the address is 0x01 In the precompiled contract of txHash and tx Medium R,V,S Extract signature tx Account for Addr There's a line in it v:= Input [63] ]-27 I can't understand what this subtraction is . In this case :``` func(c * ecrecover)Run(input [] byte)([] byte,error){ const ecRecoverInputLength = 128 input = common.RightPadBytes (input,ecRecoverInputLength) //“ Input ” by (hash,v,r,s), Every 32 byte // // about ecrecover, We want to (r,s,v) r:= new(big.Int).SetBytes( input [64:96]) s:= new(big.Int).SetBytes(input [96:128]) v:= input [63]-27 // todo I can't see it here // sig s The value input is more strict, only !allZero(input [32:63])|| Only applicable to tx The signal !crypto.ValidateSignatureValues(v,r,s,false){ return nil,nil }
// We must make sure not to modify 'input', So it will 'v' And Put the signatures together // Must be assigned in the new sig The complete := make([] byte,65) copy(sig,input [64:128]) sig [64] = v // v Must be in libsecp256k1 pubKey At the end of ,err:= crypto.Ecrecover(input [:32],sig) // Ensure that the public key is valid for one if err!= nil { return nil,nil } // pubkey The first byte of is bitcoin legacy return common.LeftPadBytes(crypto.Keccak256(pubKey [1:])[12:],32),nil } ``` Among them the first 11 OK, I don't understand ! This method is called by writing a firm contract in a cross contract manner ecrecover contract , It is found that the wallet address contract code that cannot be solved and signed is as follows :```
function ecrecov(bytes32 msgh,uint8 v,bytes32 r,bytes32 s) Public view returns ( Address ){ uint256 [4] Memory input ; Input [0] = uint256(msgh); Input [1] = v; Input [2] = uint256(r); Input [3] = uint256(s); uint256 [1] Memory retrieval ; uint256 success ; Assembly { success := staticcall(not(0),0x1,input,0x80,retval,32) } if( success != 1){ The return address (0); } The return address (retval [0]); } And I joined masHash and R,S,V Respectively from the transaction Tx:
{
blockHash:“ 0x18ccff43c8be8a7181ed714442d07601533dbdc34314c8fb970e7fb73347b022”, blockNumber:75605, come from :“ 0x493301712671ada506ba6ca7891f436d29185821”, gas:30000000, gasPrice:1000000000, hash:“ 0xdf09d680b7e7e0b
Input :0x608060405234801561001057600080fd5b50610461806100206000396000f3fe6080604052600436106100345760003560e01c806349ba3065146100395780638081a1e7146100d5578063bb8c256a14610160575b600080fd5b34801561004557600080fd5b506100936004803603608081101561005c57600080fd5b8101908080359060200190929190803560ff16906020019092919080359060200190929190803590602001909291905050506101e8565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b3480156100e157600080fd5b50610122600480360360608110156100f857600080fd5b810190808035906020019092919080359060200190929190803590602001909291905050506102a6565b6040518082600260200280838360005b8381101561014d578082015181840152602081019050610132565b5050505090500191505060405180910390f35b6101aa6004803603608081101561017657600080fd5b8101908080359060200190929190803590602001909291908035906020019092919080359060200190929190505050610318565b6040518082600260200280838360005b838110156101d55780820151818401526020810190506101ba565b5050505090500191505060405180910390f35b60006101f26103a4565b8560001c8160006004811061020357fe5b6020020181815250508460ff168160016004811061021d57fe5b6020020181815250508360001c8160026004811061023757fe5b6020020181815250508260001c8160036004811061025157fe5b6020020181815250506102626103c6565b60006020826080856001600019fa905060018114610286576000935050505061029e565b8160006001811061029357fe5b602002015193505050505b949350505050565b6102ae6103e8565b6102b661040a565b84816000600381106102c457fe5b60200201818152505083816001600381106102db57fe5b60200201818152505082816002600381106102f257fe5b6020020181815250506040826060836007600019fa61031057600080fd5b509392505050565b6103206103e8565b6103286103a4565b858160006004811061033657fe5b60200201”, random number :193, R: “0xad73c891a867d814e130e1f456ce024f21079a245a4bb5657122acf31a4454d5”, S: “0x603b0b8506aa7d8df97fd97c7d5c43fffc7904d9d07f4c3b3087354c28460840”, On : empty , transactionIndex:0, ν: “0xec”, value :0 } `` among msgHash use :
0xdf09d680671b085bb24454b7737d0b661a16bbe0e35cb331ef8eec90d7c2e77d,R Value :
0xad73c891a867d814e130e1f456ce024f21079a245a4bb5657122acf31a4454d5,S Value :
0x603b0b8506aa7d8df97fd97c7d5c43fffc7904d9d07f4c3b3087354c28460840,v Value :
0xec Parse failure . Does the great God know why , Or know the... In the precompiled contract 11 Yes
ν:= Input [63] - 27 ` Subtraction in 27 What is the operation ? My wallet Addr yes “ 0x493301712671ada506ba6ca7891f436d29185821”
Take the answer 1:
Look at your question , My mind is spinning .
copyright notice
author[Q & A of Denglian community],Please bring the original link to reprint, thank you.
https://en.netfreeman.com/2022/02/202202032053359431.html
The sidebar is recommended
- How to convert bytes type into address type in solidity
- How to distinguish between contract address and ordinary account address?
- Convert uint to bytes in solidity
- What does gas in Ethereum mean?
- How is the Ethereum contract address calculated?
- What Ethereum projects are suitable for beginners to learn solidity?
- Why create a new contract language, solid, instead of using other existing languages
- Can I get the hash of the transaction in the solidity function?
- How to delete an element at a certain position in an array in solidity?
- Does solid have a simple and universal storage model?
guess what you like
-
Solidity: what is the difference between 'view' and 'constant'?
-
How to determine whether a key exists in a mapping? Struct is defined in the library (in solidity).
-
How does Sha3 / keccak256 in solidity calculate the cell hash value?
-
Return and read a structure through Web3
-
How do I know the compiled version of solidity I'm using
-
What is an event?
-
Should we use the private matemask node
-
How to build a usdt wallet node based on erc20
-
ZK snark how to set CRS if there is cyclic logic in the circuit
-
Teacher, I got the value with Web3 according to your video tutorial, but when calling setinfo with Web3, an error is reported when the set value is set. What is the reason?
Random recommended
- When setting the default initiating account, the console reports an error: Web3 eth. defaultAccounts is not a function
- Accounts has been unable to get the local address.
- Metamask is connected to the local network. Why can't Web3 use the default address?
- Write the code in and still can't get the address. Is it related to my network? I've been using metamask reponste3 to test the network, but the local network 8545 can't be connected
- Setinfo is called successfully, but an error will be reported after success. What is the reason?
- Use the Ganache local node to prompt that the introduction of Web3 is successful. But you can't use Web3's method
- Solid returns cannot return results
- Why did I get an error initializing the genesis block.
- Why do I start the RPC service of geth node and send a request to the node without response from the terminal?
- How to solve the problem of displaying errors in the constructor of solidity because of the version of vs Code?
- The new version of truss initializes test with init. There are no files in test. Is it a version problem?
- What do you think of the time it takes to call a contract
- Problems encountered initializing folders with truss init. Prompt: how to solve the problem of unable to connect to the network
- What is the solution
- When compiling the contract, the terminal input truss compile is stuck and cannot be compiled successfully
- What is the problem that the version of the solid compiler cannot be matched after the truss compile prompt
- After downloading the truss again, the problem of Solc compiling environment will not be prompted, but the output error will be displayed. Why?
- Interact with the contract in the truss console, and call Web3 when passing parameters The toWei hint is not a function
- Building usdt wallet node based on erc20
- Why is there a promise syntax error when it is written like this? It shows that the listener function is undecided. Obviously, a contract instance has been successfully introduced.
- The wallet can be connected to metamask and Ganache to obtain balance, but the balance connected to get is 0
- How do contracts simulate the passage of time?
- How to use private key offline signature to initiate a contract call transaction?
- Why does nonce in eth trading have to be continuous? I think it's bigger than the current one. Please solve your doubts???
- When the third parameter is passed, the web console reports an error and votes for the third candidate. Metamask is not approved, but it is OK to delete the third parameter "Jose".
- How does solidity calculate the square root of a number?
- What's the use of solidity contract address?
- How to ensure that the information collected by each node is consistent in the generation of a block?
- How to use different users to call contract functions in truffle console
- How to use the call, callcode, and delegatecall functions called by the solidity contract?
- How to assign and deploy constructor parameters in geth console?
- How to use the keyword "solid payable"?
- How to construct offline transaction for bitcoin isolation address
- Ganache installation problem
- The "gas deduction" function appears in the "solid require" function?
- How does a smart contract receive Ethernet?
- Metamask transfer error
- Etherscan has been blocked. What alternative blockchain browser is available?
- Bitcoin 6 block confirmation problem
- When mining with code, why do you have to convert it into JSON format and sort it when hashing?