Skip to content
This repository has been archived by the owner on Nov 6, 2022. It is now read-only.

Commit

Permalink
notion of throw
Browse files Browse the repository at this point in the history
  • Loading branch information
rachel-bousfield committed Dec 13, 2021
1 parent b1a427c commit a182c5a
Show file tree
Hide file tree
Showing 105 changed files with 699 additions and 602 deletions.
32 changes: 16 additions & 16 deletions arb_os/accounts.mini
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ type AggregatorInfo = struct {
var globalAccountStore: AccountStore; // needs to be initialized before use


public view write func accountStore_init() {
public view write throw func accountStore_init() {
globalAccountStore = struct {
accounts: newmap<address, Account>,
retryBuffer: retryBuffer_new(),
Expand All @@ -110,14 +110,14 @@ public func escrowStore_new() -> EscrowStore {
}
}

public view write func accounts_notifyParamsChanged() { // called if the chain parameters have changed
public view write throw func accounts_notifyParamsChanged() { // called if the chain parameters have changed
set globalAccountStore.retryBuffer = retryBuffer_setDefaultLifetime(globalAccountStore.retryBuffer);
}

// safeGetGlobalAccountStore gets a copy of the global account store, if we are not in a user tx
// if we're in a user tx, this will error, which will revert the tx
// that should never happen, but we check to be safe
public view write func safeGetGlobalAccountStore() -> AccountStore {
public view write throw func safeGetGlobalAccountStore() -> AccountStore {
if ! evmCallStack_isEmpty() {
asm(668) { debugprint };
error;
Expand All @@ -126,7 +126,7 @@ public view write func safeGetGlobalAccountStore() -> AccountStore {
}

// see comment on safeGet... above
public view write func safeSetGlobalAccountStore(acctStore: AccountStore) {
public view write throw func safeSetGlobalAccountStore(acctStore: AccountStore) {
if ! evmCallStack_isEmpty() {
asm(669) { debugprint };
error;
Expand Down Expand Up @@ -193,7 +193,7 @@ public func accountStore_changeNumContracts(acctStore: AccountStore, delta: int)
acctStore with { numContracts: uint(int(acctStore.numContracts) + delta) }
}

public func accountStore_destroyAccount(acctStore: AccountStore, addrToDestroy: address) -> AccountStore {
public throw func accountStore_destroyAccount(acctStore: AccountStore, addrToDestroy: address) -> AccountStore {
if let Some(contractInfo) = accountStore_get(acctStore, addrToDestroy).contractInfo {
acctStore = accountStore_dropCodeRef(
acctStore,
Expand Down Expand Up @@ -244,7 +244,7 @@ public func account_getAggregatorToPayAsOption(account: Account) -> option<addre
account.aggregatorToPay
}

public view func account_getAggregatorToPay(account: Account) -> address {
public view throw func account_getAggregatorToPay(account: Account) -> address {
if let Some(atp) = account.aggregatorToPay {
atp
} else {
Expand Down Expand Up @@ -293,7 +293,7 @@ public func account_getAggregatorDecompressionState(account: Account) -> option<
(account.aggregatorInfo?).decompressionState
}

public view func account_setAggregatorDecompressionState(
public view throw func account_setAggregatorDecompressionState(
account: Account,
maybeState: option<AggregatorDecompressionState>,
) -> Account {
Expand Down Expand Up @@ -326,7 +326,7 @@ public func account_getFeeCollector(account: Account) -> address {
}
}

public view func account_setFeeCollector(account: Account, newCollector: address) -> Account {
public view throw func account_setFeeCollector(account: Account, newCollector: address) -> Account {
account with {
aggregatorInfo: Some(
if let Some(aggInfo) = account.aggregatorInfo {
Expand Down Expand Up @@ -362,7 +362,7 @@ public func account_setBaseTxFeeL1Gas(account: Account, fee: uint) -> Account {
}
}

public view func account_setStorage(account: Account, storage: StorageMap) -> Account {
public view throw func account_setStorage(account: Account, storage: StorageMap) -> Account {
account with {
contractInfo: Some(
if let Some(contractInfo) = account.contractInfo {
Expand All @@ -385,7 +385,7 @@ public view func account_setStorage(account: Account, storage: StorageMap) -> Ac
}
}

public view write func accountStore_createAccountFromEvmCode(
public view write throw func accountStore_createAccountFromEvmCode(
store: AccountStore,
newAddr: address,
code: ByteArray,
Expand Down Expand Up @@ -443,7 +443,7 @@ public func accountStore_upgradeContractFromEvmCode(
}
}

public func accountStore_createBuiltinContract(
public throw func accountStore_createBuiltinContract(
acctStore: AccountStore,
addr: address,
entryPoint: view write func(),
Expand Down Expand Up @@ -568,7 +568,7 @@ public func accountStore_getEscrowBalance(acctStore: AccountStore, key: uint) ->
storageMap_get(acctStore.escrowStore.escrowedValues, key)
}

public func accountStore_sumOfAllEscrowBalances(acctStore: AccountStore) -> uint {
public throw func accountStore_sumOfAllEscrowBalances(acctStore: AccountStore) -> uint {
unsafecast<uint>(
storageMap_forall(
acctStore.escrowStore.escrowedValues,
Expand Down Expand Up @@ -733,7 +733,7 @@ type asfa_wrappedState = struct {
// For each account, do state = closure(account, state)
// Return the resulting state
// The order of traversal is deterministic but weird, and might change in future upgrades, so don't rely on it.
public func accountStore_forall(acctStore: AccountStore, closure_: func(Account, any) -> any, startState: any) -> any {
public throw func accountStore_forall(acctStore: AccountStore, closure_: func(Account, any) -> any, startState: any) -> any {
let wrappedState = struct {
innerClosure: closure_,
innerState: startState,
Expand All @@ -752,7 +752,7 @@ func asfaClosure(_: any, acct: Account, wrappedState: asfa_wrappedState) -> asfa
}
}

func hashForCodeRef(code: ByteArray, contractStateVersion: uint) -> bytes32 {
throw func hashForCodeRef(code: ByteArray, contractStateVersion: uint) -> bytes32 {
// This hash, meant as the key in the coderef table, is a collision-free function of this function's args.
// For the original contractStateVersion (= 0) this is just the keccak256 of the code, so it is
// backward-compatible with the original hashing scheme.
Expand All @@ -762,7 +762,7 @@ func hashForCodeRef(code: ByteArray, contractStateVersion: uint) -> bytes32 {
// If a CodeRef exists for code, increment its reference count.
// If one doesn't exist, create and initialize one.
// Return the attributes of the resulting CodeRef
public view write func accountStore_createOrAddCodeRef(
public view write throw func accountStore_createOrAddCodeRef(
acctStore: AccountStore,
contractStateVersion: uint,
code: ByteArray
Expand Down Expand Up @@ -800,7 +800,7 @@ public func accountStore_addCodeRef(acctStore: AccountStore, codeHash: bytes32)
Some(acctStore)
}

public func accountStore_createCodeRef(
public throw func accountStore_createCodeRef(
acctStore: AccountStore,
contractStateVersion: uint,
code: ByteArray,
Expand Down
16 changes: 8 additions & 8 deletions arb_os/arbaddresstable.mini
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ use std::rlp::rlp_encodeUint;
use std::rlp::rlp_encodeAddress;


public view write func arbAddressTable_txcall() {
public view write throw func arbAddressTable_txcall() {
if let Some(topFrame) = evmCallStack_topFrame() {
let calldata = evmCallFrame_getCalldata(topFrame);
if bytearray_size(calldata) < 4 {
Expand Down Expand Up @@ -76,7 +76,7 @@ func getFuncCode(ba: ByteArray) -> uint {
(bytearray_get256(ba, 0) >> 224)
}

view write func arbAddressTable_register(_topFrame: EvmCallFrame, calldata: ByteArray) { // (address addr) -> uint
view write throw func arbAddressTable_register(_topFrame: EvmCallFrame, calldata: ByteArray) { // (address addr) -> uint
// return the index of addr in the address table
// if addr isn't in the table already, add it to the table and return its new index
evmOp_revertIfStatic();
Expand All @@ -96,7 +96,7 @@ view write func arbAddressTable_register(_topFrame: EvmCallFrame, calldata: Byte
}
}

view write func arbAddressTable_lookup(_topFrame: EvmCallFrame, calldata: ByteArray) { // (address addr) -> uint
view write throw func arbAddressTable_lookup(_topFrame: EvmCallFrame, calldata: ByteArray) { // (address addr) -> uint
// return the index of addr in the address table; revert if it's not in the table
if bytearray_size(calldata) != 36 {
evmOp_revert_knownCodePc(address(const::Address_ArbAddressTable), 120, 0, 0);
Expand All @@ -113,7 +113,7 @@ view write func arbAddressTable_lookup(_topFrame: EvmCallFrame, calldata: ByteAr
}
}

view write func arbAddressTable_addressExists(_topFrame: EvmCallFrame, calldata: ByteArray) { // (address addr) -> bool
view write throw func arbAddressTable_addressExists(_topFrame: EvmCallFrame, calldata: ByteArray) { // (address addr) -> bool
// return true iff addr is in the address table
if bytearray_size(calldata) != 36 {
evmOp_revert_knownCodePc(address(const::Address_ArbAddressTable), 130, 0, 0);
Expand All @@ -131,7 +131,7 @@ view write func arbAddressTable_addressExists(_topFrame: EvmCallFrame, calldata:
}
}

view write func arbAddressTable_size(_topFrame: EvmCallFrame, calldata: ByteArray) { // () -> uint
view write throw func arbAddressTable_size(_topFrame: EvmCallFrame, calldata: ByteArray) { // () -> uint
// return the number of items in the address table
if bytearray_size(calldata) != 4 {
evmOp_revert_knownCodePc(address(const::Address_ArbAddressTable), 140, 0, 0);
Expand All @@ -144,7 +144,7 @@ view write func arbAddressTable_size(_topFrame: EvmCallFrame, calldata: ByteArra
}
}

view write func arbAddressTable_lookupIndex(_topFrame: EvmCallFrame, calldata: ByteArray) { // (uint index) -> address
view write throw func arbAddressTable_lookupIndex(_topFrame: EvmCallFrame, calldata: ByteArray) { // (uint index) -> address
// return the address at slot index in the address table, or revert if index is beyond the end of the table
if bytearray_size(calldata) != 36 {
evmOp_revert_knownCodePc(address(const::Address_ArbAddressTable), 150, 0, 0);
Expand All @@ -161,7 +161,7 @@ view write func arbAddressTable_lookupIndex(_topFrame: EvmCallFrame, calldata: B
}
}

view write func arbAddressTable_decompress(_topFrame: EvmCallFrame, calldata: ByteArray) { // (bytes buf, uint offset) -> (address, uint)
view write throw func arbAddressTable_decompress(_topFrame: EvmCallFrame, calldata: ByteArray) { // (bytes buf, uint offset) -> (address, uint)
// read a compressed address from buf at offset, return (resulting address, updated offset)
// revert if buf is too short
if bytearray_size(calldata) < 4+4*32 {
Expand Down Expand Up @@ -196,7 +196,7 @@ view write func arbAddressTable_decompress(_topFrame: EvmCallFrame, calldata: By
}
}

view write func arbAddressTable_compress(_topFrame: EvmCallFrame, calldata: ByteArray) { // (address addr) -> bytes
view write throw func arbAddressTable_compress(_topFrame: EvmCallFrame, calldata: ByteArray) { // (address addr) -> bytes
// compress addr, based on the current address table contents, and return the resulting buffer
if bytearray_size(calldata) != 36 {
evmOp_revert_knownCodePc(address(const::Address_ArbAddressTable), 100, 0, 0);
Expand Down
18 changes: 9 additions & 9 deletions arb_os/arbaggregator.mini
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ use std::bytearray::bytearray_get256;
use std::bytearray::bytearray_set256;


public view write func arbaggregator_txcall() {
public view write throw func arbaggregator_txcall() {
if let Some(topFrame) = evmCallStack_topFrame() {
let calldata = evmCallFrame_getCalldata(topFrame);
if bytearray_size(calldata) < 4 {
Expand Down Expand Up @@ -70,7 +70,7 @@ public view write func arbaggregator_txcall() {
}

// function getPreferredAggregator(address addr) external view returns (address, bool);
view write func arbaggregator_getPreferredAggregator(_topFrame: EvmCallFrame, calldata: ByteArray) {
view write throw func arbaggregator_getPreferredAggregator(_topFrame: EvmCallFrame, calldata: ByteArray) {
if bytearray_size(calldata) != 36 {
evmOp_revert_knownPc(10, 0, 0);
}
Expand All @@ -92,7 +92,7 @@ view write func arbaggregator_getPreferredAggregator(_topFrame: EvmCallFrame, ca
}

// function setPreferredAggregator(address prefAgg) external;
view write func arbaggregator_setPreferredAggregator(topFrame: EvmCallFrame, calldata: ByteArray) {
view write throw func arbaggregator_setPreferredAggregator(topFrame: EvmCallFrame, calldata: ByteArray) {
evmOp_revertIfStatic();
if bytearray_size(calldata) != 36 {
evmOp_revert_knownPc(20, 0, 0);
Expand All @@ -115,7 +115,7 @@ view write func arbaggregator_setPreferredAggregator(topFrame: EvmCallFrame, cal
}

// function getDefaultAggregator() external view returns (address);
view write func arbaggregator_getDefaultAggregator(_topFrame: EvmCallFrame, calldata: ByteArray) { // () -> address
view write throw func arbaggregator_getDefaultAggregator(_topFrame: EvmCallFrame, calldata: ByteArray) { // () -> address
if bytearray_size(calldata) != 4 {
evmOp_revert_knownPc(30, 0, 0);
}
Expand All @@ -128,7 +128,7 @@ view write func arbaggregator_getDefaultAggregator(_topFrame: EvmCallFrame, call
}

// function setDefaultAggregator(address newDefault) external;
view write func arbaggregator_setDefaultAggregator(topFrame: EvmCallFrame, calldata: ByteArray) { // (address)
view write throw func arbaggregator_setDefaultAggregator(topFrame: EvmCallFrame, calldata: ByteArray) { // (address)
evmOp_revertIfStatic();
let caller = evmCallFrame_getCaller(topFrame);
if bytearray_size(calldata) != 36 {
Expand All @@ -143,7 +143,7 @@ view write func arbaggregator_setDefaultAggregator(topFrame: EvmCallFrame, calld
}

// function getFeeCollector(address aggregator) external view returns (address);
view write func arbaggregator_getFeeCollector(_topFrame: EvmCallFrame, calldata: ByteArray) { // (address) -> address
view write throw func arbaggregator_getFeeCollector(_topFrame: EvmCallFrame, calldata: ByteArray) { // (address) -> address
if bytearray_size(calldata) != 36 {
evmOp_revert_knownPc(50, 0, 0);
}
Expand All @@ -158,7 +158,7 @@ view write func arbaggregator_getFeeCollector(_topFrame: EvmCallFrame, calldata:
}

// function setFeeCollector(address aggregator, address newFeeCollector) external;
view write func arbaggregator_setFeeCollector(topFrame: EvmCallFrame, calldata: ByteArray) {
view write throw func arbaggregator_setFeeCollector(topFrame: EvmCallFrame, calldata: ByteArray) {
evmOp_revertIfStatic();
let caller = evmCallFrame_getCaller(topFrame);
if bytearray_size(calldata) != 68 {
Expand All @@ -179,7 +179,7 @@ view write func arbaggregator_setFeeCollector(topFrame: EvmCallFrame, calldata:
}

// function getTxBaseFee(address aggregator) external view returns (uint);
view write func arbaggregator_getTxBaseFee(_topFrame: EvmCallFrame, calldata: ByteArray) { // (address) -> uint
view write throw func arbaggregator_getTxBaseFee(_topFrame: EvmCallFrame, calldata: ByteArray) { // (address) -> uint
if bytearray_size(calldata) != 36 {
evmOp_revert_knownPc(70, 0, 0);
}
Expand All @@ -193,7 +193,7 @@ view write func arbaggregator_getTxBaseFee(_topFrame: EvmCallFrame, calldata: By
}

// function setTxBaseFee(address aggregator, uint feeInL1Gas) external;
view write func arbaggregator_setTxBaseFee(topFrame: EvmCallFrame, calldata: ByteArray) { // (address, uint)
view write throw func arbaggregator_setTxBaseFee(topFrame: EvmCallFrame, calldata: ByteArray) { // (address, uint)
let caller = evmCallFrame_getCaller(topFrame);
if bytearray_size(calldata) != 68 {
evmOp_revert_knownPc(80, 0, 0);
Expand Down
6 changes: 3 additions & 3 deletions arb_os/arbbls.mini
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use std::bls::bls_makeKey;
use std::bls::bls_marshalPublicKey;


public view write func arbBLS_txcall() {
public view write throw func arbBLS_txcall() {
if let Some(topFrame) = evmCallStack_topFrame() {
let calldata = evmCallFrame_getCalldata(topFrame);
if bytearray_size(calldata) < 4 {
Expand All @@ -57,7 +57,7 @@ func getFuncCode(ba: ByteArray) -> uint {
(bytearray_get256(ba, 0) >> 224)
}

view write func arbBLS_register(topFrame: EvmCallFrame, calldata: ByteArray) {
view write throw func arbBLS_register(topFrame: EvmCallFrame, calldata: ByteArray) {
evmOp_revertIfStatic();
if bytearray_size(calldata) != 4+32*4 {
evmOp_revert_knownCodePc(address(const::Address_ArbBLS), 170, 0, 0);
Expand All @@ -78,7 +78,7 @@ view write func arbBLS_register(topFrame: EvmCallFrame, calldata: ByteArray) {
}
}

view write func arbBLS_getPublicKey(topFrame: EvmCallFrame, calldata: ByteArray) { // (address) -> (uint, uint, uint, uint)
view write throw func arbBLS_getPublicKey(topFrame: EvmCallFrame, calldata: ByteArray) { // (address) -> (uint, uint, uint, uint)
if bytearray_size(calldata) != 36 {
evmOp_revert_knownCodePc(address(const::Address_ArbBLS), 180, 0, 0);
}
Expand Down
8 changes: 4 additions & 4 deletions arb_os/arbfunctiontable.mini
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use decompression::functionTableSize;
use decompression::parseAggregatorFunctionTable;


public view write func arbFunctionTable_txcall() {
public view write throw func arbFunctionTable_txcall() {
if let Some(topFrame) = evmCallStack_topFrame() {
let calldata = evmCallFrame_getCalldata(topFrame);
if bytearray_size(calldata) < 4 {
Expand Down Expand Up @@ -62,7 +62,7 @@ func getFuncCode(ba: ByteArray) -> uint {
}

// function upload(bytes calldata buf) external;
view write func arbFunctionTable_upload(topFrame: EvmCallFrame, calldata: ByteArray) {
view write throw func arbFunctionTable_upload(topFrame: EvmCallFrame, calldata: ByteArray) {
evmOp_revertIfStatic();
if bytearray_size(calldata) < (4+2*32) {
evmOp_revert_knownCodePc(address(const::Address_ArbFunctionTable), 190, 0, 0);
Expand Down Expand Up @@ -93,7 +93,7 @@ view write func arbFunctionTable_upload(topFrame: EvmCallFrame, calldata: ByteAr
}

// function size(address addr) external view returns(uint);
view write func arbFunctionTable_size(_topFrame: EvmCallFrame, calldata: ByteArray) { // (address) -> uint
view write throw func arbFunctionTable_size(_topFrame: EvmCallFrame, calldata: ByteArray) { // (address) -> uint
if bytearray_size(calldata) != 36 {
evmOp_revert_knownCodePc(address(const::Address_ArbFunctionTable), 200, 0, 0);
}
Expand All @@ -108,7 +108,7 @@ view write func arbFunctionTable_size(_topFrame: EvmCallFrame, calldata: ByteArr
}

// function get(address addr, uint index) external view returns(uint, bool, uint);
view write func arbFunctionTable_get(_topFrame: EvmCallFrame, calldata: ByteArray) { // (address, uint) -> (uint, bool, uint)
view write throw func arbFunctionTable_get(_topFrame: EvmCallFrame, calldata: ByteArray) { // (address, uint) -> (uint, bool, uint)
if bytearray_size(calldata) != 68 {
evmOp_revert_knownCodePc(address(const::Address_ArbFunctionTable), 210, 0, 0);
}
Expand Down
Loading

0 comments on commit a182c5a

Please sign in to comment.