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

cost estimation: discrepancy between budget and resources #1421

Open
tomerweller opened this issue Dec 27, 2024 · 0 comments
Open

cost estimation: discrepancy between budget and resources #1421

tomerweller opened this issue Dec 27, 2024 · 0 comments

Comments

@tomerweller
Copy link

tomerweller commented Dec 27, 2024

This might just be a gap in my understanding but for a given invocation that errors on budget exceeded, the number of instructions in resources does not match the number of instructions in budget. More specifically, the resources instructions count does not seem to take into account the BLS cost types in this specific invocation.

This is for a single invocation and I reset the budget before it so expected the instruction numbers to be equal.

std::println!("{:#?}", e.cost_estimate().resources());
InvocationResources {
    instructions: 1249108,
    mem_bytes: 1400159,
    read_entries: 1,
    write_entries: 2,
    read_bytes: 3672,
    write_bytes: 54092,
    contract_events_size_bytes: 0,
    persistent_rent_ledger_bytes: 221080860,
    persistent_entry_rent_bumps: 2,
    temporary_rent_ledger_bytes: 0,
    temporary_entry_rent_bumps: 0,
}
std::println!("{:#?}", e.cost_estimate().budget());`
===============================================================================================================================================================================
Cpu limit: 100000000; used: 100127383
Mem limit: 41943040; used: 1630623
===============================================================================================================================================================================
CostType                           iterations     input          cpu_insns      mem_bytes      const_term_cpu      lin_term_cpu        const_term_mem      lin_term_mem        
WasmInsnExec                       1988454        None           7953816        0              4                   0                   0                   0                   
MemAlloc                           4722           Some(1363107)  2219731        1438659        434                 16                  16                  128                 
MemCpy                             3741           Some(244828)   187713         0              42                  16                  0                   0                   
MemCmp                             43             Some(906)      1989           0              44                  16                  0                   0                   
DispatchHostFunction               3115           None           965650         0              310                 0                   0                   0                   
VisitObject                        7813           None           476593         0              61                  0                   0                   0                   
ValSer                             0              Some(0)        0              0              230                 29                  242                 384                 
ValDeser                           0              Some(0)        0              0              59052               4001                0                   384                 
ComputeSha256Hash                  1              Some(0)        3738           0              3738                7012                0                   0                   
ComputeEd25519PubKey               0              None           0              0              40253               0                   0                   0                   
VerifyEd25519Sig                   0              Some(0)        0              0              377524              4068                0                   0                   
VmInstantiation                    0              Some(0)        0              0              451626              45405               130065              5064                
VmCachedInstantiation              0              Some(0)        0              0              41142               634                 69472               1217                
InvokeVmFunction                   1              None           1948           14             1948                0                   14                  0                   
ComputeKeccak256Hash               0              Some(0)        0              0              3766                5969                0                   0                   
DecodeEcdsaCurve256Sig             0              None           0              0              710                 0                   0                   0                   
RecoverEcdsaSecp256k1Key           0              None           0              0              2315295             0                   181                 0                   
Int256AddSub                       0              None           0              0              4404                0                   99                  0                   
Int256Mul                          0              None           0              0              4947                0                   99                  0                   
Int256Div                          0              None           0              0              4911                0                   99                  0                   
Int256Pow                          0              None           0              0              4286                0                   99                  0                   
Int256Shift                        0              None           0              0              913                 0                   99                  0                   
ChaCha20DrawBytes                  0              Some(0)        0              0              1058                501                 0                   0                   
ParseWasmInstructions              1              Some(1077)     286878         71893          73077               25410               17564               6457                
ParseWasmFunctions                 1              Some(17)       71818          6303           0                   540752              0                   47464               
ParseWasmGlobals                   1              Some(3)        4133           314            0                   176363              0                   13420               
ParseWasmTableEntries              1              Some(0)        0              0              0                   29989               0                   6285                
ParseWasmTypes                     1              Some(12)       99510          6062           0                   1061449             0                   64670               
ParseWasmDataSegments              1              Some(1)        1854           227            0                   237336              0                   29074               
ParseWasmElemSegments              1              Some(0)        0              0              0                   328476              0                   48095               
ParseWasmImports                   1              Some(15)       82247          12097          0                   701845              0                   103229              
ParseWasmExports                   1              Some(7)        23481          1990           0                   429383              0                   36394               
ParseWasmDataSegmentBytes          1              Some(164)      35             329            0                   28                  0                   257                 
InstantiateWasmInstructions        1              None           43030          70704          43030               0                   70704               0                   
InstantiateWasmFunctions           1              Some(17)       1003           1940           0                   7556                0                   14613               
InstantiateWasmGlobals             1              Some(3)        251            160            0                   10711               0                   6833                
InstantiateWasmTableEntries        1              Some(0)        0              0              0                   3300                0                   1025                
InstantiateWasmTypes               1              None           0              0              0                   0                   0                   0                   
InstantiateWasmDataSegments        1              Some(1)        179            1012           0                   23038               0                   129632              
InstantiateWasmElemSegments        1              Some(0)        0              0              0                   42488               0                   13665               
InstantiateWasmImports             1              Some(15)       97145          11441          0                   828974              0                   97637               
InstantiateWasmExports             1              Some(7)        16247          501            0                   297100              0                   9176                
InstantiateWasmDataSegmentBytes    1              Some(164)      17             161            0                   14                  0                   126                 
Sec1DecodePointUncompressed        0              None           0              0              1882                0                   0                   0                   
VerifyEcdsaSecp256r1Sig            0              None           0              0              3000906             0                   0                   0                   
Bls12381EncodeFp                   1036           None           684796         0              661                 0                   0                   0                   
Bls12381DecodeFp                   2076           None           2044860        0              985                 0                   0                   0                   
Bls12381G1CheckPointOnCurve        1034           None           1999756        0              1934                0                   0                   0                   
Bls12381G1CheckPointInSubgroup     2              None           1461020        0              730510              0                   0                   0                   
Bls12381G2CheckPointOnCurve        2              None           11842          0              5921                0                   0                   0                   
Bls12381G2CheckPointInSubgroup     2              None           2115644        0              1057822             0                   0                   0                   
Bls12381G1ProjectiveToAffine       516            None           47803272       0              92642               0                   0                   0                   
Bls12381G2ProjectiveToAffine       0              None           0              0              100742              0                   0                   0                   
Bls12381G1Add                      516            None           3967524        0              7689                0                   0                   0                   
Bls12381G1Mul                      0              None           0              0              2458985             0                   0                   0                   
Bls12381G1Msm                      0              Some(0)        0              0              2426722             96397671            109494              354667              
Bls12381MapFpToG1                  0              None           0              0              1541554             0                   5552                0                   
Bls12381HashToG1                   0              Some(0)        0              0              3211191             6713                9424                0                   
Bls12381G2Add                      0              None           0              0              25207               0                   0                   0                   
Bls12381G2Mul                      0              None           0              0              7873219             0                   0                   0                   
Bls12381G2Msm                      0              Some(0)        0              0              8035968             309667335           219654              354667              
Bls12381MapFp2ToG2                 0              None           0              0              2420202             0                   3344                0                   
Bls12381HashToG2                   1              Some(32)       7052263        6816           7050564             6797                6816                0                   
Bls12381Pairing                    1              Some(2)        20447400       0              10558948            632860943           2204                9340474             
Bls12381FrFromU256                 0              None           0              0              1994                0                   0                   0                   
Bls12381FrToU256                   0              None           0              0              1155                0                   248                 0                   
Bls12381FrAddSub                   0              None           0              0              74                  0                   0                   0                   
Bls12381FrMul                      0              None           0              0              332                 0                   0                   0                   
Bls12381FrPow                      0              Some(0)        0              0              691                 74558               0                   128                 
Bls12381FrInv                      0              None           0              0              35421               0                   0                   0                   
===============================================================================================================================================================================
Internal details (diagnostics info, does not affect fees) 
Total # times meter was called: 26199
Shadow cpu limit: 100000000; used: 1010213
Shadow mem limit: 41943040; used: 283046
===============================================================================================================================================================================
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant