Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate signature error Tron #3993

Open
anton-yakimenko opened this issue Aug 20, 2024 · 0 comments
Open

Validate signature error Tron #3993

anton-yakimenko opened this issue Aug 20, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@anton-yakimenko
Copy link

Describe the bug
Hello! I got answer with tron transaction from dex-service Rango:
{
"ok": true,
"error": null,
"errorCode": null,
"traceId": null,
"transaction": {
"type": "TRON",
"blockChain": "TRON",
"isApprovalTx": false,
"raw_data": {
"contract": [
{
"parameter": {
"value": {
"data": "b24ebddb00000000000000000000000000000000000000000000000000000000005358eb000000000000000000000000000000000000000000000000000001916f9e0a17000000000000000000000000000000000000000000000000000000000253d2f0",
"owner_address": "4125f6835920fde416dc9b6b9ab76dea06e7dbc7b0",
"contract_address": "41a2726afbecbd8e936000ed684cef5e2f5cf43008",
"call_value": 39047920
},
"type_url": "type.googleapis.com/protocol.TriggerSmartContract"
},
"type": "TriggerSmartContract"
}
],
"ref_block_bytes": "3aac",
"ref_block_hash": "5c747ef87c3f9f35",
"expiration": 1724154573000,
"fee_limit": 1500000000,
"timestamp": 1724154514026
},
"raw_data_hex": "0a023aac22085c747ef87c3f9f3540c8e1fbfc96325ad401081f12cf010a31747970652e676f6f676c65617069732e636f6d2f70726f746f636f6c2e54726967676572536d617274436f6e74726163741299010a154125f6835920fde416dc9b6b9ab76dea06e7dbc7b0121541a2726afbecbd8e936000ed684cef5e2f5cf4300818f0a5cf122264b24ebddb00000000000000000000000000000000000000000000000000000000005358eb000000000000000000000000000000000000000000000000000001916f9e0a17000000000000000000000000000000000000000000000000000000000253d2f070ea94f8fc9632900180dea0cb05",
"externalTxId": null,
"payload": {
"owner_address": "4125f6835920fde416dc9b6b9ab76dea06e7dbc7b0",
"call_value": 39047920,
"contract_address": "41a2726afbecbd8e936000ed684cef5e2f5cf43008",
"fee_limit": 1500000000,
"function_selector": "trxToTokenSwapInput(uint256,uint256,uint256)",
"parameter": "00000000000000000000000000000000000000000000000000000000005358eb000000000000000000000000000000000000000000000000000001916f9e0a17000000000000000000000000000000000000000000000000000000000253d2f0",
"chainType": 0
},
"txID": "cd014f91d7a4e1408d5338b39d908b61d21dd630f65c70c43daee41a8ac30a44",
"visible": false
}
}

When I sign transaction and try to send, in result got error:
Validate signature error: 9830a120e0369096c8172ec19b398af8990ea531b820df57846929cca2cb6c844d59737ad2e2ba5fa1758acdafa37b414187ef32359b14bd0b0f99d1c7fc7a1900 is signed by TLzoQNmdkmfeJK96W4S8xXmYLQYK27xGUj but it is not contained of permission

To Reproduce
Example of my code:
func createRangoTronTransaction(amount: Decimal,
receiverAddress: String,
lastTronBlock: CheckTronLatestBlockResponse,
assetCode: String,
orderId: Int?,
decimalValue: Int) -> (tronModel: TronTransactionRequestModel?, signatureSize: Int)? {
let inputAmount = Int64(NSDecimalNumber(decimal: amount * pow(10, decimalValue)).intValue)
let timestamp = Date().currentTimeMillis()
let wallet = walletService?.getWallet()
guard let unwrapWallet = wallet else { return nil }
let privateKey = unwrapWallet.getKeyForCoin(coin: .tron).data

    let blockHeader = TronBlockHeader.with {
        $0.timestamp = (lastTronBlock.blockHeader.rawData.timestamp)
        $0.number = (lastTronBlock.blockHeader.rawData.number)
        $0.version = (lastTronBlock.blockHeader.rawData.version)
        $0.txTrieRoot =
        Data(hexString:lastTronBlock.blockHeader.rawData.txTrieRoot)!
        $0.parentHash =
        Data(hexString: lastTronBlock.blockHeader.rawData.parentHash)!
        $0.witnessAddress =
        Data(hexString: lastTronBlock.blockHeader.rawData.witnessAddress)!
    }
    
    let triggerSmart = TronTriggerSmartContract.with {
        $0.data = Data(hexStringToData(hex: "b24ebddb00000000000000000000000000000000000000000000000000000000005358eb000000000000000000000000000000000000000000000000000001916f9e0a17000000000000000000000000000000000000000000000000000000000253d2f0")!)
        $0.callValue = 39047920
        $0.ownerAddress = "TDRwKBiz5xSkGpPSpn6t3T6xdUYcfCDQjX"
        $0.contractAddress = "TQn9Y2khEsLJW1ChVWFMSMeRDow5KcbLSE"
    }
    
    let transaction = TronTransaction.with {
        $0.triggerSmartContract = triggerSmart
        $0.blockHeader = blockHeader
        $0.feeLimit = 50000000//feeLimit//70000000
        $0.timestamp = timestamp
        $0.expiration = timestamp + 10 * 60 * 60 * 1000
    }
    
    let input = TronSigningInput.with {
        $0.privateKey = privateKey
        $0.transaction = transaction
           }
    
    let output: TronSigningOutput =
    AnySigner.sign(input: input, coin: .tron)
    var trc20Model: TronTransactionRequestModel?
    do {
        let jsonData = output.json.data(using: .utf8)
        let tronTransactionModel =
        try JSONDecoder()
            .decode(TronTransactionRequestModel.self, from: jsonData!)
        trc20Model = tronTransactionModel
        
    } catch {
        print("Don't create TronTransactionRequestModel")
    }
    
    trc20Model?.raw_data.fee_limit = 50000000
    trc20Model?.tx_from = unwrapWallet.getAddressForCoin(coin: .tron)
    trc20Model?.tx_to = ""
    trc20Model?.code = "TRX"
    trc20Model?.value = 39047920
    trc20Model?.raw_data.contract[0].parameter.value.amount = 39047920
    trc20Model?.orderId = orderId
    let transActionSize = output.id.count + output.signature.count + output.refBlockBytes.count + output.refBlockHash.count
    return (tronModel: trc20Model, signatureSize: transActionSize)
}

Also I tried to sign transaction directly with txId, result was same:
let input = TronSigningInput.with {
$0.txID = "cd014f91d7a4e1408d5338b39d908b61d21dd630f65c70c43daee41a8ac30a44"
$0.transaction = transaction
}
I am sure then used valid and correct private key

Please help, where is problem in my code?

@anton-yakimenko anton-yakimenko added the bug Something isn't working label Aug 20, 2024
@trustwallet trustwallet deleted a comment Aug 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants
@anton-yakimenko and others