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

Qb 1816 - implement proxy, add prepay #265

Merged
merged 15 commits into from
Jun 2, 2023
Merged

Conversation

BoThe1K
Copy link
Contributor

@BoThe1K BoThe1K commented May 16, 2023

No description provided.

app/app.go Show resolved Hide resolved
return err
}

if err := pc.call(pc.consensusOwner, proxyAddress, upgradeData, p.Amount.BigInt()); err != nil {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Conceptual difference between consensus owner and proxy owner - consensus owner is who could change a logic, proxy owner is a real owner of a proxy, so this is who could manage a proxy itself. Diffrence required because of TransparentUpgradableProxy to avoid msg.sender collision for upgrade purposes.

evm.StateDB.CreateAccount(to)
}

evm.Context.Transfer(evm.StateDB, from, to, purchased.BigInt())
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is causing a problem if TotalUnissuedPrepay is not allowed.

@@ -426,6 +483,8 @@ func (k *Keeper) ApplyMessageWithConfig(ctx sdk.Context, msg core.Message, trace
}
}

k.ApplyEvents(ctx, vmErr != nil)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

events only applied if not solidity errors, so all func execution has been succeed.

@@ -62,6 +66,7 @@ func New(ctx sdk.Context, keeper Keeper, txConfig TxConfig) *StateDB {
accessList: newAccessList(),
logs: make([]*ethtypes.Log, 0),
txConfig: txConfig,
keestatedb: keestatedb.New(ctx),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with current approach, it should be always fresh

)

var (
TransparentUpgradableProxyBin = "0x608060405260405162000ed038038062000ed08339810160408190526200002691620004a0565b828162000036828260006200004d565b50620000449050826200008a565b505050620005d3565b6200005883620000e5565b600082511180620000665750805b1562000085576200008383836200012760201b620001691760201c565b505b505050565b7f7e644d79422f17c01e4894b5f4f588d331ebfa28653d42ae832dc59e38c9798f620000b562000156565b604080516001600160a01b03928316815291841660208301520160405180910390a1620000e2816200018f565b50565b620000f08162000244565b6040516001600160a01b038216907fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b90600090a250565b60606200014f838360405180606001604052806027815260200162000ea960279139620002f8565b9392505050565b60006200018060008051602062000e8983398151915260001b6200037760201b620001951760201c565b546001600160a01b0316919050565b6001600160a01b038116620001fa5760405162461bcd60e51b815260206004820152602660248201527f455243313936373a206e65772061646d696e20697320746865207a65726f206160448201526564647265737360d01b60648201526084015b60405180910390fd5b806200022360008051602062000e8983398151915260001b6200037760201b620001951760201c565b80546001600160a01b0319166001600160a01b039290921691909117905550565b6200025a816200037a60201b620001981760201c565b620002be5760405162461bcd60e51b815260206004820152602d60248201527f455243313936373a206e657720696d706c656d656e746174696f6e206973206e60448201526c1bdd08184818dbdb9d1c9858dd609a1b6064820152608401620001f1565b80620002237f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc60001b6200037760201b620001951760201c565b6060600080856001600160a01b03168560405162000317919062000580565b600060405180830381855af49150503d806000811462000354576040519150601f19603f3d011682016040523d82523d6000602084013e62000359565b606091505b5090925090506200036d8683838762000389565b9695505050505050565b90565b6001600160a01b03163b151590565b60608315620003fd578251600003620003f5576001600160a01b0385163b620003f55760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401620001f1565b508162000409565b62000409838362000411565b949350505050565b815115620004225781518083602001fd5b8060405162461bcd60e51b8152600401620001f191906200059e565b80516001600160a01b03811681146200045657600080fd5b919050565b634e487b7160e01b600052604160045260246000fd5b60005b838110156200048e57818101518382015260200162000474565b83811115620000835750506000910152565b600080600060608486031215620004b657600080fd5b620004c1846200043e565b9250620004d1602085016200043e565b60408501519092506001600160401b0380821115620004ef57600080fd5b818601915086601f8301126200050457600080fd5b8151818111156200051957620005196200045b565b604051601f8201601f19908116603f011681019083821181831017156200054457620005446200045b565b816040528281528960208487010111156200055e57600080fd5b6200057183602083016020880162000471565b80955050505050509250925092565b600082516200059481846020870162000471565b9190910192915050565b6020815260008251806020840152620005bf81604085016020870162000471565b601f01601f19169190910160400192915050565b6108a680620005e36000396000f3fe60806040523661001357610011610017565b005b6100115b61001f6101a7565b6001600160a01b0316330361015f5760606001600160e01b0319600035166364d3180d60e11b810161005a576100536101da565b9150610157565b63587086bd60e11b6001600160e01b031982160161007a57610053610231565b63070d7c6960e41b6001600160e01b031982160161009a57610053610277565b621eb96f60e61b6001600160e01b03198216016100b9576100536102a8565b63a39f25e560e01b6001600160e01b03198216016100d9576100536102e8565b60405162461bcd60e51b815260206004820152604260248201527f5472616e73706172656e745570677261646561626c6550726f78793a2061646d60448201527f696e2063616e6e6f742066616c6c6261636b20746f2070726f78792074617267606482015261195d60f21b608482015260a4015b60405180910390fd5b815160208301f35b6101676102fc565b565b606061018e838360405180606001604052806027815260200161084a6027913961030c565b9392505050565b90565b6001600160a01b03163b151590565b60007fb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d61035b546001600160a01b0316919050565b60606101e4610384565b60006101f33660048184610695565b81019061020091906106db565b905061021d8160405180602001604052806000815250600061038f565b505060408051602081019091526000815290565b60606000806102433660048184610695565b810190610250919061070c565b915091506102608282600161038f565b604051806020016040528060008152509250505090565b6060610281610384565b60006102903660048184610695565b81019061029d91906106db565b905061021d816103bb565b60606102b2610384565b60006102bc6101a7565b604080516001600160a01b03831660208201529192500160405160208183030381529060405291505090565b60606102f2610384565b60006102bc610412565b610167610307610412565b610421565b6060600080856001600160a01b03168560405161032991906107fa565b600060405180830381855af49150503d8060008114610364576040519150601f19603f3d011682016040523d82523d6000602084013e610369565b606091505b509150915061037a86838387610445565b9695505050505050565b341561016757600080fd5b610398836104c6565b6000825111806103a55750805b156103b6576103b48383610169565b505b505050565b7f7e644d79422f17c01e4894b5f4f588d331ebfa28653d42ae832dc59e38c9798f6103e46101a7565b604080516001600160a01b03928316815291841660208301520160405180910390a161040f81610506565b50565b600061041c6105af565b905090565b3660008037600080366000845af43d6000803e808015610440573d6000f35b3d6000fd5b606083156104b45782516000036104ad576001600160a01b0385163b6104ad5760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e7472616374000000604482015260640161014e565b50816104be565b6104be83836105d7565b949350505050565b6104cf81610601565b6040516001600160a01b038216907fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b90600090a250565b6001600160a01b03811661056b5760405162461bcd60e51b815260206004820152602660248201527f455243313936373a206e65772061646d696e20697320746865207a65726f206160448201526564647265737360d01b606482015260840161014e565b807fb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d61035b80546001600160a01b0319166001600160a01b039290921691909117905550565b60007f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc6101cb565b8151156105e75781518083602001fd5b8060405162461bcd60e51b815260040161014e9190610816565b6001600160a01b0381163b61066e5760405162461bcd60e51b815260206004820152602d60248201527f455243313936373a206e657720696d706c656d656e746174696f6e206973206e60448201526c1bdd08184818dbdb9d1c9858dd609a1b606482015260840161014e565b807f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc61058e565b600080858511156106a557600080fd5b838611156106b257600080fd5b5050820193919092039150565b80356001600160a01b03811681146106d657600080fd5b919050565b6000602082840312156106ed57600080fd5b61018e826106bf565b634e487b7160e01b600052604160045260246000fd5b6000806040838503121561071f57600080fd5b610728836106bf565b9150602083013567ffffffffffffffff8082111561074557600080fd5b818501915085601f83011261075957600080fd5b81358181111561076b5761076b6106f6565b604051601f8201601f19908116603f01168101908382118183101715610793576107936106f6565b816040528281528860208487010111156107ac57600080fd5b8260208601602083013760006020848301015280955050505050509250929050565b60005b838110156107e95781810151838201526020016107d1565b838111156103b45750506000910152565b6000825161080c8184602087016107ce565b9190910192915050565b60208152600082518060208401526108358160408501602087016107ce565b601f01601f1916919091016040019291505056fe416464726573733a206c6f772d6c6576656c2064656c65676174652063616c6c206661696c6564a264697066735822122081bdb2c4d7ec00ca91134719260d0c14c35df5f50dba8a8c2c59a0ef40e1066064736f6c634300080f0033b53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103416464726573733a206c6f772d6c6576656c2064656c65676174652063616c6c206661696c6564"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

slot4 = new(uint256.Int).Mul(slot1, uint256.NewInt(0x04))
)

func opPrepay(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New opcode PREPAY

}

// stratos keeper jump table update
jt := newKeeperInstructionSet(*cfg.JumpTable)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stratos instructions update with PREPAY

// Get the operation from the jump table and validate the stack to ensure there are
// enough stack items available to perform the operation.
op = contract.GetOp(pc)
operation := wrapWithKeeper(op, in, callContext)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

importnat wrapper for a call forwarding to prepay opcode

}

// swaping callGasTemp with addr and replace with gas to decrase params
stack.swap(2)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as prepay does not have addr in stack, required to remove it for the dynamic op override

return calcMemSize64(stack.Back(0), stack.Back(1))
}

func memoryPrepay(stack *Stack) (uint64, bool) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

memory calc for prpay

// NOTE: Maybe we should make on our specific update, instead of apply on go-ethereum update
// see a top lines with instructions sets
func newKeeperInstructionSet(instructionSet JumpTable) JumpTable {
instructionSet[PREPAY] = &operation{
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PREPAY is set here

@BoThe1K BoThe1K marked this pull request as ready for review May 17, 2023 12:48
@BoThe1K BoThe1K changed the title DRAFT: Qb 1816 - implement proxy, add prepay Qb 1816 - implement proxy, add prepay May 17, 2023
@BoThe1K BoThe1K changed the base branch from dev to audit June 2, 2023 13:55
@alexstratos alexstratos merged commit b05d09e into audit Jun 2, 2023
alexstratos added a commit that referenced this pull request Jun 2, 2023
* First test
* Update with working test deploy
* Add cli
* Add genesis deployments
* Update proxy owner
* Add VM intrpreter
* Add PREPAY opcode and test impl
* Updat before state change checks
* First state machine dsign
* Add prpay with new keeper statedb
* Rm revert from func
* Refactor + some add hoc test + keeper mrge
* Update test
* Fix keeper issue
* Rm comment, change gas for prepay fn
BoThe1K added a commit that referenced this pull request Jun 20, 2023
alexstratos pushed a commit that referenced this pull request Jun 20, 2023
alexstratos added a commit that referenced this pull request Jul 6, 2023
* First test
* Update with working test deploy
* Add cli
* Add genesis deployments
* Update proxy owner
* Add VM intrpreter
* Add PREPAY opcode and test impl
* Updat before state change checks
* First state machine dsign
* Add prpay with new keeper statedb
* Rm revert from func
* Refactor + some add hoc test + keeper mrge
* Update test
* Fix keeper issue
* Rm comment, change gas for prepay fn
@alexstratos alexstratos deleted the QB-1816/embed-proxies branch July 6, 2023 18:41
alexstratos pushed a commit that referenced this pull request Jul 6, 2023
* First test
* Update with working test deploy
* Add cli
* Add genesis deployments
* Update proxy owner
* Add VM intrpreter
* Add PREPAY opcode and test impl
* Updat before state change checks
* First state machine dsign
* Add prpay with new keeper statedb
* Rm revert from func
* Refactor + some add hoc test + keeper mrge
* Update test
* Fix keeper issue
* Rm comment, change gas for prepay fn
alexstratos pushed a commit that referenced this pull request Jul 6, 2023
alexstratos pushed a commit that referenced this pull request Jul 6, 2023
* First test
* Update with working test deploy
* Add cli
* Add genesis deployments
* Update proxy owner
* Add VM intrpreter
* Add PREPAY opcode and test impl
* Updat before state change checks
* First state machine dsign
* Add prpay with new keeper statedb
* Rm revert from func
* Refactor + some add hoc test + keeper mrge
* Update test
* Fix keeper issue
* Rm comment, change gas for prepay fn
alexstratos pushed a commit that referenced this pull request Jul 6, 2023
alexstratos added a commit that referenced this pull request Jul 6, 2023
* Qb 1816 - implement proxy, add prepay (#265)`
* Revert "Qb 1816 - implement proxy, add prepay (#265)" (#285)
This reverts commit b05d09e.

---------

Co-authored-by: BoThe1K <121880388+BoThe1K@users.noreply.github.com>
BoThe1K added a commit that referenced this pull request Jan 9, 2024
* First test
* Update with working test deploy
* Add cli
* Add genesis deployments
* Update proxy owner
* Add VM intrpreter
* Add PREPAY opcode and test impl
* Updat before state change checks
* First state machine dsign
* Add prpay with new keeper statedb
* Rm revert from func
* Refactor + some add hoc test + keeper mrge
* Update test
* Fix keeper issue
* Rm comment, change gas for prepay fn
BoThe1K added a commit that referenced this pull request Jan 9, 2024
* First test
* Update with working test deploy
* Add cli
* Add genesis deployments
* Update proxy owner
* Add VM intrpreter
* Add PREPAY opcode and test impl
* Updat before state change checks
* First state machine dsign
* Add prpay with new keeper statedb
* Rm revert from func
* Refactor + some add hoc test + keeper mrge
* Update test
* Fix keeper issue
* Rm comment, change gas for prepay fn
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

Successfully merging this pull request may close these issues.

2 participants