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.

Random recommended