Gas Calculation Problem

I have some trivial contract and a simple transaction with one parameter and it is estimated for more than a MILLION of gas needed.... It looks like a bug for me. What is wrong here?


tr.tiff 90.6K

Comments

  • AlexNaAlexNa Member Posts: 32
    Here is the screenshot


    tr.jpg 69.3K
  • gavofyorkgavofyork Member Posts: 14 ✭✭
    Could you post the code you used to make the contract you're sending the transaction to?
  • AlexNaAlexNa Member Posts: 32
    edited April 2015
    Here is the contract:
    
    {
    	;( def NameReg 0xd5ccd26ba09ce1d85148b5081fa3ed77949417be )
    
    	; Initialization
    	[[0x0]]  (caller) 	; Admin
    	[[0x1]]  "CryptoRPS"	 
    	[[0x2]]  2 			; Status: 0 - completed , 1 - active, 2 - paused
    	[[0x3]]  0x0 		; Round number
    	[[0x4]]  4   		; Needed bets
    	[[0x5]]  1000000000000000000		; Min bet (in weis)
    	[[0x6]]  (NUMBER) 	; Start block of round
    	[[0x7]]  0 			; Number of bets
    	[[0x8]]  0   		; Total bets
    	[[0x9]]  0   		; Public Key ( part 1 )
    	[[0xa]]  0   		; Public Key ( part 2 )
    	[[0xb]]  0   		; Public Key ( part 3 )
    	[[0xc]]  15000000000000000000   		; Jack Pot
    	[[0xd]]  50   		; Jack Pot percentage
    	[[0xe]]  70   		; Jack Pot payment percentage
    	[[0xf]]  10000000000000000   		; Jack Pot bet
    	[[0x10]] 10   		; Jack Pot needed bits
    	
        (def "owner"        0x0 )
        (def "sign"         0x1 )
        (def "status"       0x2 )
        (def "round_number" 0x3 )
        (def "needed_bets"  0x4 )
        (def "min_bet"      0x5 )
        (def "start_block"  0x6 )
        (def "n_bets"       0x7 )
        (def "total_bets"   0x8 )
        (def "pk1"          0x9 )
        (def "pk2"          0xa )
        (def "pk3"          0xb )
        (def "jp"           0xc )
        (def "jp_percentage" 0xd )
        (def "jp_payment_percentage" 0xe )
        (def "jp_bet"       0xf )
        (def "jp_needed_bits" 0x10 )
        
        (def "table_offset" 0x100 )
    
        (def "txCommand"    (calldataload 0) )
        (def "txParam"      (calldataload 0x20) )
        (def "txParam1"     (calldataload 0x20) )
        (def "txParam2"     (calldataload 0x40) )
        (def "txParam3"     (calldataload 0x60) )
        (def "txParam4"     (calldataload 0x80) )
    
    	; [0x0]: "CRPS" ; Name of the contract
    	; (call NameReg 0 0 0 13 0 0) ;Register with name registration
    
    ( return 0 ( lll {
    
        ; local variables
        (def "bet_is_placed" 0x0 )
        (def "ptr" 0x20 )
        (def "actual_bet" 0x40 )
                         
        [ bet_is_placed ] 0
                         
    ;---------------------------------------------------
    ;   Admin Commands
    ;---------------------------------------------------
        ( when (= (caller) @@owner) 
     		{
                ( when (&& (= txCommand "start_round") (= @@status 0 ) ) { ; only when the previous is completed
                    ( when (= txParam1 (+ @@round_number 1 ) ) { ; only for the correct round number
                        [[ status ]] 1   ; active
                        [[ round_number ]] txParam1
                        [[ start_block ]] (NUMBER)
                        [[ n_bets ]] 0
                        [[ total_bets ]] 0
                        [[ pk1 ]] txParam2
                        [[ pk2 ]] txParam3
                        [[ pk3 ]] txParam4
                    })
                })
            
    	        ( when (= txCommand "set_status") { 
                   [[ status ]] txParam 
                   } )
    
                ( when (= txCommand "set_jp") { 
                   [[ jp ]] txParam 
                   } )
    
                ( when (= txCommand "set_jp_bet") { 
                   [[ jp_bet ]] txParam 
                   } )
        
                ( when (= txCommand "set_jp_needed_bits") { 
                   [[ jp_needed_bits ]] txParam 
                   } )
        
                ( when (= txCommand "set_jp_percentage") { 
                   [[ jp_percentage ]] txParam 
                   } )
        
                ( when (= txCommand "set_jp_payment_percentage") { 
                   [[ jp_payment_percentage ]] txParam 
                   } )
        
                ( when  (= txCommand "set_needed_bets")
    	           {
                        when(> txParam 3 ) 
                            {
                                [[needed_bets]] txParam
                            }                
    	           })
    
                ( when (= txCommand "set_min_bets")	{ 
                        [[ min_bet]] txParam 
                    })
    
                ( when  (&& (= txCommand "kill") (= @@status 0 ) ) ; only kill if the round is completed
    	    	  {
    				;(call NameReg 0 0 0 0 0 0) ; deregister
    	        	(suicide @@0)
    	           })
    
    
    ;---------------------------------------------------
    ;   General Commands
    ;---------------------------------------------------
            ( when (= txCommand "bet")  
            {     
                [ actual_bet ] ( callvalue )
                ( when (> txParam4 0 ) ; bet for Jack Pot
                {
                    [ actual_bet ] (- @actual_bet @@jp_bet )
                })            
                
                ( when (>= @actual_bet @@min_bet ) {
                    ( when (&& (= @@status 1 ) (= @@round_number txParam1) ) {  ; round is correct and active
                        ( when (< @@n_bets @@needed_bets ) {                    ; not all bets are done yet
                            [ ptr ] (* @@n_bets 5 )
                            [ ptr ] (+ table_offset @ptr )
                            [[ (+ @ptr 0) ]] ( caller )
                            [[ (+ @ptr 1) ]] ( callvalue )
                            [[ (+ @ptr 2) ]] txParam2   ; encrypted value 1
                            [[ (+ @ptr 3) ]] txParam3   ; encrypted value 2
                            [[ (+ @ptr 4) ]] txParam4   ; jp on
    
                            [[ total_bets ]] (+ @@total_bets ( callvalue ) )
                            [[ n_bets ]] (+ @@n_bets 1 )
                            [ bet_is_placed ] 1
                            })
                        })
                    })
                })
    
        	})
    
    ;---------------------------------------------------
    ;   Final steps
    ;---------------------------------------------------
            ( when (&& (> callvalue 0 ) (= @bet_is_placed 0) ) { ; return the money
                (send caller callvalue )
            });
    
      	} 0))
    
    }
    
    Post edited by StephanTual on
  • StephanTualStephanTual London, EnglandMember, Moderator Posts: 1,282 mod
    Note that I edited the post above to make use of the <code> markup :)
  • AlexNaAlexNa Member Posts: 32
    edited April 2015
    Nice, thank you. What about the resolution for the problem? It is not just the estimation. The transaction does not work and if I try to debug it, the whole AlethZero crashes...
  • gavofyorkgavofyork Member Posts: 14 ✭✭
    difficult to say. generally try to comment out conditions in your code to track down what is causing the large amount of gas required. definitely place parens around caller and callvalue, like you did with NUMBER. post an issue with for the AlethZero with reproduction instructions from a clean chain and i'll get round to it eventually :-)
  • AlexNaAlexNa Member Posts: 32
    edited April 2015
    Yes, the parents fixed the problem. All I did, I changed this:
    
            ( when (&& (> callvalue 0 ) (= @bet_is_placed 0) ) { ; return the money
                (send caller callvalue )
            });
    To this:
    
            ( when (&& (> ( callvalue ) 0 ) (= @bet_is_placed 0) ) { ; return the money
                (send ( caller ) ( callvalue ) )
            });
    Syntactically it should be the same. So I still think it was a bug.

    Anyway, thank you Gav.
Sign In or Register to comment.