
201 Cal.App.3d 832 (1988)
247 Cal. Rptr. 340
ROBERT BOVARD, Plaintiff and Appellant,
v.
AMERICAN HORSE ENTERPRISES, INC., et al., Defendants and Appellants.
Docket No. C000134.
Court of Appeals of California, Third District.
May 27, 1988.
*835 COUNSEL
Robert McDermand III and Steven Lewis for Plaintiff and Appellant.
Maxim N. Bach for Defendants and Appellants.
[Opinion certified for partial publication.[*]]
OPINION
PUGLIA, P.J.
Robert Bovard appeals from the judgment dismissing his supplemental complaint against defendants, American Horse Enterprises, Inc., and James T. Ralph. Bovard contends the trial court erroneously concluded the contract upon which his action was founded was illegal and void as contrary to public policy; alternatively, he contends it is the law of the case that the contract does not violate public policy. Ralph cross-appeals, challenging the trial court's postjudgment order striking his memorandum *836 of costs and taxing costs. We shall affirm the judgment and postjudgment order.[1]

I
This is the second appeal in this case. Our unpublished opinion disposing of the first appeal sets out much of the relevant procedural history of this dispute:
"In two actions later consolidated, plaintiff Bovard separately sued defendants Ralph and American Horse Enterprises, Inc. a corporation, ... to recover on promissory notes executed by defendants in connection with Ralph's purchase of the corporation in 1978.
"On December 9, 1980, and December 10, 1980, court-supervised settlement conferences were held before the Honorable Richard E. Tuttle. If any settlement was arrived at, it was not put on the record.
"On January 26, 1981, [Ralph's] then counsel wrote to the clerk of the court requesting a refund of jury fees because the case had settled. On the same date, counsel for plaintiff wrote a letter to Judge Tuttle asserting that a settlement had been reached at the December 1980 settlement conferences, that [Ralph] had agreed to the settlement, but that [Ralph] refused to sign a stipulated judgment. The letter requested that the judge sign the judgment so that it could be `filed.' Judge Tuttle did so, and judgment was entered February 4, 1981, against [Ralph and American Horse Enterprises, Inc.] for a sum in excess of $194,000.
"On March 30, 1982, more than a year after entry of judgment, Ralph's new counsel noticed a motion to set aside and vacate the February 4, 1981, judgment on the ground that the court records failed to reflect any agreement by Ralph authorizing his former counsel to settle the case. [Citation and fns. omitted.] Counsel argued the judgment was thus void and should be set aside pursuant to [Code of Civil Procedure] section 473 or the equitable powers of the court. In opposition, plaintiff Bovard and his counsel submitted declarations stating the terms of the judgment were agreed upon by all parties and counsel at a settlement conference with Judge Tuttle on December 10, 1980. Defendant Ralph filed a declaration denying he had agreed to the terms outlined in the judgment or had authorized his attorney to compromise the case.
*837 "After argument on April 15, 1982, Ralph's motion to vacate was denied by a judge other than Judge Tuttle. Plaintiff's pending order of examination was stayed while Ralph petitioned this court and the California Supreme Court for extraordinary relief. Both petitions were denied.
"Ralph then filed a notice of appeal from the order denying his motion to vacate and from a notice of entry of the February 4, 1981, judgment he filed on May 24, 1982. We dismissed the purported appeal from the judgment and will consider only the denial of the motion to vacate. We conclude the trial court erred in denying the motion to set aside the judgment." (Bovard v. Ralph, 3 Civ. 21877, unpublished opinion filed Aug. 16, 1983.)
In our opinion reversing the denial of the motion to vacate the judgment, we noted, "Beneath the pleadings there lurks an aroma of the avoidance of a debt validly owed." We suggested that on remand, Bovard might file a supplemental complaint alleging a cause of action based on an agreement to settle. Bovard followed our suggestion and, on October 31, 1983, filed a supplemental complaint.
The trial court severed the supplemental complaint from the cross-complaint (see fn. 1, ante, p. 836) and from the consolidated action on the promissory notes. The supplemental complaint went to trial before a jury. On the third day of trial, Bovard testified as to the nature of the business conducted by American Horse Enterprises, Inc., at the time the corporation was sold to Ralph. Bovard explained the corporation made jewelry and drug paraphernalia, which consisted of "roach clips" and "bongs" used to smoke marijuana and tobacco. At that point the trial court excused the jury and asked counsel to prepare arguments on the question whether the contract for sale of the corporation was illegal and void.
The following day, after considering the arguments of counsel, the trial court dismissed the supplemental complaint. The court found that the corporation predominantly produced paraphernalia used to smoke marijuana and was not engaged significantly in jewelry production, and that Bovard had recovered the corporate machinery through self-help. The parties do not challenge these findings. The court acknowledged that the manufacture of drug paraphernalia was not itself illegal in 1978 when Bovard and Ralph contracted for the sale of American Horse Enterprises, Inc. However, the court concluded a public policy against the manufacture of drug paraphernalia was implicit in the statute making the possession, use and transfer of marijuana unlawful. (See Health & Saf. Code, §§ 11357, 11358, 11359, *838 11360.)[2] The trial court held the consideration for the contract was contrary to the policy of express law, and the contract was therefore illegal and void. Finally, the court found the parties were in pari delicto and thus with respect to their contractual dispute should be left as the court found them.

II
"The consideration of a contract must be lawful within the meaning of section sixteen hundred and sixty-seven." (Civ. Code, § 1607.) "That is not lawful which is: [¶] 1. Contrary to an express provision of law; [¶] 2. Contrary to the policy of express law, though not expressly prohibited; or, [¶] 3. Otherwise contrary to good morals." (Civ. Code, § 1667.) "If any part of a single consideration for one or more objects, or of several considerations for a single object, is unlawful, the entire contract is void." (Civ. Code, § 1608.)
The trial court concluded the consideration for the contract was contrary to the policy of the law as expressed in the statute prohibiting the possession, use and transfer of marijuana. (1a) Whether a contract is contrary to public policy is a question of law to be determined from the circumstances of the particular case. (Kallen v. Delug (1984) 157 Cal. App.3d 940, 951 [203 Cal. Rptr. 879]; Russell v. Soldinger (1976) 59 Cal. App.3d 633, 642 [131 Cal. Rptr. 145].) Here, the critical facts are not in dispute. (2) Whenever a court becomes aware that a contract is illegal, it has a duty to refrain from entertaining an action to enforce the contract. (Russell v. Soldinger, supra; Santoro v. Carbone (1972) 22 Cal. App.3d 721, 732 [99 Cal. Rptr. 488], disapproved on another ground in Liodas v. Sahadi (1977) 19 Cal.3d 278, 287 [137 Cal. Rptr. 635, 562 P.2d 316].) (3) Furthermore the court will not permit the parties to maintain an action to settle or compromise a claim based on an illegal contract. (Union Collection Co. v. Buckman (1907) 150 Cal. 159, 165 [88 P. 708]; see also First Nat. Bk. v. Thompson (1931) 212 Cal. 388, 405 [298 P. 808].)
The question whether a contract violates public policy necessarily involves a degree of subjectivity. Therefore, "... courts have been cautious in blithely applying public policy reasons to nullify otherwise enforceable contracts. This concern has been graphically articulated by the California Supreme Court as follows: `It has been well said that public policy is an *839 unruly horse, astride of which you are carried into unknown and uncertain paths, ... While contracts opposed to morality or law should not be allowed to show themselves in courts of justice, yet public policy requires and encourages the making of contracts by competent parties upon all valid and lawful considerations, and courts so recognizing have allowed parties the widest latitude in this regard; and, unless it is entirely plain that a contract is violative of sound public policy, a court will never so declare. "The power of the courts to declare a contract void for being in contravention of sound public policy is a very delicate and undefined power, and, like the power to declare a statute unconstitutional, should be exercised only in cases free from doubt." [Citation.] ... "No court ought to refuse its aid to enforce a contract on doubtful and uncertain grounds. (4) The burden is on the defendant to show that its enforcement would be in violation of the settled public policy of this state, or injurious to the morals of its people." [Citation.]'" (Moran v. Harris (1982) 131 Cal. App.3d 913, 919-920 [182 Cal. Rptr. 519, 28 A.L.R.4th 655], quoting Stephens v. Southern Pacific Co. (1895) 109 Cal. 86, 89-90 [41 P. 783].)
Bovard places great reliance on Moran v. Harris, supra, 131 Cal. App.3d 913, to support his argument the trial court erred in finding the contract violative of public policy. In Moran, two lawyers entered into a fee splitting agreement relative to a case referred by one to the other. The agreement was made in 1972, 10 months before the adoption of a rule of professional conduct prohibiting such agreements. In 1975, the attorney to whom the case had been referred settled the case, but then refused to split the attorney's fees with the referring attorney. (Id., at pp. 916-917.) The trial court held the fee splitting contract violated public policy. The appellate court reversed, noting the rule of professional conduct had been amended effective January 1, 1979, to permit fee splitting agreements; thus there was no statute or rule prohibiting fee splitting agreements either at the time the attorneys' contract was formed or after January 1, 1979, during the pendency of the action to enforce the fee splitting contract. Therefore, the court held there was no basis for a finding that the contract violated public policy. (Id., at pp. 920-921.)
Here, in contrast to Moran, there is positive law on which to premise a finding of public policy, although the trial court did not find the manufacture of marijuana paraphernalia against public policy on the basis of the later enacted ordinance or statute prohibiting such manufacture. (1b) (See fn. 3.) Rather, the court's finding was based on a statute prohibiting the *840 possession, use and transfer of marijuana which long antedated the parties' contract.[3]
Moran suggests factors to consider in analyzing whether a contract violates public policy: "Before labeling a contract as being contrary to public policy, courts must carefully inquire into the nature of the conduct, the extent of public harm which may be involved, and the moral quality of the conduct of the parties in light of the prevailing standards of the community. [Citations.]" (Id., at p. 920.)
(5) These factors are more comprehensively set out in the Restatement Second of Contracts section 178: "(1) A promise or other term of an agreement is unenforceable on grounds of public policy if legislation provides that it is unenforceable or the interest in its enforcement is clearly outweighed in the circumstances by a public policy against the enforcement of such terms.
"(2) In weighing the interest in the enforcement of a term, account is taken of
"(a) the parties' justified expectations,
"(b) any forfeiture that would result if enforcement were denied, and
"(c) any special public interest in the enforcement of the particular term.
"(3) In weighing a public policy against enforcement of a term, account is taken of
"(a) the strength of that policy as manifested by legislation or judicial decisions,
"(b) the likelihood that a refusal to enforce the term will further that policy,
"(c) the seriousness of any misconduct involved and the extent to which it was deliberate, and
"(d) the directness of the connection between that misconduct and the term."
*841 (6) Applying the Restatement test to the present circumstances, we conclude the interest in enforcing this contract is very tenuous. Neither party was reasonably justified in expecting the government would not eventually act to geld American Horse Enterprises, a business harnessed to the production of paraphernalia used to facilitate the use of an illegal drug. Moreover, although voidance of the contract imposed a forfeiture on Bovard, he did recover the corporate machinery, the only assets of the business which could be used for lawful purposes, i.e., to manufacture jewelry. Thus, the forfeiture was significantly mitigated if not negligible. Finally, there is no special public interest in the enforcement of this contract, only the general interest in preventing a party to a contract from avoiding a debt.
On the other hand, the Restatement factors favoring a public policy against enforcement of this contract are very strong. As we have explained, the public policy against manufacturing paraphernalia to facilitate the use of marijuana is strongly implied in the statutory prohibition against the possession, use, etc., of marijuana, a prohibition which dates back at least to 1929. (See Stats. 1929, ch. 216, § 1, p. 380.) Obviously, refusal to enforce the instant contract will further that public policy not only in the present circumstances but by serving notice on manufacturers of drug paraphernalia that they may not resort to the judicial system to protect or advance their business interests. Moreover, it is immaterial that the business conducted by American Horse Enterprises was not expressly prohibited by law when Bovard and Ralph made their agreement since both parties knew that the corporation's products would be used primarily for purposes which were expressly illegal. We conclude the trial court correctly declared the contract contrary to the policy of express law and therefore illegal and void.

III
(7a) We reject Bovard's contention legality of the contract is established by the law of the case. (8) That doctrine provides that where an appellate court states in its opinion a principle of law necessary to its decision, the principle becomes the law of the case for later proceedings, including appeals. (Clemente v. State of California (1985) 40 Cal.3d 202, 211 [219 Cal. Rptr. 445, 707 P.2d 818].) The general rule is that the doctrine applies only to issues which were both presented and determined in a prior appeal. (9 Witkin, Cal. Procedure (3d ed. 1985) Appeal, § 753, p. 721.) "Where the particular point was essential to the decision, and the appellate judgment could not have been rendered without its determination, a necessary conclusion in support of the judgment is that it was determined. With respect to such a point, the appellate decision is law of the case even though the point was not raised by counsel or expressly mentioned." (9 Witkin, op. cit. supra, at § 754, p. 722.)
*842 (7b) Here, the legality of the contract was not essential to a determination of the first appeal. At that time there had been no fact finding in the case. The appeal was from the denial of a motion to vacate a judgment entered on a settlement agreement. The record contained no clear evidence of the nature of the corporation's business. Thus, although Ralph raised the issue in his brief on appeal, we could not have decided it on the record before us and consequently neither considered nor expressed any views on the subject. The absence of fact finding at the time of the first appeal distinguishes this case from Nevcal Enterprises v. Cal-Neva Lodge, Inc. (1963) 217 Cal. App.2d 799 [32 Cal. Rptr. 106] relied on by Bovard, in which the appeal followed a trial on the merits.

IV
Following entry of judgment dismissing the supplemental complaint, Ralph filed a memorandum seeking $26,356.06 in costs and attorney's fees. Ralph served the memorandum on both Bovard and his previous attorney, Joseph T. Harbison. After Bovard and Harbison each filed opposition, the trial court filed its order striking Ralph's memorandum of costs and taxing costs. In his cross-appeal from this order after judgment, Ralph contends he is entitled to costs and attorney's fees as a matter of right. Ralph is wrong.
(9) The promissory notes, given as consideration for the sale of the corporation, contain provisions for the award of attorney's fees, but not for costs. Thus, the decision whether to award costs rested firmly in the trial court's discretion. (See Code Civ. Proc., § 1032.) As there is no contention the trial court abused its discretion in denying costs, we consider only Ralph's contention of error in denying attorney's fees.
(10) Ordinarily, in an action on a contract which provides for an award of attorney's fees, the prevailing party in the action is entitled to attorney's fees. (Civ. Code, § 1717, subd. (a).) This is so even when the party prevails on grounds the contract is inapplicable, invalid, unenforceable or nonexistent, if the other party would have been entitled to attorney's fees had it prevailed. (North Associates v. Bell (1986) 184 Cal. App.3d 860, 865 [229 Cal. Rptr. 305]; see also Reynolds Metals Co. v. Alperson (1979) 25 Cal.3d 124, 128-129 [158 Cal. Rptr. 1, 599 P.2d 83]; Manier v. Anaheim Business Center Co. (1984) 161 Cal. App.3d 503, 507 [207 Cal. Rptr. 508]; Jones v. Drain (1983) 149 Cal. App.3d 484, 489-490 [196 Cal. Rptr. 827]; Care Constr., Inc. v. Century Convalescent Centers, Inc. (1976) 54 Cal. App.3d 701, 707 [126 Cal. Rptr. 761].) The rationale for this rule is that an award of attorney's fees pursuant to Civil Code section 1717 is governed by equitable principles, and it would be inequitable to deny attorney's fees to a party who successfully defends an action based on a contract simply because the *843 party initiating the case filed a frivolous lawsuit. (Jones v. Drain, supra, at pp. 489-490.)
(11) However, a different rule applies where a contract is held unenforceable because of illegality. Geffen v. Moss (1975) 53 Cal. App.3d 215 [125 Cal. Rptr. 687, 79 A.L.R.3d 1232] is directly on point. In that case, the court held a party may not recover attorney's fees when it successfully defends an action on a contract on the ground the contract violated public policy. In Geffen, the contract was declared void as violative of public policy. (Id., at pp. 221, 225-227.) The court refused to award attorney's fees, explaining, "Civil Code section 1717 renders the obligation to pay attorney's fees mutual. However, since we have decided that the obligation to [perform under the contract] is contrary to public policy and unenforceable the right to attorney's fees created by this provision never matured." (Id., at p. 227.)
A party to a contract who successfully argues its illegality stands on different ground than a party who prevails in an action on a contract by convincing the court the contract is inapplicable, invalid, nonexistent or unenforceable for reasons other than illegality. "The effect of the Geffen decision is that where neither party can enforce the agreement there is no need for a mutual right to attorney's fees." (Care Constr., Inc. v. Century Convalescent Centers, Inc., supra, 54 Cal. App.3d at p. 707 [affirming award of attorney's fees to party who successfully argued lease was nonexistent]. See also Star Pacific Investments, Inc. v. Oro Hills Ranch, Inc. (1981) 121 Cal. App.3d 447, 459-460 [176 Cal. Rptr. 546].)
Consistent with our decision that the contract is illegal and void, we affirm the trial court's order denying Ralph's claim for attorney's fees.
(12) Finally, although Ralph's contention that Bovard's former counsel, Harbison, is liable for Ralph's costs and fees is frivolous (see In re Marriage of Flaherty (1982) 31 Cal.3d 637, 650 [183 Cal. Rptr. 508, 646 P.2d 179]), we deny Harbison's request for sanctions. No reasonable attorney could believe that costs and attorney's fees are recoverable from opposing counsel who was never a party to the supplemental complaint; serving Harbison with the cost memorandum did not effect the necessary transmutation. The authorities relied upon by Ralph (Gray v. Don Miller & Associates, Inc. (1984) 35 Cal.3d 498 [198 Cal. Rptr. 551, 674 P.2d 253, 44 A.L.R.4th 763]; Wolfrich Corp. v. United Services Automobile Assn. (1983) 149 Cal. App.3d 1206 [197 Cal. Rptr. 446]) are inapposite and cannot seriously be argued to apply to this situation.
However, precisely because Harbison was not a party to the supplemental complaint, his objections and exertions in opposition to Ralph's memorandum *844 were those of a volunteer. For the same reason, Harbison is not a party to this appeal and lacks standing to move in this court for sanctions.[4]

V[*]
.... .... .... .... .... .
The judgment dismissing the supplemental complaint, the order striking the memorandum of costs and taxing costs, and the judgment dismissing the cross-complaint are affirmed. The parties are to bear their own costs on appeal.
Evans, J., and Sims, J., concurred.
NOTES
[*]   Pursuant to California Rules of Court, rule 976.1, this opinion is certified for publication with the exception of part V.
[1]  Ralph separately appeals from an order dismissing his cross-complaint to the supplemental complaint. Ralph's appeal has been consolidated with Bovard's. In the unpublished part of this opinion we uphold the trial court's ruling that the cross-complaint was premised upon the void contract and affirm the judgment of dismissal accordingly.
[2]  The manufacture of drug paraphernalia, including bongs and roach clips, was made criminal effective January 1, 1983, by Statutes 1982, chapter 1278, sections 1 and 2, pages 4725-4728, which enacted Health and Safety Code sections 11014.5 and 11364.7. (See A&B Cattle Co. v. City of Escondido (1987) 192 Cal. App.3d 1032, 1036-1037, 1042 [238 Cal. Rptr. 580].)

In addition, Sacramento County made criminal the manufacture of drug paraphernalia by ordinance in July 1980.
[3]  "In determining whether the subject of a given contract violates public policy, courts must rely on the state of the law as it existed at the time the contract was made. [Citations.]" (Moran v. Harris, supra, 131 Cal. App.3d at p. 918.)
[4]  Harbison was named as a cross-defendant in Ralph's cross-complaint to Bovard's supplemental complaint. The cross-complaint alleged that Harbison, Bovard and others "wrongfully obtained a void judgment" against Ralph "based upon an alleged settlement that never occurred" and "proceeded to wrongfully levy upon and/or attach property owned" by Ralph in an effort to enforce the judgment. Shortly after the cross-complaint was filed Harbison substituted out as counsel for Bovard. The supplemental complaint was severed from the cross-complaint for trial; it was dismissed by the court almost six months after the dismissal of the supplemental complaint.
[*]   See footnote, ante, page 832.
