go-ethereum icon indicating copy to clipboard operation
go-ethereum copied to clipboard

eth/tracers: add a simple diffstateTracer

Open jsvisa opened this issue 3 years ago • 15 comments

A simple diffstateTracer, fork from prestateTracer

eg:

curl -XPOST http://127.0.0.1:8545 -d '{
    "jsonrpc": "2.0",
    "method": "debug_traceTransaction",
    "params": [
        "0x594fd479b3c80b1cfa67caa87ba1b6ed898fb32d34556f5cd7ba7d0cd9022956",
        {
            "tracer": "diffstateTracer",
            "timeout": "120s"
        }
    ],
    "id": 67
}
'
{
    "jsonrpc": "2.0",
    "id": 67,
    "result": {
        "0x1158c3c9a70e85d8358972810ed984c8e6ffcf0f": {
            "before": {
                "balance": "0x0",
                "nonce": 0,
                "code": "0x606060405236156101885760e060020a600035046215aa6c811461018a578062d17eba146101ab57806302d7870f146101b557806306eda960146101f457806309010d00146101ff5780630ff0f6431461020e57806311ca5b741461023f5780631468c030146102785780632541897f146102b3578063285e1406146102c75780632c6b569f146102fa578063445a796e146103055780634e7ceacb146103195780634fbc08251461032d57806356e7affb14610341578063578cb8f91461034f578063706f76581461035a57806371e73fec1461036e57806379927531146103a957806387db1955146103da578063893d20e8146103e557806393423e9c146103f957806398b195c81461046257806399a5d7471461049d57806399e1fcac146104c4578063ab77b178146104cf578063b2552fc414610512578063b31b162614610574578063be74264d1461057f578063beabacc81461058a578063c71cbcf3146105f9578063cf09e0d014610747578063d85c896614610750578063fdb575c914610811575b005b61084c600435600a60205260009081526040902054600160a060020a031681565b610869600c545b90565b61087b5b60085460009060a060020a8104820b820b60a860020a909104820b820b1261092a576009546201518080820690030142101561094a576101b2565b6108696013546101b2565b61087b600060006108ff6101b9565b6108696004356024356044356001546000908190600160a060020a0390811633909116141561097957610abe6102ee565b610869600435600154600090600160a060020a039081163390911614156108dc575060018054600160a060020a031916821781556108dc565b610869600435600154600090600160a060020a039081163390911614156108dc575060048054600160a060020a0319168217905560016108dc565b61084c600454600160a060020a03166101b2565b6108696004356001546000908190600160a060020a03908116339091161415610953576109585b60006000610eba6101b9565b6108696011546101b2565b61084c600b54600160a060020a03166101b2565b61084c600854600160a060020a03166101b2565b61084c600254600160a060020a03166101b2565b610869600d5460ff166101b2565b6108696012546101b2565b61084c600354600160a060020a03166101b2565b610869600435600154600090600160a060020a039081163390911614156108dc575060038054600160a060020a0319168217905560016108dc565b6108696004356024356044356001546000908190600160a060020a03908116339091161415610979576109816102ee565b6108696005546101b2565b61084c600154600160a060020a03166101b2565b61086960043560408051600b5460e060020a63f8b2cb4f028252600160a060020a03848116600484015292516000939190911691829163f8b2cb4f91602481810192602092909190829003018188876161da5a03f1156100025750506040515192506108e59050565b610869600435600154600090600160a060020a039081163390911614156108dc5750600b8054600160a060020a0319168217905560016108dc565b6108696004355b6006546005546000916064840402908110156108eb5760055491506108e5565b6108696007546101b2565b61086960043560243560015460009081908190600160a060020a0390811633909116141561050a57600b5460a060020a900460ff1615610a0d575b505092915050565b61086960006000600060006000600060006000600260009054906101000a9004600160a060020a0316600160a060020a031633600160a060020a03161415610b37574260106000505460116000505402600c60005054011115610b4157610b37565b6108696010546101b2565b6108696006546101b2565b610869600435602435604435600454600090600160a060020a03908116339091161415610d9957600160a060020a038481168252600a6020526040822054859116821415610d9e57600160a060020a0384811683526040832054859116831415610da457610dab86868661079c565b610869600435602435600354600090600160a060020a03908116339091161415610ab057600160a060020a038381168252600a6020526040822054849116821415610aae5760408083208054600160a060020a03191685179055600b54815160e060020a63f8b2cb4f028152600160a060020a0380851660048301529251610ab693859388938893919092169183918291849163f8b2cb4f91602481810192602092909190829003018187876161da5a03f1156100025750506040805180517f07bc6fad000000000000000000000000000000000000000000000000000000008252600160a060020a038a81166004840152602483018290526044830186905260648301869052925190955091861692506307bc6fad916084828101926020929190829003018187876161da5a03f115610002575050604051519150508015156110b5575b50505092915050565b61086960005481565b610869600435602435600154600090600160a060020a03908116339091161415610ab057600160a060020a038381168252600a6020526040822054849116821415610aae57610ab63385855b60408051600b5460e060020a63f8b2cb4f028252600160a060020a03868116600484015292516000939190911691839182918691859163f8b2cb4f916024828101926020929190829003018188876161da5a03f1156100025750506040515191909110159050610f03575b5050509392505050565b610869600435600154600090600160a060020a039081163390911614156108dc575060028054600160a060020a0319168217905560016108dc565b60408051600160a060020a03929092168252519081900360200190f35b60408051918252519081900360200190f35b6040805160009290920b8252519081900360200190f35b6008805460f860020a60a860020a80830460000b6001018202919091040260a860020a60ff02199091161790554260095561096f8360088054600160a060020a0319168217905560015b919050565b8091505b50919050565b6007548111156108e15760075491506108e5565b90508060000b60001914156109225760085460a060020a900460000b9150610926565b8091505b5090565b5060085460a860020a8104600090810b60a060020a909204900b036101b2565b506000196101b2565b6108e5565b90508060000b6000141561089257600091506108e5565b91506108e5565b91505b509392505050565b90508060000b600014156109985760009150610979565b6008805460f860020a60a860020a80830460000b6001018202919091040260a860020a60ff021990911617905542600955610976858585600060008410806109e05750600083105b806109eb5750606483115b806109f65750600082105b80610a0057508382105b15610eec57506000610b1e565b60408051600b5460e160020a63761562a7028252600160a060020a0388811660048401526024830188905260006044840181905260648401819052935191169450849263ec2ac54e926084818101936020939092839003909101908290876161da5a03f11561000257505060405151600b805474ff0000000000000000000000000000000000000000191660a060020a8302179055935083915061050a9050565b505b92915050565b915050610ab0565b90508060000b60001415610ad55760009150610979565b6008805460f860020a60a860020a80830460000b6001018202919091040260a860020a60ff02199091161790554260095561097685858560118290556010839055601381905560015b9392505050565b600d805460ff19166001179055600097505b5050505050505090565b6011546000544203049650605a8711610bd457603295505b61016d8660640204600a02955085506000945084505b600f54851015610c1b57600f80548690811015610002577f8d1108e10bcb7c27dddfc02ed9d693a074039d026cf4ea4240b40f7d581ac8020154600160a060020a039081166000818152600a60205260408120549197509116149050610c6657610d7f565b60b48711610be55760289550610b59565b61010e8711610bf757601e9550610b59565b6101688711610c095760149550610b59565b61088e8711610b2557600a9550610b59565b600f8054600080835591909152610d8b907f8d1108e10bcb7c27dddfc02ed9d693a074039d026cf4ea4240b40f7d581ac802908101905b808211156109265760008155600101610c52565b600160a060020a0384166000908152600e6020526040812060018101549094501115610d5a575050604080516001830154600b5460e160020a63761562a7028352600160a060020a0386811660048501526064928302899004602485018190526000604486018190529385018490529451911692839263ec2ac54e9260848381019360209390839003909101908290876161da5a03f115610002575050604080516000808252600160a060020a0388166020830152428284015260608201869052608082015290517e9f837f1feddc3de305fab200310a83d2871686078dab617c02b44360c9e23692509081900360a00190a15b600160a060020a0384166000908152600e60205260408120805460ff19168155600101555b60019490940193610b6f565b5042600c5560019750610b37565b610b1e565b50610b1e565b5050610b1e565b1515610dbc57600092505050610b1e565b610eae86868660006000600061014060405190810160405280600a905b6000815260200190600190039081610dd957505060408051608081018252600080825260208201819052918101829052606081018290526012805460010190819055600b54601354600160a060020a039190911696508392839290918391106113e05760128190555b60145460ff861610156111285760148054600a916000918890811015610002576004027fce6d7b5282bd9a3661ae061feed1dbda4e52ab073b1f9285be6e155d9c38d4ec0154600160a060020a039081168352602093909352506040812054909116146112315761136e565b50600192505050610b1e565b90506000198160000b1215610922576008805460a860020a60ff0219169081905560a060020a900460000b9150610926565b506005839055600682905560078190556001610b1e565b82600160a060020a03166307bc6fad8887600060006040518560e060020a0281526004018085600160a060020a031681526020018481526020018360010281526020018281526020019450505050506020604051808303816000876161da5a03f1156100025750610f7791508690506104a4565b9150818503905082600160a060020a031663ec2ac54e8783600060006040518560e060020a0281526004018085600160a060020a031681526020018481526020018360010281526020018281526020019450505050506020604051808303816000876161da5a03f11561000257505060408051600160a060020a038a81168252891660208201524281830152606081018490526080810185905290517e9f837f1feddc3de305fab200310a83d2871686078dab617c02b44360c9e236925060a0918190039190910190a16040805160085460e160020a63761562a7028252600160a060020a039081166004830152602482018590526000604483018190526064830181905292519086169263ec2ac54e926084818101936020939092839003909101908290876161da5a03f115610002575060019550610807915050565b82600160a060020a031663ec2ac54e8684600060006040518560e060020a0281526004018085600160a060020a031681526020018481526020018360010281526020018281526020019450505050506020604051808303816000876161da5a03f11561000257506001955061073e915050565b60009450601492505b600a60ff861610156113e05787600160a060020a031663ec2ac54e8787600a811015610002576040805160209283029093015160e160020a63761562a7028452600160a060020a031660048401526024830188905260006044840181905260648401819052905160848481019491929183900301908290876161da5a03f11561000257507e9f837f1feddc3de305fab200310a83d2871686078dab617c02b44360c9e2369150600090508787600a8110156100025750506040805160208981028b0151848352600160a060020a03169082015242818301526060810187905260808101929092525160a0918190039190910190a160019490940193611131565b866014600050868154811015610002576000919091526004027fce6d7b5282bd9a3661ae061feed1dbda4e52ab073b1f9285be6e155d9c38d4ee015411156112d957601480548690811015610002576004027fce6d7b5282bd9a3661ae061feed1dbda4e52ab073b1f9285be6e155d9c38d4ee0154975060009450505b60ff8581169085161161137a5760008685600a811015610002576020020152600193909301926112ae565b866014600050868154811015610002576000919091526004027fce6d7b5282bd9a3661ae061feed1dbda4e52ab073b1f9285be6e155d9c38d4ee0154141561136e57601480548690811015610002576004027fce6d7b5282bd9a3661ae061feed1dbda4e52ab073b1f9285be6e155d9c38d4ec0154600160a060020a031690508686600a811015610002575050602086028701525b60019490940193610e42565b601480548690811015610002576000919091526004027fce6d7b5282bd9a3661ae061feed1dbda4e52ab073b1f9285be6e155d9c38d4ec0154600160a060020a03168686600a81101561000257600160a060020a0392909216602092909202015261136e565b601254620186969011156114d757600160a060020a038c811683528b166020830152604082018a9052426060830152600a8a11156114d757601480546001810180835582818380158290116114855760040281600402836000526020600020918201910161148591905b80821115610926578054600160a060020a0319908116825560018201805490911681556000600283018190556003929092019190915561144a565b5050509190906000526020600020906004020160005080548451600160a060020a0319918216178255602085015160018301805490921617905560408401516002820155606084015160039190910155505b600d5460ff1615156115f15787600160a060020a031663f8b2cb4f8d6040518260e060020a0281526004018082600160a060020a031681526020019150506020604051808303816000876161da5a03f1156100025750506040805151600160a060020a038f166000908152600e602052919091205490925060ff1615905061157a576040600020600101548110156115755760406000206001018190555b6115f1565b600f80546001810180835582818380158290116115aa578183600052602060002091820191016115aa9190610c52565b50505060009283525060208083209091018054600160a060020a0319168f179055600160a060020a038e168252600e905260409020805460ff191660019081178255018190555b5060019b9a505050505050505050505056",
                "storage": {
                    "0x0000000000000000000000000000000000000000000000000000000000000001": "0x00000000000000000000000048175da4c20313bcb6b62d74937d3ff985885701",
                    "0x0000000000000000000000000000000000000000000000000000000000000005": "0x0000000000000000000000000000000000000000000000000000000000000000",
                    "0x0000000000000000000000000000000000000000000000000000000000000006": "0x0000000000000000000000000000000000000000000000000000000000000000",
                    "0x0000000000000000000000000000000000000000000000000000000000000007": "0x0000000000000000000000000000000000000000000000000000000000000001",
                    "0x0000000000000000000000000000000000000000000000000000000000000008": "0x00000000000000000000020248175da4c20313bcb6b62d74937d3ff985885701",
                    "0x000000000000000000000000000000000000000000000000000000000000000b": "0x000000000000000000000001276c5c6ca8507ed7bac085fc9b9521f4f54b58d3",
                    "0xfc3f74b3054f270df6d6424ccca2eca892e17df506bac70b4c3b98fea2c8c6a9": "0x0000000000000000000000000000000000000000000000000000000000000000"
                }
            },
            "after": {
                "balance": "0x0",
                "nonce": 0,
                "code": "0x606060405236156101885760e060020a600035046215aa6c811461018a578062d17eba146101ab57806302d7870f146101b557806306eda960146101f457806309010d00146101ff5780630ff0f6431461020e57806311ca5b741461023f5780631468c030146102785780632541897f146102b3578063285e1406146102c75780632c6b569f146102fa578063445a796e146103055780634e7ceacb146103195780634fbc08251461032d57806356e7affb14610341578063578cb8f91461034f578063706f76581461035a57806371e73fec1461036e57806379927531146103a957806387db1955146103da578063893d20e8146103e557806393423e9c146103f957806398b195c81461046257806399a5d7471461049d57806399e1fcac146104c4578063ab77b178146104cf578063b2552fc414610512578063b31b162614610574578063be74264d1461057f578063beabacc81461058a578063c71cbcf3146105f9578063cf09e0d014610747578063d85c896614610750578063fdb575c914610811575b005b61084c600435600a60205260009081526040902054600160a060020a031681565b610869600c545b90565b61087b5b60085460009060a060020a8104820b820b60a860020a909104820b820b1261092a576009546201518080820690030142101561094a576101b2565b6108696013546101b2565b61087b600060006108ff6101b9565b6108696004356024356044356001546000908190600160a060020a0390811633909116141561097957610abe6102ee565b610869600435600154600090600160a060020a039081163390911614156108dc575060018054600160a060020a031916821781556108dc565b610869600435600154600090600160a060020a039081163390911614156108dc575060048054600160a060020a0319168217905560016108dc565b61084c600454600160a060020a03166101b2565b6108696004356001546000908190600160a060020a03908116339091161415610953576109585b60006000610eba6101b9565b6108696011546101b2565b61084c600b54600160a060020a03166101b2565b61084c600854600160a060020a03166101b2565b61084c600254600160a060020a03166101b2565b610869600d5460ff166101b2565b6108696012546101b2565b61084c600354600160a060020a03166101b2565b610869600435600154600090600160a060020a039081163390911614156108dc575060038054600160a060020a0319168217905560016108dc565b6108696004356024356044356001546000908190600160a060020a03908116339091161415610979576109816102ee565b6108696005546101b2565b61084c600154600160a060020a03166101b2565b61086960043560408051600b5460e060020a63f8b2cb4f028252600160a060020a03848116600484015292516000939190911691829163f8b2cb4f91602481810192602092909190829003018188876161da5a03f1156100025750506040515192506108e59050565b610869600435600154600090600160a060020a039081163390911614156108dc5750600b8054600160a060020a0319168217905560016108dc565b6108696004355b6006546005546000916064840402908110156108eb5760055491506108e5565b6108696007546101b2565b61086960043560243560015460009081908190600160a060020a0390811633909116141561050a57600b5460a060020a900460ff1615610a0d575b505092915050565b61086960006000600060006000600060006000600260009054906101000a9004600160a060020a0316600160a060020a031633600160a060020a03161415610b37574260106000505460116000505402600c60005054011115610b4157610b37565b6108696010546101b2565b6108696006546101b2565b610869600435602435604435600454600090600160a060020a03908116339091161415610d9957600160a060020a038481168252600a6020526040822054859116821415610d9e57600160a060020a0384811683526040832054859116831415610da457610dab86868661079c565b610869600435602435600354600090600160a060020a03908116339091161415610ab057600160a060020a038381168252600a6020526040822054849116821415610aae5760408083208054600160a060020a03191685179055600b54815160e060020a63f8b2cb4f028152600160a060020a0380851660048301529251610ab693859388938893919092169183918291849163f8b2cb4f91602481810192602092909190829003018187876161da5a03f1156100025750506040805180517f07bc6fad000000000000000000000000000000000000000000000000000000008252600160a060020a038a81166004840152602483018290526044830186905260648301869052925190955091861692506307bc6fad916084828101926020929190829003018187876161da5a03f115610002575050604051519150508015156110b5575b50505092915050565b61086960005481565b610869600435602435600154600090600160a060020a03908116339091161415610ab057600160a060020a038381168252600a6020526040822054849116821415610aae57610ab63385855b60408051600b5460e060020a63f8b2cb4f028252600160a060020a03868116600484015292516000939190911691839182918691859163f8b2cb4f916024828101926020929190829003018188876161da5a03f1156100025750506040515191909110159050610f03575b5050509392505050565b610869600435600154600090600160a060020a039081163390911614156108dc575060028054600160a060020a0319168217905560016108dc565b60408051600160a060020a03929092168252519081900360200190f35b60408051918252519081900360200190f35b6040805160009290920b8252519081900360200190f35b6008805460f860020a60a860020a80830460000b6001018202919091040260a860020a60ff02199091161790554260095561096f8360088054600160a060020a0319168217905560015b919050565b8091505b50919050565b6007548111156108e15760075491506108e5565b90508060000b60001914156109225760085460a060020a900460000b9150610926565b8091505b5090565b5060085460a860020a8104600090810b60a060020a909204900b036101b2565b506000196101b2565b6108e5565b90508060000b6000141561089257600091506108e5565b91506108e5565b91505b509392505050565b90508060000b600014156109985760009150610979565b6008805460f860020a60a860020a80830460000b6001018202919091040260a860020a60ff021990911617905542600955610976858585600060008410806109e05750600083105b806109eb5750606483115b806109f65750600082105b80610a0057508382105b15610eec57506000610b1e565b60408051600b5460e160020a63761562a7028252600160a060020a0388811660048401526024830188905260006044840181905260648401819052935191169450849263ec2ac54e926084818101936020939092839003909101908290876161da5a03f11561000257505060405151600b805474ff0000000000000000000000000000000000000000191660a060020a8302179055935083915061050a9050565b505b92915050565b915050610ab0565b90508060000b60001415610ad55760009150610979565b6008805460f860020a60a860020a80830460000b6001018202919091040260a860020a60ff02199091161790554260095561097685858560118290556010839055601381905560015b9392505050565b600d805460ff19166001179055600097505b5050505050505090565b6011546000544203049650605a8711610bd457603295505b61016d8660640204600a02955085506000945084505b600f54851015610c1b57600f80548690811015610002577f8d1108e10bcb7c27dddfc02ed9d693a074039d026cf4ea4240b40f7d581ac8020154600160a060020a039081166000818152600a60205260408120549197509116149050610c6657610d7f565b60b48711610be55760289550610b59565b61010e8711610bf757601e9550610b59565b6101688711610c095760149550610b59565b61088e8711610b2557600a9550610b59565b600f8054600080835591909152610d8b907f8d1108e10bcb7c27dddfc02ed9d693a074039d026cf4ea4240b40f7d581ac802908101905b808211156109265760008155600101610c52565b600160a060020a0384166000908152600e6020526040812060018101549094501115610d5a575050604080516001830154600b5460e160020a63761562a7028352600160a060020a0386811660048501526064928302899004602485018190526000604486018190529385018490529451911692839263ec2ac54e9260848381019360209390839003909101908290876161da5a03f115610002575050604080516000808252600160a060020a0388166020830152428284015260608201869052608082015290517e9f837f1feddc3de305fab200310a83d2871686078dab617c02b44360c9e23692509081900360a00190a15b600160a060020a0384166000908152600e60205260408120805460ff19168155600101555b60019490940193610b6f565b5042600c5560019750610b37565b610b1e565b50610b1e565b5050610b1e565b1515610dbc57600092505050610b1e565b610eae86868660006000600061014060405190810160405280600a905b6000815260200190600190039081610dd957505060408051608081018252600080825260208201819052918101829052606081018290526012805460010190819055600b54601354600160a060020a039190911696508392839290918391106113e05760128190555b60145460ff861610156111285760148054600a916000918890811015610002576004027fce6d7b5282bd9a3661ae061feed1dbda4e52ab073b1f9285be6e155d9c38d4ec0154600160a060020a039081168352602093909352506040812054909116146112315761136e565b50600192505050610b1e565b90506000198160000b1215610922576008805460a860020a60ff0219169081905560a060020a900460000b9150610926565b506005839055600682905560078190556001610b1e565b82600160a060020a03166307bc6fad8887600060006040518560e060020a0281526004018085600160a060020a031681526020018481526020018360010281526020018281526020019450505050506020604051808303816000876161da5a03f1156100025750610f7791508690506104a4565b9150818503905082600160a060020a031663ec2ac54e8783600060006040518560e060020a0281526004018085600160a060020a031681526020018481526020018360010281526020018281526020019450505050506020604051808303816000876161da5a03f11561000257505060408051600160a060020a038a81168252891660208201524281830152606081018490526080810185905290517e9f837f1feddc3de305fab200310a83d2871686078dab617c02b44360c9e236925060a0918190039190910190a16040805160085460e160020a63761562a7028252600160a060020a039081166004830152602482018590526000604483018190526064830181905292519086169263ec2ac54e926084818101936020939092839003909101908290876161da5a03f115610002575060019550610807915050565b82600160a060020a031663ec2ac54e8684600060006040518560e060020a0281526004018085600160a060020a031681526020018481526020018360010281526020018281526020019450505050506020604051808303816000876161da5a03f11561000257506001955061073e915050565b60009450601492505b600a60ff861610156113e05787600160a060020a031663ec2ac54e8787600a811015610002576040805160209283029093015160e160020a63761562a7028452600160a060020a031660048401526024830188905260006044840181905260648401819052905160848481019491929183900301908290876161da5a03f11561000257507e9f837f1feddc3de305fab200310a83d2871686078dab617c02b44360c9e2369150600090508787600a8110156100025750506040805160208981028b0151848352600160a060020a03169082015242818301526060810187905260808101929092525160a0918190039190910190a160019490940193611131565b866014600050868154811015610002576000919091526004027fce6d7b5282bd9a3661ae061feed1dbda4e52ab073b1f9285be6e155d9c38d4ee015411156112d957601480548690811015610002576004027fce6d7b5282bd9a3661ae061feed1dbda4e52ab073b1f9285be6e155d9c38d4ee0154975060009450505b60ff8581169085161161137a5760008685600a811015610002576020020152600193909301926112ae565b866014600050868154811015610002576000919091526004027fce6d7b5282bd9a3661ae061feed1dbda4e52ab073b1f9285be6e155d9c38d4ee0154141561136e57601480548690811015610002576004027fce6d7b5282bd9a3661ae061feed1dbda4e52ab073b1f9285be6e155d9c38d4ec0154600160a060020a031690508686600a811015610002575050602086028701525b60019490940193610e42565b601480548690811015610002576000919091526004027fce6d7b5282bd9a3661ae061feed1dbda4e52ab073b1f9285be6e155d9c38d4ec0154600160a060020a03168686600a81101561000257600160a060020a0392909216602092909202015261136e565b601254620186969011156114d757600160a060020a038c811683528b166020830152604082018a9052426060830152600a8a11156114d757601480546001810180835582818380158290116114855760040281600402836000526020600020918201910161148591905b80821115610926578054600160a060020a0319908116825560018201805490911681556000600283018190556003929092019190915561144a565b5050509190906000526020600020906004020160005080548451600160a060020a0319918216178255602085015160018301805490921617905560408401516002820155606084015160039190910155505b600d5460ff1615156115f15787600160a060020a031663f8b2cb4f8d6040518260e060020a0281526004018082600160a060020a031681526020019150506020604051808303816000876161da5a03f1156100025750506040805151600160a060020a038f166000908152600e602052919091205490925060ff1615905061157a576040600020600101548110156115755760406000206001018190555b6115f1565b600f80546001810180835582818380158290116115aa578183600052602060002091820191016115aa9190610c52565b50505060009283525060208083209091018054600160a060020a0319168f179055600160a060020a038e168252600e905260409020805460ff191660019081178255018190555b5060019b9a505050505050505050505056",
                "storage": {
                    "0x0000000000000000000000000000000000000000000000000000000000000001": "0x00000000000000000000000048175da4c20313bcb6b62d74937d3ff985885701",
                    "0x0000000000000000000000000000000000000000000000000000000000000005": "0x0000000000000000000000000000000000000000000000000000000000000000",
                    "0x0000000000000000000000000000000000000000000000000000000000000006": "0x0000000000000000000000000000000000000000000000000000000000000000",
                    "0x0000000000000000000000000000000000000000000000000000000000000007": "0x0000000000000000000000000000000000000000000000000000000000000001",
                    "0x0000000000000000000000000000000000000000000000000000000000000008": "0x00000000000000000000020248175da4c20313bcb6b62d74937d3ff985885701",
                    "0x000000000000000000000000000000000000000000000000000000000000000b": "0x000000000000000000000001276c5c6ca8507ed7bac085fc9b9521f4f54b58d3",
                    "0xfc3f74b3054f270df6d6424ccca2eca892e17df506bac70b4c3b98fea2c8c6a9": "0x0000000000000000000000000000000000000000000000000000000000000000"
                }
            }
        },
        "0x276c5c6ca8507ed7bac085fc9b9521f4f54b58d3": {
            "before": {
                "balance": "0x0",
                "nonce": 0,
                "code": "0x6060604052361561006c5760e060020a600035046307bc6fad811461006e57806313af40351461013c57806327e235e31461017f578063893d20e814610197578063ab470f05146101aa578063beb92f55146101be578063ec2ac54e14610202578063f8b2cb4f14610286575b005b6102ab600435602435604435606435600154600090819033600160a060020a03908116911614156101335750600160a060020a0385168152600260205260408120548481106101335733600160a060020a03168286606082818181858883f15050604091829020600160a060020a038a168087526002602090815292860390915582518781529182018990528251869450909288927fea0f544916910bb1ff33390cbe54a3f5d36d298328578399311cde3c9a750686929081900390910190a4600191505b50949350505050565b6102ab60043560008054600160a060020a039081163390911614156102d057805473ffffffffffffffffffffffffffffffffffffffff19168217905560016102a6565b6102ab60043560026020526000908152604090205481565b6102bd600054600160a060020a03165b90565b6102bd600154600160a060020a03166101a7565b6102ab60043560008054600160a060020a039081163390911614156102d057506001805473ffffffffffffffffffffffffffffffffffffffff1916821781556102a6565b6102ab60043560243560443560643560015460009033600160a060020a039081169116141561027e57600160a060020a0385168082526002602052604080832080548701905560608481526080879052839186917fea0f544916910bb1ff33390cbe54a3f5d36d298328578399311cde3c9a7506869190a45060015b949350505050565b6102ab600435600160a060020a0381166000908152600260205260409020545b919050565b60408051918252519081900360200190f35b600160a060020a03166060908152602090f35b6102a656",
                "storage": {
                    "0x0000000000000000000000000000000000000000000000000000000000000001": "0x0000000000000000000000001158c3c9a70e85d8358972810ed984c8e6ffcf0f",
                    "0x308b0384a8194ad39f3cae09180d053432ea6ec62a6ed4268c469e46fcdd2f38": "0x000000000000000000000000000000000000000000000000000000000d2c3140",
                    "0x6d0bc9c70e6e169ea1da8dab3ee227366100f942e5b4af5531151cce44492e24": "0x00000000000000000000000000000000000000000000000000000005a2e2056d"
                }
            },
            "after": {
                "balance": "0x0",
                "nonce": 0,
                "code": "0x6060604052361561006c5760e060020a600035046307bc6fad811461006e57806313af40351461013c57806327e235e31461017f578063893d20e814610197578063ab470f05146101aa578063beb92f55146101be578063ec2ac54e14610202578063f8b2cb4f14610286575b005b6102ab600435602435604435606435600154600090819033600160a060020a03908116911614156101335750600160a060020a0385168152600260205260408120548481106101335733600160a060020a03168286606082818181858883f15050604091829020600160a060020a038a168087526002602090815292860390915582518781529182018990528251869450909288927fea0f544916910bb1ff33390cbe54a3f5d36d298328578399311cde3c9a750686929081900390910190a4600191505b50949350505050565b6102ab60043560008054600160a060020a039081163390911614156102d057805473ffffffffffffffffffffffffffffffffffffffff19168217905560016102a6565b6102ab60043560026020526000908152604090205481565b6102bd600054600160a060020a03165b90565b6102bd600154600160a060020a03166101a7565b6102ab60043560008054600160a060020a039081163390911614156102d057506001805473ffffffffffffffffffffffffffffffffffffffff1916821781556102a6565b6102ab60043560243560443560643560015460009033600160a060020a039081169116141561027e57600160a060020a0385168082526002602052604080832080548701905560608481526080879052839186917fea0f544916910bb1ff33390cbe54a3f5d36d298328578399311cde3c9a7506869190a45060015b949350505050565b6102ab600435600160a060020a0381166000908152600260205260409020545b919050565b60408051918252519081900360200190f35b600160a060020a03166060908152602090f35b6102a656",
                "storage": {
                    "0x0000000000000000000000000000000000000000000000000000000000000001": "0x0000000000000000000000001158c3c9a70e85d8358972810ed984c8e6ffcf0f",
                    "0x308b0384a8194ad39f3cae09180d053432ea6ec62a6ed4268c469e46fcdd2f38": "0x000000000000000000000000000000000000000000000000000000000d502504",
                    "0x6d0bc9c70e6e169ea1da8dab3ee227366100f942e5b4af5531151cce44492e24": "0x00000000000000000000000000000000000000000000000000000005a2be11a9"
                }
            }
        },
        "0x48175da4c20313bcb6b62d74937d3ff985885701": {
            "before": {
                "balance": "0x1c099997830dd15ee",
                "nonce": 18002,
                "code": "0x",
                "storage": {}
            },
            "after": {
                "balance": "0x1c079b628e6502f0e",
                "nonce": 18003,
                "code": "0x",
                "storage": {}
            }
        }
    }
}

jsvisa avatar Jul 27 '22 18:07 jsvisa

What would be the use case for this tracer?

karalabe avatar Jul 28 '22 06:07 karalabe

What would be the use case for this tracer?

We want to get all contracts/accounts' state change before and after a TX execution. It is useful for analyzing some exploit transactions.

jsvisa avatar Jul 28 '22 07:07 jsvisa

So we can extract the difference of the state, eg: https://etherscan.io/tx/0x9ef7a35012286fef17da12624aa124ebc785d9e7621e1fd538550d1209eb9f7d#statechange

image

jsvisa avatar Jul 28 '22 07:07 jsvisa

Thanks for the PR - we just discussed it in triage - and in general this is something that would be nice to have. Just the implementation needs some changes:

  • diff should only return differences
  • there should be tests (please look at other tracers how it is done there)

ligi avatar Jul 28 '22 08:07 ligi

Nitpick: please rename to stateDiffTracer

Edit: also it was on my backlog to implement this tracer myself, thanks for opening the PR!

s1na avatar Jul 28 '22 12:07 s1na

Nitpick: please rename to stateDiffTracer

Edit: also it was on my backlog to implement this tracer myself, thanks for opening the PR!

I happen to need to use this feature in our workspace :) && renamed.

jsvisa avatar Jul 28 '22 13:07 jsvisa

Thanks for the PR - we just discussed it in triage - and in general this is something that would be nice to have. Just the implementation needs some changes:

* diff should only return differences

* there should be tests (please look at other tracers how it is done there)

@ligi thanks for your advice, but there is small questions:

diff should only return differences

IMHO, the original value may be more useful, user can check the pre and post values by their own means.

  • there should be tests (please look at other tracers how it is done there)

Where should I put the test cases inside, eth/tracers/api_test.go or eth/tracers/internal/tracetest ?

jsvisa avatar Jul 28 '22 14:07 jsvisa

@ligi add a simple testcase inside [eth/tracers/internal/tracetest](eth/tracers/internal/tracetest]

BTW, seems the 4byte, prestate and other tracers doesn't have testcases. If necessary, I will file another PR

jsvisa avatar Jul 28 '22 15:07 jsvisa

Also if #25430 is merged, then this can become an option in the prestateTracer. Something like collectAfter: true, which when falls returns the same result as now for backwards compatibility and if true returns a result similar to how you have it here. (and we'll probably avoid +100 extra LoC).

s1na avatar Jul 28 '22 16:07 s1na

https://github.com/ethereum/go-ethereum/pull/25430 has been merged 👀

shekhirin avatar Aug 09 '22 15:08 shekhirin

@s1na PTAL, merge the statediff into prestate with config as collectPost: true

jsvisa avatar Aug 09 '22 17:08 jsvisa

Hey @jsvisa, sorry for coming back late. Thanks for updating it with the config. The result of this tracer will be vague in some cases: specifically around account creation and deletion. It also needs to handle new storage slots and cleared slots. So I propose the following schema:

{
  "pre": {
    // Same thing as before
    "0xaa": {
      ...
    }
  },
  "post": {
    "0xbb": {
      ...
    }
  }
}

With the following logic:

  • If an account is created during tx, it doesn't exist in pre but only in post.
  • If an account is self-destructed, it will be in pre but not in post.
  • Account was modified: we generallly want to omit fields that have the same value as before. E.g. if we have a simple account that only increased its nonce, then post state account will have one field nonce with the new value. Storage is handled the same way as in accounts:
    • new slots will only show up in the storage section of post account
    • cleared slots will not show up in post storage
    • modified slots will contain new value
  • Note it's possible that a simple account changes to a contract (i.e. has ether balance but no code, and then code is deployed to that address). Similar logic applies here, the new fields will be shared in the post account
  • It's not possible that a self-destructed contract becomes a simple account with ether balance in the same tx. Therefore omitting fields is safe and not vague.

s1na avatar Sep 14 '22 14:09 s1na

@s1na thanks for your advice, I'll implement it ASAP.

Please help me to confirm whether my understanding is correct:

  1. Is this pre-post schema for all prestate tracer, or only available for the config with post collecter, I prefer to only the later case, compatible with the previous API. But in terms of code logic, the all prestate one is a much cleaner.

  2. If an account is self-destructed, then this account must be a contract, should we keep the code in pre?

  3. If an account is self-destructed, then re-created(via create2), we should keep the ether balance on both side(code is omitted);

  4. Note it's possible that a simple account changes to a contract:

    Does simple account == EOA, How can an EOA account change into a Contract? (contract address is calculated by the caller's adress+nonce or salt)

  5. In some cases, besides the diff state, we want the full state, should we add another config(eg: collectFull: true) to keep the complete data?

jsvisa avatar Sep 15 '22 01:09 jsvisa

Hey great that you like to continue working on this! Re the questions:

  1. Yes only when we're collecting post state too. Better for backwards-compatibility.
  2. Yes pre should contain everything about the account. Only partial storage tho (slots that were accessed).
  3. AFAIK CREATE2 can only re-create in a later tx, not the same tx as SELFDESTRUCT. So when contract is destroyed address should be omitted from post
  4. Yes I mean EOA. The address is predictable when using CREATE2 so someone can transfer funds to it before creation
  5. I would leave that for a future PR

s1na avatar Sep 15 '22 15:09 s1na

@s1na Thanks for the details, I'll implement it this weekend ASAP.

jsvisa avatar Sep 16 '22 15:09 jsvisa

@s1na sorry for the later reply, please take another look.

jsvisa avatar Sep 22 '22 03:09 jsvisa

Thanks for updating based on the comments. Also very cool that you added the extra test cases. In the meanwhile #25637 was merged which unfortunately conflicts with your PR. Can you please rebase? The gist of that PR is that we store account values not as hex string anymore but their native types and the encoding happens only at the end.

Apart from that one last comment: I'm not sure anymore collectPost is a good name for the flag since you're now removing an account that hasn't been modified from pre. I think it should suggest that it reports the diff, but I'm struggling with a good name. Maybe stateDiff: true, or diffMode: true or something. Up to you.

s1na avatar Sep 27 '22 16:09 s1na

I'm rebasing it. Just curious, after rebasing from the master branch, the post balance of from_address was increased, I have to figure out what happened.

Prefer to diffMode: true

jsvisa avatar Sep 28 '22 03:09 jsvisa

@s1na Sorry, May I ask for your help?

If I assign the Balance as *big.Int, then the from_address in post's balance is wrong(increased) this branch; but if stored in string, everything is OK, code in feature/statediff-tracer-string

request as below:

request

trace tx: 0x9aac76c9ed191da631b5e70c8824f2ad106a0f5147d57c611ed64653734dd85f

{
    "jsonrpc": "2.0",
    "method": "debug_traceTransaction",
    "params": [
        "0x9aac76c9ed191da631b5e70c8824f2ad106a0f5147d57c611ed64653734dd85f",
        {
            "tracer": "prestateTracer",
            "timeout": "120s",
            "tracerConfig": {
                "diffMode": true
            }
        }
    ],
    "id": 67
}

this branch's result(:-1:)

{
    "jsonrpc": "2.0",
    "id": 67,
    "result": {
        "pre": {
            "0x082d4cdf07f386ffa9258f52a5c49db4ac321ec6": {
                "balance": "0xc820f93200f4000",
                "nonce": 94,
                "code": "0x",
                "storage": {}
            },
            "0x332b656504f4eabb44c8617a42af37461a34e9dc": {
                "balance": "0x11faea4f35e5af80000",
                "nonce": 0,
                "code": "0x",
                "storage": {
                    "0x0000000000000000000000000000000000000000000000000000000000000000": "0x0000000000000000000000000000000000000000000000000000000000000000"
                }
            },
            "0x52bc44d5378309ee2abf1539bf71de1b7d7be3b5": {
                "balance": "0xbf681825be002ac452",
                "nonce": 28922,
                "code": "0x",
                "storage": {}
            },
            "0x82effbaaaf28614e55b2ba440fb198e0e5789b0f": {
                "balance": "0xb3d0ac5cb94df6f6b0",
                "nonce": 1,
                "code": "0x",
                "storage": {}
            }
        },
        "post": {
            "0x082d4cdf07f386ffa9258f52a5c49db4ac321ec6": {
                "balance": "0xd2ef044de504c00",
                "nonce": 95,
                "code": "0x",
                "storage": {}
            },
            "0x52bc44d5378309ee2abf1539bf71de1b7d7be3b5": {
                "balance": "0xbf681ce7c870aeb852",
                "nonce": 0,
                "code": "0x",
                "storage": {}
            },
            "0x82effbaaaf28614e55b2ba440fb198e0e5789b0f": {
                "balance": "0x1d37f515017a8eef6b0",
                "nonce": 0,
                "code": "0x",
                "storage": {}
            }
        }
    }
}

the post-state of 0x082d4cdf07f386ffa9258f52a5c49db4ac321ec6 is incorrect.

statediff-tracer-string's result(:+1:)

{
    "jsonrpc": "2.0",
    "id": 67,
    "result": {
        "pre": {
            "0x082d4cdf07f386ffa9258f52a5c49db4ac321ec6": {
                "balance": "0xc820f93200f4000",
                "nonce": 94,
                "code": "0x",
                "storage": {}
            },
            "0x332b656504f4eabb44c8617a42af37461a34e9dc": {
                "balance": "0x11faea4f35e5af80000",
                "nonce": 0,
                "code": "0x",
                "storage": {
                    "0x0000000000000000000000000000000000000000000000000000000000000000": "0x0000000000000000000000000000000000000000000000000000000000000000"
                }
            },
            "0x52bc44d5378309ee2abf1539bf71de1b7d7be3b5": {
                "balance": "0xbf681825be002ac452",
                "nonce": 28922,
                "code": "0x",
                "storage": {}
            },
            "0x82effbaaaf28614e55b2ba440fb198e0e5789b0f": {
                "balance": "0xb3d0ac5cb94df6f6b0",
                "nonce": 1,
                "code": "0x",
                "storage": {}
            }
        },
        "post": {
            "0x082d4cdf07f386ffa9258f52a5c49db4ac321ec6": {
                "balance": "0xc7d4d88af8b4c00",
                "nonce": 95,
                "code": "0x",
                "storage": {}
            },
            "0x52bc44d5378309ee2abf1539bf71de1b7d7be3b5": {
                "balance": "0xbf681ce7c870aeb852",
                "nonce": 0,
                "code": "0x",
                "storage": {}
            },
            "0x82effbaaaf28614e55b2ba440fb198e0e5789b0f": {
                "balance": "0x1d37f515017a8eef6b0",
                "nonce": 0,
                "code": "0x",
                "storage": {}
            }
        }
    }
}

the post-state of 0x082d4cdf07f386ffa9258f52a5c49db4ac321ec6 is correct.

Please feel free to correct me if anything I'm missing.

Git diff as below:

git diff
diff --git a/eth/tracers/native/gen_account_json.go b/eth/tracers/native/gen_account_json.go
index 25dc77dc7..c854811fc 100644
--- a/eth/tracers/native/gen_account_json.go
+++ b/eth/tracers/native/gen_account_json.go
@@ -21,7 +21,9 @@ func (a account) MarshalJSON() ([]byte, error) {
 		Storage map[common.Hash]common.Hash `json:"storage"`
 	}
 	var enc account
-	enc.Balance = (*hexutil.Big)(a.Balance)
+    balance := new(big.Int)
+    balance.SetString(a.Balance[2:], 16)
+	enc.Balance = (*hexutil.Big)(balance)
 	enc.Nonce = a.Nonce
 	enc.Code = a.Code
 	enc.Storage = a.Storage
@@ -41,7 +43,7 @@ func (a *account) UnmarshalJSON(input []byte) error {
 		return err
 	}
 	if dec.Balance != nil {
-		a.Balance = (*big.Int)(dec.Balance)
+		a.Balance = bigToHex((*big.Int)(dec.Balance))
 	}
 	if dec.Nonce != nil {
 		a.Nonce = *dec.Nonce
diff --git a/eth/tracers/native/prestate.go b/eth/tracers/native/prestate.go
index 237206c7c..adc8b5305 100644
--- a/eth/tracers/native/prestate.go
+++ b/eth/tracers/native/prestate.go
@@ -30,8 +30,6 @@ import (
 	"github.com/ethereum/go-ethereum/eth/tracers"
 )
 
-//go:generate go run github.com/fjl/gencodec -type account -field-override accountMarshaling -out gen_account_json.go
-
 func init() {
 	register("prestateTracer", newPrestateTracer)
 }
@@ -39,10 +37,10 @@ func init() {
 type state = map[common.Address]*account
 
 type account struct {
-	Balance *big.Int                    `json:"balance,omitempty"`
-	Nonce   uint64                      `json:"nonce,omitempty"`
-	Code    []byte                      `json:"code,omitempty"`
-	Storage map[common.Hash]common.Hash `json:"storage,omitempty"`
+	Balance string                      `json:"balance"`
+	Nonce   uint64                      `json:"nonce"`
+	Code    []byte                      `json:"code"`
+	Storage map[common.Hash]common.Hash `json:"storage"`
 }
 
 type accountMarshaling struct {
@@ -97,16 +95,16 @@ func (t *prestateTracer) CaptureStart(env *vm.EVM, from common.Address, to commo
 	t.lookupAccount(env.Context.Coinbase)
 
 	// The recipient balance includes the value transferred.
-	toBal := new(big.Int).Sub(t.pre[to].Balance, value)
-	t.pre[to].Balance = toBal
+	toBal := new(big.Int).Sub(hexutil.MustDecodeBig(t.pre[to].Balance), value)
+	t.pre[to].Balance = bigToHex(toBal)
 
 	// The sender balance is after reducing: value and gasLimit.
 	// We need to re-add them to get the pre-tx balance.
-	fromBal := t.pre[from].Balance
+	fromBal := hexutil.MustDecodeBig(t.pre[from].Balance)
 	gasPrice := env.TxContext.GasPrice
 	consumedGas := new(big.Int).Mul(gasPrice, new(big.Int).SetUint64(t.gasLimit))
 	fromBal.Add(fromBal, new(big.Int).Add(value, consumedGas))
-	t.pre[from].Balance = fromBal
+	t.pre[from].Balance = bigToHex(fromBal)
 	t.pre[from].Nonce--
 
 	if create && t.config.DiffMode {
@@ -187,11 +185,11 @@ func (t *prestateTracer) CaptureTxEnd(restGas uint64) {
 		}
 		modified := false
 		postAccount := &account{Storage: make(map[common.Hash]common.Hash)}
-		newBalance := t.env.StateDB.GetBalance(addr)
+		newBalance := bigToHex(t.env.StateDB.GetBalance(addr))
 		newNonce := t.env.StateDB.GetNonce(addr)
 		newCode := t.env.StateDB.GetCode(addr)
 
-		if newBalance.Cmp(t.pre[addr].Balance) != 0 {
+		if newBalance != t.pre[addr].Balance {
 			modified = true
 			postAccount.Balance = newBalance
 		}
@@ -229,7 +227,7 @@ func (t *prestateTracer) CaptureTxEnd(restGas uint64) {
 	// the new created contracts' prestate were empty, so delete them
 	for a := range t.created {
 		// the created contract maybe exists in statedb before the creating tx
-		if s := t.pre[a]; s.Balance.Cmp(big.NewInt(0)) == 0 && len(s.Storage) == 0 && len(s.Code) == 0 {
+		if s := t.pre[a]; s.Balance != "0x" && len(s.Storage) == 0 && len(s.Code) == 0 {
 			delete(t.pre, a)
 		}
 	}
@@ -268,7 +266,7 @@ func (t *prestateTracer) lookupAccount(addr common.Address) {
 	}
 
 	t.pre[addr] = &account{
-		Balance: t.env.StateDB.GetBalance(addr),
+		Balance: bigToHex(t.env.StateDB.GetBalance(addr)),
 		Nonce:   t.env.StateDB.GetNonce(addr),
 		Code:    t.env.StateDB.GetCode(addr),
 		Storage: make(map[common.Hash]common.Hash),
@@ -284,3 +282,10 @@ func (t *prestateTracer) lookupStorage(addr common.Address, key common.Hash) {
 	}
 	t.pre[addr].Storage[key] = t.env.StateDB.GetState(addr, key)
 }
+
+func bigToHex(n *big.Int) string {
+	if n == nil {
+		return ""
+	}
+	return "0x" + n.Text(16)
+}

I'm rebasing it. Just curious, after rebasing from the master branch, the post balance of from_address was increased, I have to figure out what happened.

Prefer to diffMode: true

jsvisa avatar Sep 28 '22 09:09 jsvisa

If I assign the Balance as *big.Int, then the from_address in post's balance is wrong(increased) this branch; but if stored in string, everything is OK, code in feature/statediff-tracer-string

>>> 0xd2ef044de504c00 - 0xc7d4d88af8b4c00 
50000000000000000

That's exactly 0.5 ether. I wonder if some codepath of @s1na 's changes to maintain native data reuses big.Int, and later accesses modify it.

holiman avatar Sep 28 '22 10:09 holiman

If I assign the Balance as *big.Int, then the from_address in post's balance is wrong(increased) this branch; but if stored in string, everything is OK, code in feature/statediff-tracer-string

>>> 0xd2ef044de504c00 - 0xc7d4d88af8b4c00 
50000000000000000

That's exactly 0.5 ether. I wonder if some codepath of @s1na 's changes to maintain native data reuses big.Int, and later accesses modify it.

thanks, maybe gasPrice is reused :curious:

https://github.com/ethereum/go-ethereum/blob/1a63a76fcc8c8055d3361f3d9c4b0a5bc9c0da6d/eth/tracers/native/prestate.go#L83

jsvisa avatar Sep 28 '22 12:09 jsvisa

If I assign the Balance as *big.Int, then the from_address in post's balance is wrong(increased) this branch; but if stored in string, everything is OK, code in feature/statediff-tracer-string

>>> 0xd2ef044de504c00 - 0xc7d4d88af8b4c00 
50000000000000000

That's exactly 0.5 ether. I wonder if some codepath of @s1na 's changes to maintain native data reuses big.Int, and later accesses modify it.

thanks, maybe gasPrice is reused :curious:

https://github.com/ethereum/go-ethereum/blob/1a63a76fcc8c8055d3361f3d9c4b0a5bc9c0da6d/eth/tracers/native/prestate.go#L83

Seems it's the fromBal

https://github.com/ethereum/go-ethereum/blob/1a63a76fcc8c8055d3361f3d9c4b0a5bc9c0da6d/eth/tracers/native/prestate.go#L82

I changed it to

	fromBal := new(big.Int).Add(big.NewInt(0), t.pre[from].Balance)

and works fine. But I don't know why?

jsvisa avatar Sep 28 '22 12:09 jsvisa

I changed it to

	fromBal := new(big.Int).Add(big.NewInt(0), t.pre[from].Balance)

and works fine. But I don't know why?

It looks like as below, please feel free to correct me if I'm missing anything.

  1. fromBal referenced to t.pre[from].Balance;
  2. and t.pre[from].Balance referenced to StateDB's stateObject, so change fromBal's value will change also change the stateObject's;
  3. before this line executing, from's balance is balance-value-gasLimit*gasPrice( via st.buyGas()), in this case, is 851300000000000000
  4. and here we change its actual value to balance-value-gasLimit*gasPrice+gasLimit*gasPrice, the one the same as previous, 901300000000000000
  5. after the tx is executed, the restGas is refunded back to from, so its value is increased, 901300000000000000 + 973215 * 50gwei

jsvisa avatar Sep 28 '22 12:09 jsvisa

@holiman @s1na I think the later one is a critical issue, we should fix it ASAP, and I filed a PR https://github.com/ethereum/go-ethereum/pull/25884

jsvisa avatar Sep 28 '22 13:09 jsvisa

@s1na please take another look :)

jsvisa avatar Sep 29 '22 01:09 jsvisa

Comparing the result of the prestate mode with master and there are 2 differences:

  • Coinbase is now part of prestate
  • Empty code and storage fields are omitted

IMO these changes are both desirable. The second one will probably break a few scripts, but trivial to fix.

s1na avatar Sep 29 '22 20:09 s1na